Explorar o código

add: 支持设置是否需要开启倒入字体

liutian hai 2 semanas
pai
achega
a8cb036782
Modificáronse 2 ficheiros con 15 adicións e 8 borrados
  1. 8 2
      packages/core/src/index.js
  2. 7 6
      packages/core/src/worker/compdfkit_worker.js

+ 8 - 2
packages/core/src/index.js

@@ -63,6 +63,8 @@ class ComPDFKitViewer {
     this.color = 'color'
     this.pagesPtr = []
     this.saveAction = null
+    this.enableCustomFont = false
+    this.fontsJson = null
     this.webFontURL = 'https://www.compdf.com/fonts/'
     this.optionUrl = {
       // baseUrl: 'https://test-compdf.kdan.cn',
@@ -272,12 +274,16 @@ class ComPDFKitViewer {
     // this.webviewerServer = true
 
     if (verified) {
+      if (options.enableCustomFont) {
+        this.enableCustomFont = true
+      }
       if (options.webFontURL) {
+        this.enableCustomFont = true
         this.webFontURL = options.webFontURL
       }
-      if (!this.webviewerServer) {
+      if (!this.webviewerServer && this.enableCustomFont) {
         const webFontURL = this.webFontURL
-        
+
         const response = await fetch(webFontURL + 'font.ff')
         if (response.ok) {
           const resData = await response.arrayBuffer()

+ 7 - 6
packages/core/src/worker/compdfkit_worker.js

@@ -160,13 +160,14 @@ class CPDFWorker {
 
       if (data.fileList) {
         ComPDFKitJS.opened_Font[0] = data.fileList
-      }
-      if (data.webFontURL !== 'https://www.compdf.com/fonts/') {
-        webFontURL = data.webFontURL
-      }
-      fontsJson = data.fontsJson
 
-      Module._InitComPDFkitFont()
+        if (data.webFontURL !== 'https://www.compdf.com/fonts/') {
+          webFontURL = data.webFontURL
+        }
+        fontsJson = data.fontsJson
+
+        Module._InitComPDFkitFont()
+      }
       const doc = Module._InitDocument()
 
       return doc