Browse Source

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

liutian 2 tuần trước cách đây
mục cha
commit
88413bf4bd

+ 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)
       }