Browse Source

fix: 文案修改+恢复字体初始化

wzl 7 months ago
parent
commit
72498089af

+ 13 - 6
packages/core/src/editor/content_container.js

@@ -19,9 +19,10 @@ export class ContentContainer {
     this.destroyed = false
     this.rendered = false
     this.frameEditorList = []
-    this.tool = this.pageViewer.tool || ''
+    this.tool = this.pageViewer.tool || options.tool || ''
     this.color = this.pageViewer.color || ''
     this._selectedFrameIndex = -1
+    this.initedFont = false
 
     this.onHandleTool = this.handleTool.bind(this)
     this.onKeydown = this.handleKeyDown.bind(this)
@@ -32,16 +33,22 @@ export class ContentContainer {
       pagePtr: this.pagePtr
     })
     this.editPagePtr = editPagePtr
+    await this.initFont()
+  }
 
-    // await this.messageHandler.sendWithPromise('SetFontCallBackForEditPage', {
-    //   editPagePtr: this.editPagePtr,
-    //   fontFile: this.pageViewer.fontFile,
-    //   fontName: 'DroidSansFallbackFull'
-    // })
+  async initFont() {
+    if (this.initedFont || this.tool === 'editImage' || this.tool === 'addImage') return
+    await this.messageHandler.sendWithPromise('SetFontCallBackForEditPage', {
+      editPagePtr: this.editPagePtr,
+      fontFile: this.pageViewer.fontFile,
+      fontName: 'DroidSansFallbackFull'
+    })
+    this.initedFont = true
   }
 
   async render () {
     if (this._cancelled || this.contentContainer) {
+      if (!this.initedFont) await this.initFont()
       return;
     }
 

+ 9 - 4
packages/core/src/index.js

@@ -304,12 +304,17 @@ class ComPDFKitViewer {
     const oldTool = this.activeTool
     this.activeTool = tool
     this.color = color
-    this.eventBus.dispatch('toolChanged', { tool, color })
+
+    if ((tool === 'editText' || tool === 'addText') && !this.fontFileInited) {
+      await this.initFontFile()
+    }
 
     const editorTools = ['editText', 'editImage', 'addText', 'addImage']
     if (this.toolMode !== 'editor' && editorTools.includes(oldTool) && !editorTools.includes(this.activeTool)) {
       await this.updateTextPtr()
     }
+    
+    this.eventBus.dispatch('toolChanged', { tool, color })
   }
 
   initAnnotations(annotations, render = false) {
@@ -2665,9 +2670,9 @@ class ComPDFKitViewer {
   async setToolMode(mode) {
     const oldMode = this.toolMode;
     this.toolMode = mode;
-    // if (mode === 'editor' && !this.fontFileInited) {
-    //   await this.initFontFile()
-    // }
+    if (mode === 'editor' && !this.fontFileInited) {
+      await this.initFontFile()
+    }
     this.eventBus.dispatch("toolModeChanged", mode);
 
     if (oldMode === 'editor' && this.toolMode !== 'editor') {

+ 4 - 2
packages/core/src/pdf_page_view.js

@@ -559,7 +559,8 @@ class PDFPageView {
               selected: this.selected,
               pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
               messageHandler: this.messageHandler,
-              $t: this.$t
+              $t: this.$t,
+              tool: this.tool
             })
           }
           if (this.mode === 'editor' || ['editText', 'editImage', 'addText', 'addImage'].includes(this.tool)) {
@@ -1214,7 +1215,8 @@ class PDFPageView {
               selected: this.selected,
               pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
               messageHandler: this.messageHandler,
-              $t: this.$t
+              $t: this.$t,
+              tool: this.tool
             })
           }
           if (this.mode === 'editor' || ['editText', 'editImage', 'addText', 'addImage'].includes(this.tool)) {

+ 2 - 0
packages/webview/locales/en.json

@@ -51,7 +51,9 @@
     "print" : "Print",
     "language": "Language",
 
+    "editText": "Edit Text",
     "addText": "Add Text",
+    "editImage": "Edit Image",
     "addImage": "Add Image",
     "undo": "Undo",
     "redo": "Redo"

+ 2 - 0
packages/webview/locales/zh-CN.json

@@ -51,7 +51,9 @@
     "print" : "打印",
     "language": "语言",
 
+    "editText": "编辑文字",
     "addText": "添加文字",
+    "editImage": "编辑图片",
     "addImage": "添加图片",
     "undo": "撤销",
     "redo": "重做"

+ 6 - 6
packages/webview/src/components/Annotate/Annotate.vue

@@ -36,16 +36,16 @@
     <Button v-else-if="tool.type === 'link' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'link' }" @click="changeActiveTool('link')" :title="$t('header.link')">
       <Link />
     </Button>
-    <Button v-else-if="tool.type === 'editText' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'editText' }" @click="changeActiveTool('editText')" :title="$t('header.editor')">
+    <Button v-else-if="tool.type === 'editText' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'editText' }" @click="changeActiveTool('editText')" :title="$t('header.editText')">
       <EditText />
     </Button>
-    <Button v-else-if="tool.type === 'editImage' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'editImage' }" @click="changeActiveTool('editImage')" :title="$t('header.editor')">
-      <EditImage />
-    </Button>
-    <Button v-else-if="tool.type === 'addText' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'addText' }" @click="changeActiveTool('addText')" title="Add Text">
+    <Button v-else-if="tool.type === 'addText' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'addText' }" @click="changeActiveTool('addText')" :title="$t('header.addText')">
       <AddText />
     </Button>
-    <Button v-else-if="tool.type === 'addImage' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'addImage' }" @click="changeActiveTool('addImage')" title="Add Image">
+    <Button v-else-if="tool.type === 'editImage' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'editImage' }" @click="changeActiveTool('editImage')" :title="$t('header.editImage')">
+      <EditImage />
+    </Button>
+    <Button v-else-if="tool.type === 'addImage' && !tool.hidden" :data-element="tool.dataElement" :class="{ active: activeTool === 'addImage' }" @click="changeActiveTool('addImage')" :title="$t('header.addImage')">
       <AddImage />
     </Button>
   </template>

+ 2 - 2
packages/webview/src/components/ContentEditorToolBar/ContentEditorToolBar.vue

@@ -1,9 +1,9 @@
 <template>
   <div class="edit-tool">
-    <Button class="operate" :class="{ active: activeTool === 'addText' }" @click="changeActiveTool('addText')" title="Add Text">
+    <Button class="operate" :class="{ active: activeTool === 'addText' }" @click="changeActiveTool('addText')" :title="$t('header.addText')">
       <AddText />{{ $t('header.addText') }}
     </Button>
-    <Button class="operate" :class="{ active: activeTool === 'addImage' }" @click="changeActiveTool('addImage')" title="Add Image">
+    <Button class="operate" :class="{ active: activeTool === 'addImage' }" @click="changeActiveTool('addImage')" :title="$t('header.addImage')">
       <AddImage />{{ $t('header.addImage') }}<input v-if="isMobileDevice" type="file" ref="editorImageInput" accept=".png, .jpg, .jpeg" style="display: none;" @change="handleFile">
     </Button>
     <!-- <div class="divider pc"></div>