Browse Source

fix: 修复api调用添加注释bugfix: 修复api调用添加注释bug

liutian 1 year ago
parent
commit
98fc4d6742

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

@@ -152,7 +152,7 @@ export default class AddListBox {
             String: this.layer.annotationStore.$t('rightPanel.option') + '2'
           }
         ],
-        selected: null
+        selected: 0
       }
 
       this.eventBus.dispatch('annotationChange', {

+ 2 - 0
packages/core/src/form/combo_box.js

@@ -963,6 +963,8 @@ export default class ComboBox extends Base {
       }
 
       const updateAnnot = Object.assign({}, annotationData, props)
+      !annotation.annotPtr && (updateAnnot.items = annotation.items)
+
       this.eventBus.dispatch('annotationChange', {
         type: 'modify',
         annotation: updateAnnot

+ 2 - 0
packages/core/src/form/list_box.js

@@ -952,6 +952,8 @@ export default class ListBox extends Base {
       }
 
       const updateAnnot = Object.assign({}, annotationData, props)
+      !annotation.annotPtr && (updateAnnot.items = annotation.items)
+
       this.eventBus.dispatch('annotationChange', {
         type: 'modify',
         annotation: updateAnnot

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

@@ -231,6 +231,10 @@ class ComPDFKitViewer {
       if (Number(annotation.pageIndex) + 1 > this.pagesCount) return
       this.pushAnnotations(annotation)
       if (!this.webviewerServer || annotation.type === 'stamp') {
+        if ('destPage' in annotation) {
+          annotation.doc = this.doc
+          annotation.pageHeight = this.pagesPtr[annotation.pageIndex].height
+        }
         const pagePtr = this.pagesPtr[annotation.pageIndex].pagePtr
         const annotPtr = await this.messageHandler.sendWithPromise('CreateAnnotation', {
           doc: this.doc,
@@ -790,7 +794,7 @@ class ComPDFKitViewer {
         annotation.isMultiLine = rawAnnotation.textStyle.multiLine === 'true' ? 1 : 0
         annotation.isHidden = !rawAnnotation.flags && rawAnnotation.flags === 'invisible' ? 1 : 0
         annotation.items = this.#getItems(rawAnnotation)
-        annotation.selected = round(rawAnnotation.select, 0)
+        annotation.selected = round(rawAnnotation.select, 0) - 1
         break
       case 'pushbutton': {
         const pushbuttonAction = rawAnnotation.OnActivation && rawAnnotation.OnActivation.Action
@@ -1591,6 +1595,8 @@ class ComPDFKitViewer {
         case 'listbox':
           annotation.type = 'list-box'
           annotation.color && (annotation.textColor = annotation.color)
+          'selected' in annotation && (annotation.selecte = annotation.selected)
+          delete annotation.selected
           delete annotation.color
           break
         case 'combobox':
@@ -1601,12 +1607,14 @@ class ComPDFKitViewer {
         case 'pushbutton':
           annotation.type = 'push-button'
           annotation.color && (annotation.textColor = annotation.color)
+          'destPage' in annotation && (annotation.destPage = annotation.destPage - 1)
           delete annotation.color
           break
       }
 
       if (annotation.operate === 'mod-form') {
         annotation.color && (annotation.textColor = annotation.color)
+        'destPage' in annotation && (annotation.destPage = annotation.destPage - 1)
         delete annotation.color
       }
 

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

@@ -1261,7 +1261,11 @@ function createWidget(doc, pagePtr, annotation) {
     })
   }
 
-  const { borderColor, borderWidth, borderStyle, isChecked, color, fontName, fontSize } = annotation
+  let { borderColor, borderWidth, borderStyle, isChecked, color, fontName, fontSize } = annotation
+  !borderColor && (borderColor = '#43474D')
+  !borderStyle && (borderStyle = 'solid')
+  !borderWidth && borderWidth !== 0 && (borderWidth = 1)
+
   setWidgetBorder({
     annotPtr,
     borderColor,
@@ -1335,6 +1339,12 @@ function createWidget(doc, pagePtr, annotation) {
       Module._SetMultiLine(annotPtr, isMultiLine)
       Module._SetWidgetTextJustification(annotPtr, textAlignmentInt)
       Module._SetTextFieldSpe(annotPtr, 0)
+      if ('contents' in annotation) {
+        setTextFieldContent({
+          annotPtr,
+          contents: annotation.contents
+        })
+      }
       setAnnotFontData({
         annotPtr,
         fontName,