Kaynağa Gözat

fix: 设置默认中文字体

liutian 1 ay önce
ebeveyn
işleme
e6a03327ab

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

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

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

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