Browse Source

fix: 字体支持不压缩列表(但会一次性下载)

liutian 1 week ago
parent
commit
88413bf4bd
2 changed files with 7 additions and 5 deletions
  1. 1 1
      packages/core/src/index.js
  2. 6 4
      packages/core/src/worker/compdfkit_worker.js

+ 1 - 1
packages/core/src/index.js

@@ -288,7 +288,7 @@ class ComPDFKitViewer {
       }
       if (options.webFontURL) {
         this.enableCustomFont = true
-        this.webFontURL = options.webFontURL
+        this.webFontURL = options.webFontURL.endsWith('/') ? options.webFontURL : options.webFontURL + '/'
       }
       if (!this.webviewerServer && this.enableCustomFont) {
         const webFontURL = this.webFontURL

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

@@ -160,14 +160,16 @@ class CPDFWorker {
         webFontURL = data.webFontURL
       }
 
-      if (data.fontsJson) {
+      if (data.fontsJson && !fontsJson) {
         fontsJson = data.fontsJson
 
         const compress = !!ComPDFKitJS.opened_Font[0]
         ComPDFKitJS.FontCount = (compress ? (data.fontsJson.length + 1) : data.fontsJson.length)
-        if (!compress && data.fontsJson.length === 1) {
-          const fontFile = readFileAsync(webFontURL + data.fontsJson[0].filePath)
-          ComPDFKitJS.opened_Font[0] = fontFile
+        if (!compress) {
+          for (let i = 0; i < data.fontsJson.length; i++) {
+            const fontFile = readFileAsync(webFontURL + data.fontsJson[i].filePath)
+            ComPDFKitJS.opened_Font[i] = fontFile
+          }
         }
         Module._InitComPDFkitFont(compress)
       }