Преглед на файлове

fix: 处理注释导入缩放无法渲染bug

liutian преди 1 година
родител
ревизия
bdaccb73c7

+ 0 - 9
packages/core/src/Outline.ts

@@ -5,7 +5,6 @@ export default class Outline {
   index: number
   children: Outline[] | []
   parent: Outline | null
-  document: any
 
   constructor(options: {
     doc: number,
@@ -14,7 +13,6 @@ export default class Outline {
     index: number,
     children: Outline[] | [],
     parent: Outline | null,
-    document: any
   }) {
     this.doc = options.doc
     this.messageHandler = options.messageHandler
@@ -22,7 +20,6 @@ export default class Outline {
     this.index = options.index
     this.children = options.children || []
     this.parent = options.parent
-    this.document = options.document
   }
 
   get pageNumber() {
@@ -37,12 +34,6 @@ export default class Outline {
     return this.outline.level
   }
 
-  goTo() {
-    this.document.scrollPageIntoView({
-      pageNumber: this.pageNumber,
-    })
-  }
-
   getOutline() {
     return this.outline
   }

+ 4 - 2
packages/core/src/TextSearch.ts

@@ -56,10 +56,12 @@ export default class TextSearch {
     const activeSearchResult = this.activeSearchResult
 
     if (search && ((activeSearchResult && (activeSearchResult.pageNum !== pageNum || left !== activeSearchResult.left || top !== activeSearchResult.top || right !== activeSearchResult.right || bottom !== activeSearchResult.bottom)) || !activeSearchResult)) {
-      const searchEles = this.searchContainer!.querySelectorAll('div')
+      if (this.searchContainer) {
+        const searchEles = this.searchContainer.querySelectorAll('div')
+        searchEles[search.pageSearchIndex].classList.add('selected')
+      }
       this.activeSearchResult = search
       this.activeIndex = pageNum - 1
-      searchEles[search.pageSearchIndex].classList.add('selected')
     }
   }
 

+ 15 - 6
packages/core/src/index.js

@@ -200,7 +200,9 @@ class ComPDFKitViewer {
   }
 
   async handleAnnotations(annotation, init = false) {
-    this.annotations = this.annotations || {}
+    if (!this.annotations) {
+      this.annotations = {}
+    }
     if (init) {
       this.initAddAnnotations(annotation)
     } else {
@@ -451,6 +453,7 @@ class ComPDFKitViewer {
 
     const pageView = this.pdfViewer._pages[activeResult.pageNum - 1]
     this.pdfViewer.currentPageNumber = activeResult.pageNum
+
     scrollIntoView(pageView.div, {
       left,
       top
@@ -570,7 +573,15 @@ class ComPDFKitViewer {
       }
     }
 
-    this.initAnnotations(annotations, true)
+    for (let index = 0; index < annotations.length; index++) {
+      if (!this.annotations) {
+        this.annotations = {}
+      }
+      this.pushAnnotations(annotations[index])
+
+      this.pdfViewer.renderAnnotation(annotations[index])
+    }
+    this.eventBus.dispatch('annotationChanged', { annotations: this.annotations })
   }
 
   get supportsFullscreen() {
@@ -781,15 +792,13 @@ class ComPDFKitViewer {
     const outlines = await messageHandler.sendWithPromise('GetOutlines', {
       doc
     })
-
-    function generateOutline(outline, index, parent) {
+    const generateOutline = (outline, index, parent) => {
       const outlineItem = new Outline({
         outline,
         index,
         doc,
         messageHandler,
-        parent,
-        document: this
+        parent
       })
       outline.children.forEach(function (outline, index) {
         outlineItem.children.push(generateOutline(outline, index, outlineItem))

+ 0 - 21
packages/core/src/pdf_page_view.js

@@ -937,27 +937,6 @@ class PDFPageView {
     canvasWrapper.classList.add("canvasWrapper");
     div.append(canvasWrapper);
 
-    if (
-      !this.textLayer &&
-      this.textLayerMode !== TextLayerMode.DISABLE &&
-      !pdfPage.isPureXfa
-    ) {
-      this._accessibilityManager ||= new TextAccessibilityManager();
-
-      this.textLayer = new TextLayerBuilder({
-        pdfPage,
-        highlighter: this._textHighlighter,
-        accessibilityManager: this._accessibilityManager,
-        isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
-      });
-      div.append(this.textLayer.div);
-    }
-
-    if (this.xfaLayer?.div) {
-      // The xfa layer needs to stay on top.
-      div.append(this.xfaLayer.div);
-    }
-
     let renderContinueCallback = null;
     if (this.renderingQueue) {
       renderContinueCallback = cont => {

+ 4 - 1
packages/webview/src/components/Outlines/Outlines.vue

@@ -13,6 +13,7 @@
 </template>
 
 <script setup>
+import core from '@/core'
 import { ref, computed } from 'vue'
 import { useDocumentStore } from '@/stores/modules/document'
 
@@ -57,7 +58,9 @@ const isOutlineActive = computed(() => useDocument.getActiveOutlineId === outlin
 
 const goToOutline = () => {
   useDocument.setActiveOutlineId(outlineId.value)
-  outline.goTo()
+  core.pageNumberChanged({
+    value: outline.pageNumber
+  })
 }
 
 const toggleOutline = (e) => {