Browse Source

fix: 解决属性转换bug

liutian 1 năm trước cách đây
mục cha
commit
37a5c37c55
32 tập tin đã thay đổi với 200 bổ sung165 xóa
  1. 0 5
      packages/core/rollup.config.js
  2. 1 5
      packages/core/src/TextSelection.ts
  3. 5 6
      packages/core/src/annotation/freetext.js
  4. 3 3
      packages/core/src/annotation/ink.js
  5. 5 6
      packages/core/src/annotation/line.js
  6. 1 1
      packages/core/src/annotation/link.js
  7. 3 3
      packages/core/src/annotation/paint/freetext.js
  8. 1 1
      packages/core/src/annotation/paint/link.js
  9. 5 7
      packages/core/src/annotation/paint/shape.js
  10. 4 3
      packages/core/src/annotation/paint/text.js
  11. 5 6
      packages/core/src/annotation/shape.js
  12. 1 36
      packages/core/src/annotation/stamp.js
  13. 8 9
      packages/core/src/annotation/text.js
  14. 1 1
      packages/core/src/form/add_check_box.js
  15. 1 1
      packages/core/src/form/add_combo_box.js
  16. 1 1
      packages/core/src/form/add_list_box.js
  17. 1 1
      packages/core/src/form/add_push_button.js
  18. 1 1
      packages/core/src/form/add_radio_button.js
  19. 1 1
      packages/core/src/form/add_text_field.js
  20. 2 2
      packages/core/src/form/check_box.js
  21. 1 1
      packages/core/src/form/combo_box.js
  22. 1 1
      packages/core/src/form/list_box.js
  23. 1 1
      packages/core/src/form/push_button.js
  24. 2 2
      packages/core/src/form/radio_button.js
  25. 1 1
      packages/core/src/form/text_field.js
  26. 70 10
      packages/core/src/index.js
  27. 1 1
      packages/core/src/ink_sign.js
  28. 1 1
      packages/core/src/markup/text_annotation.js
  29. 3 2
      packages/core/src/pdf_page_view.js
  30. 67 44
      packages/core/src/worker/compdfkit_worker.js
  31. 1 1
      packages/webview/src/components/AnnotationContainer/AnnotationContent.vue
  32. 1 1
      packages/webview/src/components/DocumentContainer/DocumentContainer.vue

+ 0 - 5
packages/core/rollup.config.js

