Browse Source

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

liutian 1 year ago
parent
commit
51d342805f

+ 4 - 4
packages/core/src/annotation/freetext.js

@@ -79,8 +79,8 @@ export default class Shape extends Base {
 
     const rect = this.calculate(this.leftTop, this.rightBottom)
 
-    if (!annotation.textColor) {
-      annotation.textColor = '#000000'
+    if (!annotation.color) {
+      annotation.color = '#000000'
     }
 
     if (!annotation.bgColor) {
@@ -114,7 +114,7 @@ export default class Shape extends Base {
       maxWidth: maxWidth+ 'px',
       maxHeight: maxHeight + 'px',
       fontSize: annotation.fontSize + 'px',
-      color: annotation.textColor,
+      color: annotation.color,
       textAlign: textAlignment,
       lineHeight: '1.2em',
       padding: '2px 4px',
@@ -131,7 +131,7 @@ export default class Shape extends Base {
       width: rect.width+ 'px',
       height: rect.height + 'px',
       fontSize: '16px',
-      color: annotation.textColor,
+      color: annotation.color,
       textAlign: textAlignment,
       lineHeight: '1.2em',
       padding: '2px 4px',

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

@@ -119,7 +119,7 @@ export default class Freetext {
         type: 'freetext',
         pageIndex: this.page,
         date: new Date(),
-        textColor: '#000000',
+        color: '#000000',
         fontSize: 16,
         fillTransparency: 1,
         fontName: 'Helvetica',

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

@@ -1525,6 +1525,8 @@ class ComPDFKitViewer {
           break
         case 'freetext':
           annotation.fillColor = annotation.bgColor
+          annotation.textColor = annotation.color
+          delete annotation.color
           delete annotation.bgColor
           break
         case 'highlight':
@@ -1537,6 +1539,13 @@ class ComPDFKitViewer {
         case 'square':
         case 'circle':
           annotation.arrow = false
+          if (!annotation.linePoints) {
+          const { left, top, right, bottom } = annotation.rect
+            annotation.linePoints = [left, bottom, right, top]
+          }
+          if (!annotation.opacity && annotation.opacity !== 0) {
+            annotation.transparency = 1
+          }
           break
         case 'line':
           if (annotation.tail === 'OpenArrow' || annotation.arrow) {

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

@@ -1076,7 +1076,7 @@ function createAnnotation(doc, pagePtr, annotation) {
   const typeInt = AnnotationType[annotation.type.toUpperCase()]
 
   const annotPtr = Module._CreateAnnot(doc, pagePtr, typeInt)
-
+  annotation.annotPtr = annotPtr
   const { color, borderWidth, contents, date, opacity, fillTransparency, rect } = annotation
   if (color) {
     setAnnotRGBColor({
@@ -1124,9 +1124,15 @@ function createAnnotation(doc, pagePtr, annotation) {
     case AnnotationType.TEXT:
       break
     case AnnotationType.LINK:
+      if (annotation.destPage ) {
+        setLinkDest(annotation)
+      }
+      if (annotation.url) {
+        setLinkUri(annotation)
+      }
       break
     case AnnotationType.FREETEXT:
-      const { bgColor, fontName, fontSize, textAlignment, textColor } = annotation
+      const { bgColor, fontName, fontSize, textAlignment, color } = annotation
       if (bgColor) {
         Module._SetFreeTextBgColor(annotPtr, bgColor.R / 255, bgColor.G / 255, bgColor.B / 255)
       } else {
@@ -1137,7 +1143,7 @@ function createAnnotation(doc, pagePtr, annotation) {
         annotPtr,
         fontName,
         fontSize,
-        textColor,
+        color,
         textAlignment,
         contents
       })
@@ -1163,8 +1169,8 @@ function createAnnotation(doc, pagePtr, annotation) {
     case AnnotationType.HIGHLIGHT:
     case AnnotationType.UNDERLINE:
     case AnnotationType.SQUIGGLY:
-    case AnnotationType.STRIKEOUT:
-      const { quadPoints } = annotation
+    case AnnotationType.STRIKEOUT: {
+      const { quadPoints, color } = annotation
       createMarkup({
         pagePtr,
         annotPtr,
@@ -1172,6 +1178,7 @@ function createAnnotation(doc, pagePtr, annotation) {
         quadPoints
       })
       break
+    }
     case AnnotationType.STAMP:
       const { stampType } = annotation
       if (stampType === 'standard') {
@@ -1224,6 +1231,7 @@ function createWidget(doc, pagePtr, annotation) {
 
   const typeInt = WidgetType[type.toUpperCase()]
   const annotPtr = Module._CreateWidget(doc, pagePtr, typeInt)
+  annotation.annotPtr = annotPtr
 
   if (date) {
     setAnnotCreationDate({
@@ -1313,6 +1321,13 @@ function createWidget(doc, pagePtr, annotation) {
       const { title: rawTitle } = annotation
       const title = stringToNewUTF8(rawTitle)
       Module._SetButtonTitle(annotPtr, title)
+
+      if (annotation.destPage) {
+        setPushButtonDest(annotation)
+      }
+      if (annotation.url) {
+        setPushButtonUri(annotation)
+      }
       break
     case 'textfield':
       const { isMultiLine, textAlignment } = annotation
@@ -2220,14 +2235,14 @@ function createMarkup(data) {
 }
 
 function setFreeText(data) {
-  const { annotPtr, fontName: rawFontName, fontSize, textColor: rawTextColor, textAlignment, contents: rawContents } = data
+  const { annotPtr, fontName: rawFontName, fontSize, color: rawColor, textAlignment, contents: rawContents } = data
   const textAlignmentInt = ALIGNMAP[textAlignment.toUpperCase()]
   const fontName = stringToNewUTF8(rawFontName)
   const contents = stringToNewUTF8(rawContents)
 
-  const textColor = convertColorToCppFormat(rawTextColor)
+  const color = convertColorToCppFormat(rawColor)
 
-  Module._SetFreeText(annotPtr, fontName, fontSize, textColor.R / 255, textColor.G / 255, textColor.B / 255, textAlignmentInt, contents)
+  Module._SetFreeText(annotPtr, fontName, fontSize, color.R / 255, color.G / 255, color.B / 255, textAlignmentInt, contents)
 }
 
 function createShape(data) {