Selaa lähdekoodia

fix: 设置默认中文字体

liutian 1 kuukausi sitten
vanhempi
commit
e6a03327ab
2 muutettua tiedostoa jossa 13 lisäystä ja 3 poistoa
  1. 5 0
      packages/core/src/index.js
  2. 8 3
      packages/core/src/worker/compdfkit_worker.js

+ 5 - 0
packages/core/src/index.js

@@ -63,6 +63,7 @@ class ComPDFKitViewer {
     this.color = 'color'
     this.pagesPtr = []
     this.saveAction = null
+    this.enableDefaultFont = false
     this.enableCustomFont = false
     this.fontsJson = null
     this.webFontURL = 'https://www.compdf.com/fonts/'
@@ -275,6 +276,9 @@ class ComPDFKitViewer {
     // this.webviewerServer = true
 
     if (verified) {
+      if ('enableDefaultFont' in options) {
+        this.enableDefaultFont = options.enableDefaultFont
+      }
       if (options.enableCustomFont) {
         this.enableCustomFont = true
       }
@@ -554,6 +558,7 @@ class ComPDFKitViewer {
             webFontURL: this.webFontURL,
             fileList: this.#fileList,
             fontsJson: this.fontsJson,
+            enableDefaultFont: this.enableDefaultFont
           })
 
           this.doc = doc

+ 8 - 3
packages/core/src/worker/compdfkit_worker.js

@@ -168,6 +168,11 @@ class CPDFWorker {
 
         Module._InitComPDFkitFont()
       }
+
+      if (data.enableDefaultFont && !ComPDFKitJS.opened_DefFont[0]) {
+        const fontFile = readFileAsync('./DroidSansFallbackFull.ttf')
+        ComPDFKitJS.opened_DefFont[0] = fontFile
+      }
       const doc = Module._InitDocument()
 
       return doc
@@ -401,7 +406,7 @@ class CPDFWorker {
 
       DataArray = []
 
-      const embedded = !!fontsJson
+      const embedded = !!fontsJson || ComPDFKitJS.opened_DefFont[0]
       Module._SaveDocumentByStream(doc, 2, embedded)
 
       const addResult = Module._AddSignSaveDocument(doc, signaturePtr, certPtr)
@@ -3067,7 +3072,7 @@ function addToTrustedCertificates(data) {
 async function copyDocument(doc, password) {
   DataArray = []
 
-  const embedded = !!fontsJson
+  const embedded = !!fontsJson || ComPDFKitJS.opened_DefFont[0]
   Module._SaveDocumentByStream(doc, 2, embedded);
   let pdfData = []
   for (let i = 0; i < DataArray.length; i++) {
@@ -3092,7 +3097,7 @@ function saveDocument(doc, saveType) {
   DataArray = []
   saveType === 1 && DataArray.push(ComPDFKitJS.opened_files[0])
 
-  const embedded = !!fontsJson
+  const embedded = !!fontsJson || ComPDFKitJS.opened_DefFont[0]
   Module._SaveDocumentByStream(doc, saveType, embedded)
   let pdfData = []
   for (let i = 0; i < DataArray.length; i++) {