Jelajahi Sumber

fix: FreeText 侧边栏属性变动未同步修复

liutian 3 bulan lalu
induk
melakukan
ab762a9f9c

+ 4 - 17
packages/core/src/annotation/layer.js

@@ -37,7 +37,8 @@ class ComPDFAnnotationLayer {
     scale,
     pageIndex,
     eventBus,
-    $t
+    $t,
+    freetextProperty
   }) {
     this._cancelled = false;
     this.pageViewer = pageViewer
@@ -58,15 +59,6 @@ class ComPDFAnnotationLayer {
     this.selectedElementName = null
     this.addMode = false
     this.toolMode = pageViewer.toolMode || ''
-    this.freetextProperty = {
-      fontSize: 14,
-      textColor: '#000000',
-      fontFamily: 'Helvetica',
-      fontStyle: '',
-      textAlignment: 'left',
-      fontStyle: '',
-      opacity: 1
-    }
 
     this.annotationStore = annotationStore
 
@@ -74,9 +66,10 @@ class ComPDFAnnotationLayer {
     this.onHandleToolMode = this.handleToolMode.bind(this)
     this.onHandlePropertyPanelChanged = this.handlePropertyPanelChanged.bind(this)
     this.onHandleAddSign = this.addSign.bind(this)
-    this.setFreetextProperty = this.setFreetextProperty.bind(this)
 
     this.annotationStore.$t = $t
+
+    this.freetextProperty = freetextProperty
   }
 
   // 处理注释工具切换
@@ -668,7 +661,6 @@ class ComPDFAnnotationLayer {
     this.eventBus._on('toolModeChanged', this.onHandleToolMode)
     this.eventBus._on('setDefaultSelect', this.onHandleDefaultSelect)
     this.eventBus._on('propertyPanelChanged', this.onHandlePropertyPanelChanged)
-    this.eventBus._on('setFreetextProperty', this.setFreetextProperty)
 
     if (viewport) {
       const clonedViewport = viewport.clone({ dontFlip: true });
@@ -976,7 +968,6 @@ class ComPDFAnnotationLayer {
     this.eventBus._off('toolModeChanged', this.onHandleToolMode)
     this.eventBus._off('setDefaultSelect', this.onHandleDefaultSelect)
     this.eventBus._off('propertyPanelChanged', this.onHandlePropertyPanelChanged)
-    this.eventBus._off('setFreetextProperty', this.setFreetextProperty)
 
     this.annotationStore.notFirstRender = true
   }
@@ -1188,10 +1179,6 @@ class ComPDFAnnotationLayer {
     this.eventBus.dispatch('changeSelectAvailable')
   }
 
-  setFreetextProperty (data) {
-    Object.assign(this.freetextProperty, data)
-  }
-
   // 处理面板属性修改
   handlePropertyPanelChanged (props) {
     if (this.annotations && this.annotations.length) {

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

@@ -115,6 +115,7 @@ class PDFPageView {
     this.eventBus = options.eventBus;
     this._annotations = options.annotations
     this._annotationsAll = options.annotationsAll
+    this._freetextProperty = options.freetextProperty
 
     this.pagesPtr = options.pagesPtr
     if (
@@ -522,7 +523,8 @@ class PDFPageView {
               pageDiv: div,
               eventBus: this.eventBus,
               selected: this.selected,
-              $t: this.$t
+              $t: this.$t,
+              freetextProperty: this._freetextProperty,
             })
           }
           this.compdfAnnotationLayer.render(this.viewport)
@@ -1175,7 +1177,8 @@ class PDFPageView {
               pageDiv: div,
               eventBus: this.eventBus,
               selected: this.selected,
-              $t: this.$t
+              $t: this.$t,
+              freetextProperty: this._freetextProperty,
             })
           } else {
             this.compdfAnnotationLayer.destroy()

+ 20 - 1
packages/core/src/pdf_viewer.js

@@ -154,6 +154,16 @@ class PDFViewer {
       throw new Error("Invalid `container` and/or `viewer` option.");
     }
 
+    this._freetextProperty = {
+      fontSize: 14,
+      textColor: '#000000',
+      fontFamily: 'Helvetica',
+      fontStyle: '',
+      textAlignment: 'left',
+      fontStyle: '',
+      opacity: 1
+    }
+
     /** if (
       this.container.offsetParent &&
       getComputedStyle(this.container).position !== "absolute"
@@ -203,6 +213,8 @@ class PDFViewer {
     this._onBeforeDraw = this._onAfterDraw = null;
     this._resetView();
 
+    this._setFreetextProperty = this._setFreetextProperty.bind(this)
+
     if (this.removePageBorders) {
       this.viewer.classList.add("removePageBorders");
     }
@@ -522,6 +534,7 @@ class PDFViewer {
     if (!pdfDocument) {
       return;
     }
+    this.eventBus._on('setFreetextProperty', this._setFreetextProperty)
     const pagesCount = pdfDocument.numPages;
     const firstPagePromise = pdfDocument.getPage(1);
     // Rendering (potentially) depends on this, hence fetching it immediately.
@@ -652,7 +665,8 @@ class PDFViewer {
             l10n: this.l10n,
             $t: this.$t,
             doc: this.doc,
-            messageHandler: this.messageHandler
+            messageHandler: this.messageHandler,
+            freetextProperty: this._freetextProperty
           });
           this._pages.push(pageView);
         }
@@ -748,6 +762,10 @@ class PDFViewer {
       });
   }
 
+  _setFreetextProperty (data) {
+    Object.assign(this._freetextProperty, data)
+  }
+
   /**
    * @param {Array|null} labels
    */
@@ -823,6 +841,7 @@ class PDFViewer {
     this.viewer.removeAttribute("lang");
     // Reset all PDF document permissions.
     this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
+    this.eventBus._off('setFreetextProperty', this._setFreetextProperty)
   }
 
   #ensurePageViewVisible() {