Przeglądaj źródła

add: 接口调试

wzl 1 miesiąc temu
rodzic
commit
389eddca2a

+ 6 - 2
packages/core/constants/index.js

@@ -127,7 +127,9 @@ const AnnotationType = {
   TRAPNET: 23,
   WATERMARK: 24,
   THREED: 25,
-  REDACT: 26,
+  RICHMEDIA: 26,
+  REDACT: 27,
+  INTERCHANGE: 28,
 };
 
 const AnnotationTypeString = {
@@ -156,7 +158,9 @@ const AnnotationTypeString = {
   23: 'trapnet',
   24: 'watermark',
   25: 'threed',
-  26: 'redact',
+  26: 'richmedia',
+  27: 'redact',
+  28: 'interchange',
 };
 
 const WidgetType = {

+ 26 - 19
packages/core/src/TextSelection.ts

@@ -3,8 +3,8 @@ import copy from 'copy-to-clipboard';
 import { getAbsoluteCoordinate, getInitialPoint, getActualPoint } from './annotation/utils.js';
 import { isMobileDevice } from './ui_utils';
 
-const markupType = isMobileDevice ? ['highlight', 'underline', 'squiggly', 'strikeout', 'selectText'] : ['highlight', 'underline', 'squiggly', 'strikeout', '']
-const markupTypeNotNull = ['highlight', 'underline', 'squiggly', 'strikeout']
+const markupType = isMobileDevice ? ['highlight', 'underline', 'squiggly', 'strikeout', 'selectText'] : ['highlight', 'underline', 'squiggly', 'strikeout', '', 'redaction', 'remove']
+const markupTypeNotNull = ['highlight', 'underline', 'squiggly', 'strikeout', 'redaction', 'remove']
 type Point = {
   x: number,
   y: number
@@ -91,7 +91,7 @@ export default class TextSelection {
     document.removeEventListener('touchmove', this.handleMouseMove)
     document.removeEventListener('dblclick', this.handleDobuleClick)
 
-    if (this.toolMode === 'view' || this.toolMode === 'annotation') {
+    if (['view', 'annotation', 'security'].includes(this.toolMode)) {
       document.addEventListener('keydown', this.handleKeyDown)
       document.addEventListener('mousedown', this.handleMouseDown)
       document.addEventListener('touchstart', this.handleMouseDown)
@@ -166,7 +166,7 @@ export default class TextSelection {
     }
   }
 
-  handleMouseDown(event: MouseEvent) {
+  async handleMouseDown(event: MouseEvent) {
     // return的几种情况:
     // 文本悬浮菜单下,且不清空选中文本
     if (this.isTargetInElement(event.target, '.text-popup')) return
@@ -201,7 +201,8 @@ export default class TextSelection {
     const { x, y } = inPage
     const point = getInitialPoint({ x, y }, this.viewport, this.scale)
     this.startPoint = point
-    this.selecting = true
+    const isText = await this.isTextAtPoint(point)
+    this.selecting = !!isText
 
     document.addEventListener('mouseup', this.handleMouseUp)
     document.addEventListener('touchend', this.handleMouseUp)
@@ -215,12 +216,7 @@ export default class TextSelection {
     }
     const { x, y } = inPage
     const point = getInitialPoint({ x, y }, this.viewport, this.scale)
-
-    const isText = await this.messageHandler.sendWithPromise('GetCharIndexAtPos', {
-      pagePtr: this.#pagePtr,
-      textPtr: this.#textPtr,
-      point
-    })
+    const isText = await this.isTextAtPoint(point)
     const startPoint = this.startPoint
     if (startPoint && (startPoint.x === point.x || startPoint.y === point.y)) return
     if (isText) {
@@ -252,13 +248,7 @@ export default class TextSelection {
     }
     const { x, y } = inPage
     const point = getInitialPoint({ x, y }, this.viewport, this.scale)
-
-    const isText = await this.messageHandler.sendWithPromise('GetCharIndexAtPos', {
-      pagePtr: this.#pagePtr,
-      textPtr: this.#textPtr,
-      point
-    })
-
+    const isText = await this.isTextAtPoint(point)
     if (!isText) return
 
     const selection = await this.messageHandler.sendWithPromise('GetSelectionForWordAtPos', {
@@ -278,7 +268,7 @@ export default class TextSelection {
   handleMouseUp() {
     if (this.selecting && this._selection && markupTypeNotNull.includes(this.tool)) {
       const annotationData = {
-        operate: "add-annot",
+        operate: 'add-annot',
         type: this.tool,
         pageIndex: this.pageIndex,
         date: new Date(),
@@ -288,6 +278,12 @@ export default class TextSelection {
         color: this.color,
         contents: this._selection.textContent || undefined
       }
+      if (this.tool === 'redaction' || this.tool === 'remove') {
+        annotationData.type = 'redact'
+        annotationData.erasure = this.tool === 'remove'
+        annotationData.fillColor = 'rgb(0, 0, 0)'
+        delete annotationData.opacity
+      }
 
       this.eventBus.dispatch('annotationChange', {
         type: 'add',
@@ -309,6 +305,7 @@ export default class TextSelection {
   updateSelection() {
     const textRects = this._selection.textRects
     this.textContainer?.textContent = ''
+    const rects = []
     const quadPoints = []
     const topArray = []
     const bottomArray = []
@@ -344,9 +341,11 @@ export default class TextSelection {
         PointY: bottom
       }
       quadPoints.push(leftTop, rightTop, leftBottom, rightBottom)
+      rects.push(rect)
       this.drawSelection(rect)
     }
     this.quadPoints = quadPoints
+    this.rects = rects
     const top = Math.min(...topArray)
     const bottom = Math.max(...bottomArray)
     const left = Math.min(...leftArray)
@@ -468,4 +467,12 @@ export default class TextSelection {
     if (el && el.contains(target)) return true
     else return false
   }
+
+  async isTextAtPoint(point: Point): boolean {
+    return await this.messageHandler.sendWithPromise('GetCharIndexAtPos', {
+      pagePtr: this.#pagePtr,
+      textPtr: this.#textPtr,
+      point
+    })
+  }
 }

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

@@ -858,7 +858,7 @@ class ComPDFAnnotationLayer {
         messageHandler: this.messageHandler
       })
       this.annotationsArray.push(signatureFields)
-    } else if ((annotation.type === 'redaction' || annotation.type === 'remove') && !annotation.isDelete) {
+    } else if (annotation.type === 'redact' && !annotation.isDelete) {
       const redaction = new Redaction({
         container: this.div,
         annotation,

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

@@ -81,7 +81,7 @@ export default class PaintRedaction {
   }
 
   handleMouseDown (event) {
-    if (this.layer.annotationStore.selectedElementName) return
+    if (this.layer.annotationStore.selectedElementName || this.container.classList.contains('text')) return
     const { x, y } = getAbsoluteCoordinate(this.container, event)
     this.initStartPoint = { x, y }
 

+ 3 - 4
packages/core/src/annotation/redaction.js

@@ -56,7 +56,6 @@ export default class Redaction extends Base {
     )
     this.start = start
     this.end = end
-    this.isRedaction = this.annotation.type === 'redaction'
 
     const rect = this.calculate(start, end)
     
@@ -71,7 +70,7 @@ export default class Redaction extends Base {
 
     const actualbdwidth = (annotation.borderWidth || 2) * this.scale
     let shapeElement
-    if (this.isRedaction) {
+    if (!annotation.erasure) {
       shapeElement = createElement(
         'div',
         {
@@ -174,11 +173,11 @@ export default class Redaction extends Base {
     this.outerLineContainer.append(this.outerLine)
     this.outerLineContainer.append(this.deletetButton)
 
-    this.isRedaction && this.moveRect.addEventListener('mouseenter', () => {
+    !annotation.erasure && this.moveRect.addEventListener('mouseenter', () => {
       this.shapeElement.style.backgroundColor = '#000000'
       this.shapeElement.style.border = ''
     })
-    this.isRedaction && this.moveRect.addEventListener('mouseleave', () => {
+    !annotation.erasure && this.moveRect.addEventListener('mouseleave', () => {
       this.shapeElement.style.backgroundColor = ''
       this.shapeElement.style.border = '2px solid #FF0000'
     })

+ 2 - 1
packages/core/src/ui_utils.js

@@ -1163,7 +1163,8 @@ const ANNOTATION_TYPE = {
   underline: 'underline',
   strikeout: 'strikeout',
   squiggly: 'squiggly',
-  stamp: 'stamp'
+  stamp: 'stamp',
+  redact: 'redact',
 };
 
 const findIndex = (name, items) => {

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

@@ -1924,6 +1924,27 @@ class CPDFWorker {
         spacing
       )
     })
+
+    messageHandler.on('ApplyRedaction', (data) => {
+      const { annotPtr } = data
+      return Module._ApplyRedaction(annotPtr)
+    })
+
+    messageHandler.on('ApplyRedactionPage', (data) => {
+      const { pagePtr } = data
+      return Module._ApplyRedactionPage(pagePtr)
+    })
+
+    messageHandler.on('ErasureRedactionFromRect', (data) => {
+      const { pagePtr, rect } = data
+      return Module._ErasureRedactionFromRect(
+        pagePtr,
+        rect.left,
+        rect.right,
+        rect.bottom,
+        rect.top
+      )
+    })
   }
 }
 
@@ -2027,7 +2048,7 @@ function createAnnotation(doc, pagePtr, annotation) {
   }
 
   annotation.annotPtr = annotPtr
-  const { color, borderWidth, contents, date, opacity, fillTransparency, rect, author } = annotation
+  const { color, borderWidth, contents, date, opacity, fillTransparency, rect, author, fillColor } = annotation
   if (color) {
     setAnnotRGBColor({
       annotPtr,
@@ -2035,6 +2056,13 @@ function createAnnotation(doc, pagePtr, annotation) {
     })
   }
 
+  if (fillColor) {
+    setAnnotFilledRGBColor({
+      annotPtr,
+      fillColor
+    })
+  }
+
   if (contents) {
     setAnnotContent({
       annotPtr,
@@ -3229,6 +3257,15 @@ function setAnnotRGBColor(data) {
   const color = convertColorToCppFormat(rawColor)
 
   const isSetColorSuccess = Module._SetAnnotRGBColor(annotPtr, color.R, color.G, color.B)
+  Module._SetAnnotFilledRGBColor(annotPtr, color.R, color.G, color.B)
+  return !!isSetColorSuccess
+}
+
+function setAnnotFilledRGBColor(data) {
+  const { annotPtr, fillColor: rawColor } = data
+  const color = convertColorToCppFormat(rawColor)
+
+  const isSetColorSuccess = Module._SetAnnotFilledRGBColor(annotPtr, color.R, color.G, color.B)
   return !!isSetColorSuccess
 }
 

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

@@ -6,7 +6,7 @@
     :show-arrow="false"
     to="#outerContainer"
     :raw="true"
-    :z-index="3"
+    :z-index="4"
   >
     <template #trigger>
       <Button class="more" :class="{ active: showDropdown, disabled: !load }">

+ 2 - 1
packages/webview/src/components/HeaderItems/HeaderItems.vue

@@ -166,6 +166,7 @@ let showToolMode = computed(()=>{
 const webviewerMode = computed(() => useViewer.getWebviewerMode)
 const activeTool = computed(() => useDocument.getActiveTool)
 const showDropdown = computed(() => popoverTool.value && popoverTool?.value[0].getMergedShow())
+const showRedactionApplyBar = computed(() => useViewer.getShowRedactionApplyBar)
 
 const changeToolMode = (mode) => {
   if (webviewerMode.value !== 'Standalone' && ['editor', 'document'].includes(mode)) {
@@ -173,7 +174,7 @@ const changeToolMode = (mode) => {
     else useViewer.openElement('docEditorPreventDialog')
     return
   }
-  if (prop.toolMode !== mode && prop.toolMode === 'security' && (activeTool.value === 'redaction' || activeTool.value === 'remove')) {
+  if (prop.toolMode !== mode && prop.toolMode === 'security' && (activeTool.value === 'redaction' || activeTool.value === 'remove') && showRedactionApplyBar.value) {
     useViewer.setRedactionConfirmDialog(useViewer.getShowRedactionApplyBar ? 1 : 0)
     return
   }

+ 1 - 1
packages/webview/src/components/SecurityToolbar/RedactionConfirmDialog.vue

@@ -36,7 +36,7 @@ const closeDialog = () => {
 }
 
 const confirm = () => {
-  dialogType.value === 1 && core.applyRedactions()
+  core.applyRedactions(dialogType.value === 1 ? 'all' : [])
   useDocument.setToolState('')
   useViewer.setActiveToolMode('view')
   useViewer.setShowRedactionApplyBar(false)

+ 1 - 1
packages/webview/src/core/applyRedactions.js

@@ -1,3 +1,3 @@
 import core from '@/core'
 
-export default () => core.getDocumentViewer().applyRedactions()
+export default (data) => core.getDocumentViewer().applyRedactions(data)