ソースを参照

fix: 修复注释rect坐标转换bug

liutian 1 年間 前
コミット
8cfe4f774e

+ 3 - 1
packages/core/src/annotation/paint/shape.js

@@ -139,10 +139,10 @@ export default class PaintShape {
         right,
         bottom
       }
-      const linePoints = [start.x, start.y, end.x, end.y]
       let color = this.color
       const annotationData = {
         operate: "add-annot",
+        arrow:this.tool === 'arrow',
         type: this.tool === 'arrow' ? 'line' : this.tool,
         pageIndex: this.page,
         date: new Date(),
@@ -153,6 +153,7 @@ export default class PaintShape {
       }
 
       if (annotationData.type == 'line') {
+        const linePoints = [start.x, start.y, end.x, end.y]
         annotationData.linePoints = linePoints
         annotationData.rect = {
           left: left - 6,
@@ -170,6 +171,7 @@ export default class PaintShape {
         annotationData.rect = rect
         annotationData.inkPointes = inkPointes
       } else {
+        const linePoints = [left, bottom, right, top]
         annotationData.linePoints = linePoints
       }
 

+ 14 - 14
packages/core/src/annotation/shape.js

@@ -66,10 +66,6 @@ export default class Shape extends Base {
     if (!annotation.borderColor) {
       annotation.borderColor = '#000000'
     }
-
-    if (!annotation.fillColor) {
-      annotation.fillColor = 'none'
-    }
     
     const annotationContainer = document.createElement('div')
     annotationContainer.id = annotation.name
@@ -97,7 +93,7 @@ export default class Shape extends Base {
           stroke: annotation.borderColor,
           'stroke-width': actualbdwidth,
           'stroke-opacity': annotation.transparency || 1,
-          fill: annotation.fillColor,
+          fill: annotation.fillColor ? annotation.fillColor : 'none',
           'fill-opacity': annotation.fillTransparency || 1,
         }
       );
@@ -112,7 +108,7 @@ export default class Shape extends Base {
           stroke: annotation.borderColor,
           'stroke-width': actualbdwidth,
           'stroke-opacity': annotation.transparency || 1,
-          fill: annotation.fillColor,
+          fill: annotation.fillColor ? annotation.fillColor : 'none',
           'fill-opacity': annotation.fillTransparency || 1,
         }
       );
@@ -614,16 +610,20 @@ export default class Shape extends Base {
     if (rect === annotation.rect) return
     annotation.rect = rect
 
+    const annotationData = {
+      operate: "mod-annot",
+      name: annotation.name,
+      pageIndex: this.page,
+      pagePtr: annotation.pagePtr,
+      annotPtr: annotation.annotPtr,
+      rect
+    }
+
+    !annotation.annotPtr && (annotationData.linePoints = [rect.left, rect.bottom, rect.right, rect.top])
+
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
-      annotation: {
-        operate: "mod-annot",
-        name: annotation.name,
-        pageIndex: this.page,
-        pagePtr: annotation.pagePtr,
-        annotPtr: annotation.annotPtr,
-        rect
-      }
+      annotation: annotationData
     })
   }
 

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

@@ -158,7 +158,7 @@ class ComPDFKitViewer {
 
     if (verified) {
       if (!this.webviewerServer) {
-        const response = await fetch('/lib/DroidSansFallbackFull.ttf')
+        const response = await fetch('./lib/DroidSansFallbackFull.ttf')
         const blob = await response.blob()
         this.#fonFile = new File([blob], 'DroidSansFallbackFull.ttf', { type: blob.type })
       }
@@ -654,7 +654,7 @@ class ComPDFKitViewer {
   #formatAnnotation(rawAnnotation) {
     const annotation = {}
     annotation.type = rawAnnotation.type
-    annotation.rect = this.#formatRect(rawAnnotation)
+    rawAnnotation.rect && (annotation.rect = this.#formatRect(rawAnnotation))
     annotation.date = parseAdobePDFTimestamp(rawAnnotation.creationdate)
     annotation.pageIndex = Number(rawAnnotation.page)
     annotation.index = Number(rawAnnotation.index)
@@ -1404,7 +1404,7 @@ class ComPDFKitViewer {
           this.pdfViewer.renderAnnotation(annotation[i], !!data.show)
         }
         annotation[i].targetPage = annotation[i].pageIndex * 1 + 1
-        let currentAnnotation = annotation[i]
+        let currentAnnotation = JSON.parse(JSON.stringify(annotation[i]))
         if (currentAnnotation.inklist) {
           currentAnnotation = this.handleInk(currentAnnotation)
         }
@@ -1413,9 +1413,9 @@ class ComPDFKitViewer {
     } else {
       const annotations = this.annotations[annotation.pageIndex]
       if (!annotations) return
-      const index = findIndex(annotation.name, annotations)
+      const index = findIndex(annotation.name, annotations) 
       if (this.webviewerServer) {
-        annotation.index = index
+        annotation.index = index + 1
       }
       if (data.type === 'delete') {
         annotations.splice(index, 1)
@@ -1531,6 +1531,26 @@ class ComPDFKitViewer {
               delete annotation.pagePtr
             }
             delete annotation.content
+            break
+          case 'inkPointes':
+            const { height } = this.pagesPtr[annotation.pageIndex]
+            const inkPointes = annotation.inkPointes
+            let points = ''
+            for (let i = 0; i < inkPointes.length; i++) {
+              const inkPoint = inkPointes[i]
+              for (let j = 0; j + 1 < inkPoint.length; j+=2) {
+                if (j === 0) {
+                  points+=inkPoint[j].PointX
+                }
+
+                points+=`,${height - inkPoint[j + 1].PointY}`
+              }
+
+              points+='//'
+            }
+            delete annotation.inkPointes
+            annotation.inklist = points
+            break
         }
       }
     }
@@ -1541,7 +1561,7 @@ class ComPDFKitViewer {
     const { left, top: rawTop, right, bottom: rawBottom } = rect
     const top = height - rawTop
     const bottom = height - rawBottom
-    return `${left},${top},${right},${bottom}`
+    return `${left},${bottom},${right},${top}`
   }
 
   #formatLinePointsForBackend(linePoints, pageIndex) {

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

@@ -81,13 +81,6 @@ class CPDFWorker {
       ComPDFKitJS.opened_files = []
       ComPDFKitJS.opened_files[0] = data.buffer
 
-      let reader = new FileReader()
-      reader.onload = async (e) => {
-        let buf = new Uint8Array(e.target.result)
-        console.log(9999)
-        ComPDFKitJS.opened_Font[0] = buf
-        ComPDFKitJS.opened_FontNames[0] = data.fontName
-      }
       if (!data.fontFile) return true
 
       return new Promise((resolve, reject) => {
@@ -97,7 +90,7 @@ class CPDFWorker {
 
           ComPDFKitJS.opened_Font[0] = buf
           ComPDFKitJS.opened_FontNames[0] = data.fontName
-
+          console.log(9999)
           resolve(true)
         }
         fileReader.onerror = () => {