Browse Source

fix: 内容编辑字体新增同步侧边栏

liutian 3 months ago
parent
commit
504f887572

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

@@ -272,6 +272,11 @@ class ComPDFKitViewer {
         this.#fileList = new Uint8Array(resData)
         const fileData = await fetch('./lib/fonts.json')
         this.fontsJson = await fileData.json()
+
+        this.messageHandler.on('LoadFont', data => {
+          const fontFamily = data.fontFamily
+          this.eventBus.dispatch("LoadFont", { fontFamily })
+        })
       }
     }
     return verified

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

@@ -84,7 +84,9 @@ function ComPDFKitDownloadFontA(index){
   if (index === 0) {
     return  ComPDFKitJS.opened_Font[index];
   }
-  fontFile = readFileAsync('./fonts/' + fontsJson[index - 1].filePath)
+  const font = fontsJson[index - 1]
+  fontFile = readFileAsync('./fonts/' + font.filePath)
+  CPDFWorker.MessageHandler.send('LoadFont', { fontFamily: font.family })
   return fontFile
 }
 
@@ -155,6 +157,10 @@ class CPDFWorker {
         ComPDFKitJS.opened_Font[0] = data.fileList
       }
 
+      if (data.defaultFont) {
+        ComPDFKitJS.opened_DefFont[0] = data.defaultFont
+      }
+
       fontsJson = data.fontsJson
 
       Module._InitComPDFkitFont()

+ 15 - 2
packages/webview/src/components/ContentEditorPanel/ContentEditorPanel.vue

@@ -164,8 +164,21 @@
       class: 'edit-select'
     }
   })
-  const fontFamilyArr = ['Helvetica', 'Courier', 'Times-Roman', 'DroidSansFallbackFull']
-  const fontFamilyOptions = fontFamilyArr.map(fontFamily => {
+  const loadFont = (data) => {
+    const fontFamily = data.fontFamily
+    if (!fontFamilyArr.includes(fontFamily)) {
+      fontFamilyArr.push(fontFamily)
+      fontFamilyOptions.value.push({
+        label: fontFamily,
+        value: fontFamily,
+        class: 'edit-select'
+      })
+    }
+  }
+  core.addEvent('LoadFont', loadFont)
+  const fontFamilyArr = ['Helvetica', 'Courier', 'Times-Roman']
+  const fontFamilyOptions = ref([])
+  fontFamilyOptions.value = fontFamilyArr.map(fontFamily => {
     return {
       label: fontFamily,
       value: fontFamily,