@@ -11,11 +11,6 @@ const reserved = ['ComPDFKitJS', 'DataArray', 'LineType', 'PageSize', 'Rect', 'R
 const plugins = [
   json(),
   ts(),
-  terser({
-    mangle: {
-      reserved
-    }
-  }),
   nodeResolve({
     preferBuiltins: true,
     mainFields: ['browser']

+ 1 - 5
packages/core/src/TextSelection.ts

@@ -198,7 +198,7 @@ export default class TextSelection {
         operate: "add-annot",
         type: this.tool,
         pageIndex: this.pageIndex,
-        createDate: new Date(),
+        date: new Date(),
         transparency: 0.5,
         quadPoints: this.quadPoints,
         rect: this.rect,
@@ -213,10 +213,6 @@ export default class TextSelection {
         annotation: annotationData
       })
       this.cleanSelection()
-      const pageView = this.pageViewer
-      if (pageView && pageView.compdfAnnotationLayer) {
-        pageView.compdfAnnotationLayer.renderAnnotation(annotationData)
-      }
     }
     this.startPoint = null
     this.endPoint = null

+ 5 - 6
packages/core/src/annotation/freetext.js

@@ -2,7 +2,6 @@ import Base from './base';
 import { ALIGN } from '../../constants'
 import { getActualPoint, getClickPoint, createSvg, keepLastIndex, getInitialPoint, getHtmlToText } from './utils';
 import { hexToRgb, onClickOutside } from '../ui_utils'
-import Color from '../color';
 
 export default class Shape extends Base {
   
@@ -80,8 +79,8 @@ export default class Shape extends Base {
 
     const rect = this.calculate(this.leftTop, this.rightBottom)
 
-    if (!annotation.color) {
-      annotation.color = '#000000'
+    if (!annotation.textColor) {
+      annotation.textColor = '#000000'
     }
 
     if (!annotation.bgColor) {
@@ -115,7 +114,7 @@ export default class Shape extends Base {
       maxWidth: maxWidth+ 'px',
       maxHeight: maxHeight + 'px',
       fontSize: annotation.fontSize + 'px',
-      color: annotation.color,
+      color: annotation.textColor,
       textAlign: textAlignment,
       lineHeight: '1.2em',
       padding: '2px 4px',
@@ -132,7 +131,7 @@ export default class Shape extends Base {
       width: rect.width+ 'px',
       height: rect.height + 'px',
       fontSize: '16px',
-      color: annotation.color,
+      color: annotation.textColor,
       textAlign: textAlignment,
       lineHeight: '1.2em',
       padding: '2px 4px',
@@ -844,10 +843,10 @@ export default class Shape extends Base {
       annotation: {
         operate: "del-annot",
         name: this.annotation.name,
-        annotPtr: this.annotation.annotPtr,
         pageIndex: this.page,
       }
     }
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 3 - 3
packages/core/src/annotation/ink.js

@@ -414,7 +414,7 @@ export default class Ink extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }
@@ -460,12 +460,12 @@ export default class Ink extends Base {
       for (let j = 0; j < this.inkPath[i].length; j++) {
         inkPathPoints.push({
           PointX: this.inkPath[i][j].x / this.scale + initialStart.x,
-          PointY: initialEnd.y - this.inkPath[i][j].y / this.scale
+          PointY: initialStart.y + this.inkPath[i][j].y / this.scale
         })
       }
       inkPointes.push(inkPathPoints)
     }
-
+    console.log(inkPointes)
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
       annotation: {

+ 5 - 6
packages/core/src/annotation/line.js

@@ -5,7 +5,6 @@ import { getAbsoluteCoordinate } from './position';
 import { getClickPoint, createSvg } from './utils';
 import { MARGIN_DISTANCE } from '../../constants'
 import ArrowHelper from './arrow'
-import Color from '../color';
 
 export default class Line extends Base {
   constructor ({
@@ -65,8 +64,8 @@ export default class Line extends Base {
     const innerRect = this.calculate(start, end)
     let arrowLength = Math.max(actualbdwidth * 3, 12 * this.scale)
 
-    if (!annotation.color) {
-      annotation.color = '#FF0000'
+    if (!annotation.borderColor) {
+      annotation.borderColor = '#FF0000'
     }
 
     const rect = {
@@ -85,7 +84,7 @@ export default class Line extends Base {
     line.setAttribute("y1", this.start.y)
     line.setAttribute("x2", this.end.x)
     line.setAttribute("y2", this.end.y)
-    line.setAttribute("stroke", annotation.color)
+    line.setAttribute("stroke", annotation.borderColor)
     line.setAttribute("stroke-width", actualbdwidth)
     if (annotation.transparency) {
       line.setAttribute("stroke-opacity", annotation.transparency)
@@ -115,7 +114,7 @@ export default class Line extends Base {
       }
       arrowUi.forEach(element => {
         if (element) {
-          element.setAttribute("stroke", annotation.color)
+          element.setAttribute("stroke", annotation.borderColor)
           element.setAttribute("stroke-width", actualbdwidth)
           element.setAttribute("fill", "none")
           if(annotation.transparency) {
@@ -447,7 +446,7 @@ export default class Line extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 1 - 1
packages/core/src/annotation/link.js

@@ -619,7 +619,7 @@ export default class Link extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 3 - 3
packages/core/src/annotation/paint/freetext.js

@@ -118,8 +118,8 @@ export default class Freetext {
         operate: "add-annot",
         type: 'freetext',
         pageIndex: this.page,
-        createDate: new Date(),
-        color: '#000000',
+        date: new Date(),
+        textColor: '#000000',
         fontSize: 16,
         fillTransparency: 1,
         fontName: 'Helvetica',
@@ -131,9 +131,9 @@ export default class Freetext {
 
       this.eventBus.dispatch('annotationChange', {
         type: 'add',
+        show: true,
         annotation
       })
-      this.layer.renderAnnotation(annotation, true)
     }
     freetextElement.removeEventListener('blur', this.onBlur)
     freetextElement.remove()

+ 1 - 1
packages/core/src/annotation/paint/link.js

@@ -107,7 +107,7 @@ export default class PaintLink {
         operate: "add-annot",
         type: 'link',
         pageIndex: this.page,
-        createDate: new Date()
+        date: new Date()
       }
 
       const newStart = {

+ 5 - 7
packages/core/src/annotation/paint/shape.js

@@ -6,7 +6,6 @@ import {
   getSvgPathFromStroke
 } from '../utils';
 import ArrowHelper from '../arrow'
-import { hexToRgb } from "../../ui_utils";
 
 // 绘制 Line, Square, Circle, Ink
 export default class PaintShape {
@@ -140,23 +139,20 @@ 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",
         type: this.tool === 'arrow' ? 'line' : this.tool,
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         lineWidth: 2,
         transparency: 0.8,
-        fillTransparency: 1,
-        color,
         borderColor: color,
-        rect,
-        arrow: this.tool === 'arrow',
+        rect
       }
 
       if (annotationData.type == 'line') {
-        const linePoints = [start.x, start.y, end.x, end.y]
         annotationData.linePoints = linePoints
         annotationData.rect = {
           left: left - 6,
@@ -173,6 +169,8 @@ export default class PaintShape {
 
         annotationData.rect = rect
         annotationData.inkPointes = inkPointes
+      } else {
+        annotationData.linePoints = linePoints
       }
 
       this.eventBus.dispatch('annotationChange', {

+ 4 - 3
packages/core/src/annotation/paint/text.js

@@ -104,18 +104,19 @@ export default class Text {
       }
       const rect = this.getTextRect()
       
-      let color = this.color
+      let textColor = this.color
 
       const text = getHtmlToText(textEditorElement)
       const annotation = {
         operate: "add-annot",
         type: 'text',
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         fontSize: 16,
-        color,
+        textColor,
         fontName: 'Helvetica',
         transparency: 1,
+        fillTransparency: 1,
         content: text,
         rect
       }

+ 5 - 6
packages/core/src/annotation/shape.js

@@ -2,7 +2,6 @@ import Base from './base';
 import { MARGIN_DISTANCE } from '../../constants'
 import { getActualPoint, getClickPoint, createSvg } from './utils';
 import { hexToRgb, onClickOutside } from '../ui_utils'
-import Color from '../color';
 
 export default class Shape extends Base {
   
@@ -64,8 +63,8 @@ export default class Shape extends Base {
     const rect = this.calculate(start, end)
     const actualbdwidth = (annotation.lineWidth || annotation.width || 2) * this.scale
 
-    if (!annotation.color) {
-      annotation.color = '#000000'
+    if (!annotation.borderColor) {
+      annotation.borderColor = '#000000'
     }
 
     if (!annotation.fillColor) {
@@ -95,7 +94,7 @@ export default class Shape extends Base {
           y: actualbdwidth / 2,
           width: `${Math.abs(rect.width - actualbdwidth)}px`,
           height: `${Math.abs(rect.height - actualbdwidth)}px`,
-          stroke: annotation.color,
+          stroke: annotation.borderColor,
           'stroke-width': actualbdwidth,
           'stroke-opacity': annotation.transparency || 1,
           fill: annotation.fillColor,
@@ -110,7 +109,7 @@ export default class Shape extends Base {
           cy: rect.height / 2,
           rx: (rect.width - actualbdwidth) / 2,
           ry: (rect.height - actualbdwidth) / 2,
-          stroke: annotation.color,
+          stroke: annotation.borderColor,
           'stroke-width': actualbdwidth,
           'stroke-opacity': annotation.transparency || 1,
           fill: annotation.fillColor,
@@ -575,7 +574,7 @@ export default class Shape extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 1 - 36
packages/core/src/annotation/stamp.js

@@ -85,17 +85,6 @@ export default class Stamp extends Base {
       this.annotation.rect = rect
     }
 
-    for (let key in this.annotation) {
-      if ((key === 'date') && this.annotation.type === 'stamp') {
-        let newName = 'textStampSecondstring'
-
-        const input = this.annotation[key]
-        const date = toDateObject(input)
-        const formattedDate = dayjs(date).format('DD/MM/YYYY HH:mm:ss')
-
-        this.annotation[newName] = formattedDate
-      }
-    }
     const annotation = this.annotation
 
     const { start, end } = this.getActualRect(
@@ -124,30 +113,6 @@ export default class Stamp extends Base {
     imgEle.style.width = "100%"
     imgEle.style.height = "100%"
 
-    const typesArray = [
-      "Approved",
-      "NotApproved",
-      "Completed",
-      "Final",
-      "Draft",
-      "Confidential",
-      "ForPublicRelease",
-      "NotForPublicRelease",
-      "ForComment",
-      "Void",
-      "PreliminaryResults",
-      "InformationOnly",
-      "Accepted",
-      "Rejected",
-      "Witness",
-      "InitialHere",
-      "SignHere",
-      "revised",
-      "PrivateMark#1",
-      "PrivateMark#2",
-      "PrivateMark#3"
-    ]
-
     let imgSrc = ''
     if (annotation.image) {
       imgSrc =  annotation.image
@@ -588,7 +553,7 @@ export default class Stamp extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 8 - 9
packages/core/src/annotation/text.js

@@ -1,7 +1,6 @@
 import Base from './base';
 import { getActualPoint, getClickPoint, createSvg, getHtmlToText, keepLastIndex, getInitialPoint } from './utils';
-import { hexToRgb, onClickOutside } from '../ui_utils'
-import Color from '../color';
+import { onClickOutside } from '../ui_utils'
 
 export default class Text extends Base {
   constructor ({
@@ -86,7 +85,7 @@ export default class Text extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }
@@ -343,8 +342,8 @@ export default class Text extends Base {
 
     const annotation = this.annotation
 
-    if (!annotation.color) {
-      annotation.color = '#FF0000'
+    if (!annotation.textColor) {
+      annotation.textColor = '#FF0000'
     }
 
     const rect = this.rectCalc({start, end})
@@ -361,7 +360,7 @@ export default class Text extends Base {
       width: '24px',
       height: '24px',
       zIndex: 6,
-      color: annotation.color
+      color: annotation.textColor
     })
     annotationContainer.innerHTML = this.textNoteStr
     annotationContainer.addEventListener('click', this.onClick)
@@ -376,10 +375,10 @@ export default class Text extends Base {
       position: 'absolute',
       left: this.rect.left + 16 + 'px',
       top: this.rect.top + 28 + 'px',
-      zIndex: 2,
-      color: this.annotation.color,
+      zIndex: 6,
+      color: this.annotation.textColor,
       border: '2px solid',
-      borderColor: this.annotation.color,
+      borderColor: this.annotation.textColor,
       outline: 'none',
       padding: '0 8px 28px',
       borderRadius: '4px',

+ 1 - 1
packages/core/src/form/add_check_box.js

@@ -130,7 +130,7 @@ export default class AddCheckBox {
         operate: "add-form",
         type: 'checkbox',
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         rect,
         backgroundColor: '#DDE9FF',
         borderColor: '#43474D',

+ 1 - 1
packages/core/src/form/add_combo_box.js

@@ -130,7 +130,7 @@ export default class AddComboBox {
         operate: "add-form",
         type: 'combobox',
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         rect,
         backgroundColor: '#DDE9FF',
         borderColor: '#43474D',

+ 1 - 1
packages/core/src/form/add_list_box.js

@@ -130,7 +130,7 @@ export default class AddListBox {
         operate: "add-form",
         type: 'listbox',
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         rect,
         backgroundColor: '#DDE9FF',
         borderColor: '#43474D',

+ 1 - 1
packages/core/src/form/add_push_button.js

@@ -130,7 +130,7 @@ export default class AddPushButton {
         operate: "add-form",
         type: 'pushbutton',
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         rect,
         backgroundColor: '#DDE9FF',
         borderColor: '#43474D',

+ 1 - 1
packages/core/src/form/add_radio_button.js

@@ -130,7 +130,7 @@ export default class AddRadioButton {
         operate: "add-form",
         type: 'radiobutton',
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         rect,
         backgroundColor: '#DDE9FF',
         borderColor: '#43474D',

+ 1 - 1
packages/core/src/form/add_text_field.js

@@ -130,7 +130,7 @@ export default class AddTextField {
         operate: "add-form",
         type: 'textfield',
         pageIndex: this.page,
-        createDate: new Date(),
+        date: new Date(),
         rect,
         backgroundColor: '#DDE9FF',
         borderColor: '#43474D',

+ 2 - 2
packages/core/src/form/check_box.js

@@ -56,7 +56,7 @@ export default class CheckBox extends Base {
     const annotation = this.annotation
 
     if (!annotation.fieldName) {
-      annotation.fieldName = 'Check Box_' + annotation.createDate.toLocaleString()
+      annotation.fieldName = 'Check Box_' + annotation.date.toLocaleString()
     }
 
     const { start, end } = this.getActualRect(
@@ -708,7 +708,7 @@ export default class CheckBox extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 1 - 1
packages/core/src/form/combo_box.js

@@ -690,7 +690,7 @@ export default class ComboBox extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 1 - 1
packages/core/src/form/list_box.js

@@ -671,7 +671,7 @@ export default class ListBox extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 1 - 1
packages/core/src/form/push_button.js

@@ -652,7 +652,7 @@ export default class PushButton extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 2 - 2
packages/core/src/form/radio_button.js

@@ -56,7 +56,7 @@ export default class RadioButton extends Base {
     const annotation = this.annotation
 
     if (!this.annotation.fieldName) {
-      this.annotation.fieldName = 'Group_' + this.annotation.createDate.toLocaleString()
+      this.annotation.fieldName = 'Group_' + this.annotation.date.toLocaleString()
     }
 
     const { start, end } = this.getActualRect(
@@ -711,7 +711,7 @@ export default class RadioButton extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 1 - 1
packages/core/src/form/text_field.js

@@ -654,7 +654,7 @@ export default class TextField extends Base {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

+ 70 - 10
packages/core/src/index.js

@@ -136,6 +136,7 @@ class ComPDFKitViewer {
       this.webviewerServer = true
     }
 
+    // this.webviewerServer = true
     const verified = await fetch(this.optionUrl.baseUrl + this.optionUrl.verifyUrl, data)
       .then((res) => {
         return res.json()
@@ -229,7 +230,7 @@ class ComPDFKitViewer {
     } else {
       if (Number(annotation.pageIndex) + 1 > this.pagesCount) return
       this.pushAnnotations(annotation)
-      if (!this.webviewerServer) {
+      if (!this.webviewerServer || annotation.type === 'stamp') {
         const pagePtr = this.pagesPtr[annotation.pageIndex].pagePtr
         const annotPtr = await this.messageHandler.sendWithPromise('CreateAnnotation', {
           doc: this.doc,
@@ -238,6 +239,34 @@ class ComPDFKitViewer {
         })
         annotation.pagePtr = pagePtr
         annotation.annotPtr = annotPtr
+
+        if (!annotation.rect && this.webviewerServer) {
+          const getRect = await this.messageHandler.sendWithPromise('GetAnnotRect', {
+            pagePtr: pagePtr,
+            annotPtr: annotPtr
+          })
+
+          let pageView = this.pdfViewer.getPageView(annotation.pageIndex)
+
+          const pageWidth = pageView.viewport.viewBox[2]
+          const pageHeight = pageView.viewport.viewBox[3]
+          const imgWidth = getRect.right - getRect.left
+          const imgHeight = getRect.bottom - getRect.top
+    
+          const left = (pageWidth - imgWidth) / 2
+          const top = (pageHeight - imgHeight) / 2
+          const right = (pageWidth + imgWidth) / 2
+          const bottom = (pageHeight + imgHeight) / 2
+    
+          const rect = {
+            left,
+            top,
+            right,
+            bottom,
+          }
+
+          annotation.rect = rect
+        }
       }
     }
   }
@@ -368,8 +397,10 @@ class ComPDFKitViewer {
           }
 
           let buffer = new Uint8Array(binaryData)
-          this.messageHandler.sendWithPromise('LoadFile', {
-            buffer
+          await this.messageHandler.sendWithPromise('LoadFile', {
+            buffer,
+            fontFile: this.#fonFile,
+            fontName: 'DroidSansFallbackFull'
           })
 
           const loadRes = await this.messageHandler.sendWithPromise('LoadDocumentByStream', {
@@ -624,7 +655,7 @@ class ComPDFKitViewer {
     const annotation = {}
     annotation.type = rawAnnotation.type
     annotation.rect = this.#formatRect(rawAnnotation)
-    annotation.createDate = parseAdobePDFTimestamp(rawAnnotation.creationdate)
+    annotation.date = parseAdobePDFTimestamp(rawAnnotation.creationdate)
     annotation.pageIndex = Number(rawAnnotation.page)
     annotation.index = Number(rawAnnotation.index)
     annotation.content = rawAnnotation.contents || ''
@@ -651,7 +682,7 @@ class ComPDFKitViewer {
         }
         break
       case 'text':
-        annotation.color = rawAnnotation.color
+        annotation.textColor = rawAnnotation.color
         break
       case 'highlight':
       case 'underline':
@@ -664,12 +695,12 @@ class ComPDFKitViewer {
         annotation.linePoints = this.#formatLinePoints(rawAnnotation)
         annotation.tail = rawAnnotation.tail
         annotation.head = rawAnnotation.head
-        annotation.color = rawAnnotation.color
+        annotation.borderColor = rawAnnotation.color
         annotation.lineWidth = round(rawAnnotation.width, 2)
         break
       case 'square':
       case 'circle':
-        annotation.color = rawAnnotation.color
+        annotation.borderColor = rawAnnotation.color
         annotation.lineWidth = round(rawAnnotation.width, 2)
         rawAnnotation['interior-opacity'] && (annotation.fillTransparency = round(rawAnnotation['interior-opacity'], 2))
         rawAnnotation['interior-color'] && (annotation.fillColor = rawAnnotation['interior-color'])
@@ -1460,6 +1491,12 @@ class ComPDFKitViewer {
     console.log(annotations)
     for (let i =0; i < annotations.length; i++) {
       const annotation = annotations[i]
+      switch (annotation.type) {
+        case 'freetext':
+          annotation.fillColor = annotation.bgColor
+          delete annotation.bgColor
+          break
+      }
       for (let key in annotation) {
         switch (key) {
           case 'rect':
@@ -1471,6 +1508,29 @@ class ComPDFKitViewer {
           case 'borderWidth':
             annotation.lineWidth = annotation.borderWidth
             break
+          case 'textAlignment':
+            annotation.alignment = annotation.textAlignment
+            delete annotation.textAlignment
+            break
+          case 'stampType':
+            if (annotation.stampType === 'standard') {
+              annotation.standardStampType = annotation.content
+            } else if (annotation.stampType === 'text') {
+              annotation.textStampFirststring = annotation.content
+              annotation.textStampSecondstring = annotation.time
+              annotation.textStampColor = annotation.stampColor
+              annotation.textStampShape = annotation.stampShape
+
+              delete annotation.time
+              delete annotation.stampColor
+              delete annotation.stampShape
+            } else if (annotation.stampType === 'image') {
+              annotation.type = 'image'
+              delete annotation.annotPtr
+              delete annotation.imageData
+              delete annotation.pagePtr
+            }
+            delete annotation.content
         }
       }
     }
@@ -2360,7 +2420,7 @@ class ComPDFKitViewer {
         pageIndex: pageNum - 1,
         rect,
         stampColor: 'white',
-        createDate: new Date(),
+        date: new Date(),
         stampType: 'standard',
         content: imgUi.alt
       }
@@ -2369,11 +2429,11 @@ class ComPDFKitViewer {
       annotData = {
         operate: 'add-annot',
         type: 'stamp',
-        createDate: new Date(),
+        date: new Date(),
         pageIndex: pageNum - 1,
         // rect,
         content: data.text,
-        date: data.time,
+        time: data.time,
         stampColor: data.color,
         stampType: 'text'
       }

+ 1 - 1
packages/core/src/ink_sign.js

@@ -255,7 +255,7 @@ class InkSign {
       type: "image",
       pageIndex: this.layerData.page + 1,
       imageBase64: this.dataURL,
-      createDate: new Date(),
+      date: new Date(),
       // targetPage: pageNum,
       // date: new Date(),
       // name: uuidv4()

+ 1 - 1
packages/core/src/markup/text_annotation.js

@@ -217,7 +217,7 @@ class TextAnnotation extends BaseAnnotation {
         pageIndex: this.page
       }
     }
-    this.annotation.annotPtr && (annotationData.annotPtr = this.annotation.annotPtr)
+    this.annotation.annotPtr && (annotationData.annotation.annotPtr = this.annotation.annotPtr)
     if (!event) {
       annotationData.type = 'empty'
     }

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

@@ -224,7 +224,7 @@ class PDFPageView {
             lineWidth: signImg.inkParam.width || 1,
             color: signImg.inkParam.color || "#000",
             date: new Date(),
-            createDate: new Date(),
+            date: new Date(),
             name: uuidv4()
           }
         } else {
@@ -234,6 +234,7 @@ class PDFPageView {
             type: "stamp",
             stampType: 'image',
             pageIndex,
+            imageBase64: imgData,
             imageData,
             rect: {
               left,
@@ -243,7 +244,7 @@ class PDFPageView {
             },
             targetPage: pageNum,
             date: new Date(),
-            createDate: new Date(),
+            date: new Date(),
             name: uuidv4()
           }
         }

+ 67 - 44
packages/core/src/worker/compdfkit_worker.js

@@ -4,6 +4,8 @@ import { parseAdobePDFTimestamp, convertToPDFTimestamp, roundToDecimalPlaces, co
 import { AnnotationType, WidgetType, LineTypeString, StampType, StampTypeString, TextStampShapeString, ActionTypeString, WidgetTypeString, AnnotationFlags, BorderStyleInt, BorderStyleString, ALIGN, ALIGNMAP } from '../../constants'
 
 let ComPDFKitJS = {}
+ComPDFKitJS.opened_Font = []
+ComPDFKitJS.opened_FontNames = []
 let DataArray = []
 let LineType = {}
 let BorderStyle = {}
@@ -78,11 +80,36 @@ class CPDFWorker {
     messageHandler.on('LoadFile', (data) => {
       ComPDFKitJS.opened_files = []
       ComPDFKitJS.opened_files[0] = data.buffer
-      return true
+
+      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) => {
+        const fileReader = new FileReader()
+        fileReader.onload = () => {
+          const buf = new Uint8Array(fileReader.result)
+
+          ComPDFKitJS.opened_Font[0] = buf
+          ComPDFKitJS.opened_FontNames[0] = data.fontName
+
+          resolve(true)
+        }
+        fileReader.onerror = () => {
+          reject(fileReader.error)
+        }
+        fileReader.readAsArrayBuffer(data.fontFile)
+      })
     })
 
     messageHandler.on('LoadDocumentByStream', (data) => {
       const { doc, fileId, length, password: rawPassword } = data
+
       const password = stringToNewUTF8(rawPassword)
       return Module._LoadDocumentByStream(doc, fileId, length, password)
     })
@@ -984,21 +1011,9 @@ class CPDFWorker {
     })
 
     messageHandler.on('SetFontCallBackForEditPage', (data) => {
-      const { editPagePtr, file } = data
+      const { editPagePtr } = data
 
-      let reader = new FileReader()
-      reader.onload = async (e) => {
-        let buf = new Uint8Array(e.target.result)
-        ComPDFKitJS.opened_Font = []
-        ComPDFKitJS.opened_FontNames = []
-        let cur_file_id = 0
-        cur_file_id = ComPDFKitJS.opened_Font.length
-        ComPDFKitJS.opened_Font[cur_file_id] = buf
-        ComPDFKitJS.opened_FontNames[cur_file_id] = 'DroidSansFallbackFull'
-
-        Module._SetFontCallBackForEditPage(editPagePtr)
-      }
-      reader.readAsArrayBuffer(file)
+      Module._SetFontCallBackForEditPage(editPagePtr)
     })
   }
 
@@ -1052,7 +1067,7 @@ function createAnnotation(doc, pagePtr, annotation) {
 
   const annotPtr = Module._CreateAnnot(doc, pagePtr, typeInt)
 
-  const { color, lineWidth, content, createDate, transparency, fillTransparency, rect } = annotation
+  const { color, lineWidth, content, date, transparency, fillTransparency, rect } = annotation
   if (color) {
     setAnnotRGBColor({
       annotPtr,
@@ -1067,10 +1082,10 @@ function createAnnotation(doc, pagePtr, annotation) {
     })
   }
 
-  if (createDate) {
+  if (date) {
     setAnnotCreationDate({
       annotPtr,
-      createDate
+      date
     })
   }
 
@@ -1097,11 +1112,15 @@ function createAnnotation(doc, pagePtr, annotation) {
   }
   switch (typeInt) {
     case AnnotationType.TEXT:
+      setAnnotRGBColor({
+        annotPtr,
+        color: annotation.textColor
+      })
       break
     case AnnotationType.LINK:
       break
     case AnnotationType.FREETEXT:
-      const { bgColor, fontName, fontSize, textAlignment } = annotation
+      const { bgColor, fontName, fontSize, textAlignment, textColor } = annotation
       if (bgColor) {
         Module._SetFreeTextBgColor(annotPtr, bgColor.R / 255, bgColor.G / 255, bgColor.B / 255)
       } else {
@@ -1112,7 +1131,7 @@ function createAnnotation(doc, pagePtr, annotation) {
         annotPtr,
         fontName,
         fontSize,
-        color,
+        textColor,
         textAlignment,
         content
       })
@@ -1127,10 +1146,12 @@ function createAnnotation(doc, pagePtr, annotation) {
     case AnnotationType.CIRCLE:
       createShape({
         annotPtr,
-        color,
         lineWidth,
-        transparency,
-        fillTransparency
+      })
+
+      setAnnotRGBColor({
+        annotPtr,
+        color: annotation.borderColor
       })
       break
     case AnnotationType.HIGHLIGHT:
@@ -1188,15 +1209,15 @@ function createAnnotation(doc, pagePtr, annotation) {
 }
 
 function createWidget(doc, pagePtr, annotation) {
-  const { type, createDate, fieldName, backgroundColor, checkStyle, rect } = annotation
+  const { type, date, fieldName, backgroundColor, checkStyle, rect } = annotation
 
   const typeInt = WidgetType[type.toUpperCase()]
   const annotPtr = Module._CreateWidget(doc, pagePtr, typeInt)
 
-  if (createDate) {
+  if (date) {
     setAnnotCreationDate({
       annotPtr,
-      createDate
+      date
     })
   }
 
@@ -1432,8 +1453,8 @@ function getAnnotation({
   }
 
   Module._GetAnnotCreationDate(annotPtr)
-  const rawCreateDate = U8StringData
-  const createDate = parseAdobePDFTimestamp(rawCreateDate)
+  const rawDate = U8StringData
+  const date = parseAdobePDFTimestamp(rawDate)
   Module._GetAnnotContent(annotPtr)
   const content = U8StringData
   Module._GetAnnotTitle(annotPtr)
@@ -1442,7 +1463,7 @@ function getAnnotation({
   const transparency = roundToDecimalPlaces(Module._GetAnnotTransparency(annotPtr))
 
   const annotation = {
-    createDate,
+    date,
     content,
     rect,
     transparency
@@ -1459,7 +1480,7 @@ function getAnnotation({
       if (hasColor) {
         const { R, G, B } = RGBColor
         const hex = convertCppRGBToHex(R, G, B)
-        annotation.color = hex
+        annotation.textColor = hex
       }
 
       return annotation
@@ -1497,7 +1518,7 @@ function getAnnotation({
 
       const { R, G, B } = FontDa
       const hex = convertCppRGBToHex(R, G, B)
-      annotation.color = hex
+      annotation.textColor = hex
 
       Module._GetFreeTextContent(annotPtr)
       const freetextContent = U8StringData
@@ -1528,7 +1549,7 @@ function getAnnotation({
         const { R, G, B } = RGBColor
         const hex = convertCppRGBToHex(R, G, B)
 
-        annotation.color = hex
+        annotation.borderColor = hex
       }
 
       annotation.lineWidth = Module._GetAnnotBorderWidth(annotPtr)
@@ -1545,7 +1566,7 @@ function getAnnotation({
         const { R, G, B } = RGBColor
         const hex = convertCppRGBToHex(R, G, B)
 
-        annotation.color = hex
+        annotation.borderColor = hex
       }
 
       RGBColor = {}
@@ -1625,15 +1646,15 @@ function getWidgetAnnotation({
   }
 
   Module._GetAnnotCreationDate(annotPtr)
-  const rawCreateDate = U8StringData
-  const createDate = parseAdobePDFTimestamp(rawCreateDate)
+  const rawDate = U8StringData
+  const date = parseAdobePDFTimestamp(rawDate)
   Module._GetAnnotContent(annotPtr)
   const content = U8StringData
 
   const type = Module._GetWidgetType(annotPtr)
 
   const annotation = {
-    createDate,
+    date,
     content,
     rect,
     type: WidgetTypeString[type]
@@ -1919,10 +1940,10 @@ function exportXFDFByStream(doc) {
 }
 
 function setAnnotCreationDate(data) {
-  const { annotPtr, createDate: rawCreateDate } = data
+  const { annotPtr, date: rawDate } = data
 
-  const createDate = stringToNewUTF8(convertToPDFTimestamp(rawCreateDate))
-  Module._SetAnnotCreationDate(annotPtr, createDate)
+  const date = stringToNewUTF8(convertToPDFTimestamp(rawDate))
+  Module._SetAnnotCreationDate(annotPtr, date)
 }
 
 function setAnnotRect(data) {
@@ -2196,12 +2217,14 @@ function createMarkup(data) {
 }
 
 function setFreeText(data) {
-  const { annotPtr, fontName: rawFontName, fontSize, color, textAlignment, content: rawContent } = data
+  const { annotPtr, fontName: rawFontName, fontSize, textColor: rawTextColor, textAlignment, content: rawContent } = data
 
   const fontName = stringToNewUTF8(rawFontName)
   const content = stringToNewUTF8(rawContent)
 
-  Module._SetFreeText(annotPtr, fontName, fontSize, color.R / 255, color.G / 255, color.B / 255, textAlignment, content)
+  const textColor = convertColorToCppFormat(rawTextColor)
+
+  Module._SetFreeText(annotPtr, fontName, fontSize, textColor.R / 255, textColor.G / 255, textColor.B / 255, textAlignment, content)
 }
 
 function createShape(data) {
@@ -2220,12 +2243,12 @@ function createStandardStamp(data) {
 }
 
 function createTextStamp(data) {
-  const { annotPtr, content: rawContent, date: rawDate, stampShape, stampColor } = data
+  const { annotPtr, content: rawContent, time: rawTime, stampShape, stampColor } = data
 
   const content = stringToNewUTF8(rawContent)
-  const date = stringToNewUTF8(rawDate)
+  const time = stringToNewUTF8(rawTime)
 
-  Module._SetTextStamp(annotPtr, content, date, stampShape, stampColor, 0)
+  Module._SetTextStamp(annotPtr, content, time, stampShape, stampColor, 0)
 }
 
 function createImageStamp(data) {

+ 1 - 1
packages/webview/src/components/AnnotationContainer/AnnotationContent.vue

@@ -22,7 +22,7 @@
                 <Text v-else-if="item.type === 'freetext'" />
                 <Note v-else-if="item.type === 'text'" />
                 <Stamp v-else-if="item.type === 'image' || item.type === 'stamp'" />
-                <span>{{ dayjs(item.createDate).format('DD/MM/YYYY HH:mm:ss') }}</span>
+                <span>{{ dayjs(item.date).format('DD/MM/YYYY HH:mm:ss') }}</span>
               </div>
               <div v-if="item.contents || item.content" class="item-content">{{ item.contents || item.content }}</div>
             </div>

+ 1 - 1
packages/webview/src/components/DocumentContainer/DocumentContainer.vue

@@ -169,7 +169,7 @@ async function handlePdf(pdf, filename = null) {
 
 onMounted(async () => {
   const res = await initConfig({
-    license: '3AxOJBuKTqXhp+I9om9P+fvB2DMYXQbYnwfM7uExRRo='
+    license: 'DlBW5J86C/sasggOf2aIPP/zHK0MquYQ88NjifgMxDs='
     // license: 'QSy1pbS2oS2Szj1i6oVBY3ZN6fMyhn6rqBLWIBNnez4='
     // license: 'pB3xWyaCvnrPR/fDkBPjh+E1LeA0e+bEj6Z7a5VI1tQ='
     // license: 'e+L5dBrcDnQJXP98kF7oHEo11SLrWIWse5oWqj5ykMU='