Forráskód Böngészése

fix: 优化form获取外观时偶尔和canvas宽高有误差的情况

wzl 3 hónapja
szülő
commit
4b3b457672

+ 2 - 2
packages/core/src/annotation/stamp.js

@@ -128,8 +128,8 @@ export default class Stamp extends Base {
 
       const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
         annotPtr: this.annotation.annotPtr,
-        rect: this.annotation.rect,
-        scale: this.scale * this.ratio
+        width: imgRect.width,
+        height: imgRect.height
       })
 
       const canvas = document.createElement('canvas')

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

@@ -780,7 +780,6 @@ export default class CheckBox extends Base {
       right: end.x,
       bottom: end.y
     }
-    this.rect = rect
 
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
@@ -1008,8 +1007,8 @@ export default class CheckBox extends Base {
 
     const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
       annotPtr: this.annotation.annotPtr,
-      rect: this.rect || this.annotation.rect,
-      scale: this.scale * this.layer.ratio
+      width: imgRect.width,
+      height: imgRect.height
     })
 
     const canvas = document.createElement('canvas')
@@ -1037,6 +1036,7 @@ export default class CheckBox extends Base {
       imgEle.style.width = '100%'
       imgEle.style.height = '100%'
       imgEle.style.pointerEvents = 'none'
+      imgEle.style.position = 'absolute'
 
       imgEle.src = imgSrc
       this.imgEle = imgEle

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

@@ -756,7 +756,6 @@ export default class ComboBox extends Base {
       right: end.x,
       bottom: end.y
     }
-    this.rect = rect
 
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
@@ -1101,8 +1100,8 @@ export default class ComboBox extends Base {
 
     const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
       annotPtr: this.annotation.annotPtr,
-      rect: this.rect || this.annotation.rect,
-      scale: this.scale * this.layer.ratio
+      width: imgRect.width,
+      height: imgRect.height
     })
 
     const canvas = document.createElement('canvas')

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

@@ -732,7 +732,6 @@ export default class ListBox extends Base {
       right: end.x,
       bottom: end.y
     }
-    this.rect = rect
 
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
@@ -1089,8 +1088,8 @@ export default class ListBox extends Base {
 
     const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
       annotPtr: this.annotation.annotPtr,
-      rect: this.rect || this.annotation.rect,
-      scale: this.scale * this.layer.ratio
+      width: imgRect.width,
+      height: imgRect.height
     })
 
     const canvas = document.createElement('canvas')

+ 2 - 3
packages/core/src/form/push_button.js

@@ -709,7 +709,6 @@ export default class PushButton extends Base {
       right: end.x,
       bottom: end.y
     }
-    this.rect = rect
 
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
@@ -1030,8 +1029,8 @@ export default class PushButton extends Base {
 
     const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
       annotPtr: this.annotation.annotPtr,
-      rect: this.rect || this.annotation.rect,
-      scale: this.scale * this.layer.ratio
+      width: imgRect.width,
+      height: imgRect.height
     })
 
     const canvas = document.createElement('canvas')

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

@@ -783,7 +783,6 @@ export default class RadioButton extends Base {
       right: end.x,
       bottom: end.y
     }
-    this.rect = rect
 
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
@@ -1025,8 +1024,8 @@ export default class RadioButton extends Base {
 
     const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
       annotPtr: this.annotation.annotPtr,
-      rect: this.rect || this.annotation.rect,
-      scale: this.scale * this.layer.ratio
+      width: imgRect.width,
+      height: imgRect.height
     })
 
     const canvas = document.createElement('canvas')

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

@@ -781,8 +781,8 @@ export default class SignatureFields extends Base {
 
     const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
       annotPtr: this.annotation.annotPtr,
-      rect: this.annotation.rect,
-      scale: this.scale * this.ratio
+      width: imgRect.width,
+      height: imgRect.height
     })
 
     const canvas = document.createElement('canvas')

+ 2 - 3
packages/core/src/form/text_field.js

@@ -714,7 +714,6 @@ export default class TextField extends Base {
       right: end.x,
       bottom: end.y
     }
-    this.rect = rect
 
     this.eventBus.dispatch('annotationChange', {
       type: 'modify',
@@ -1121,8 +1120,8 @@ export default class TextField extends Base {
 
     const imageArray = await this.messageHandler.sendWithPromise('GetRenderAnnot', {
       annotPtr: this.annotation.annotPtr,
-      rect: this.rect || this.annotation.rect,
-      scale: this.scale * this.layer.ratio
+      width: imgRect.width,
+      height: imgRect.height
     })
 
     const canvas = document.createElement('canvas')

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

@@ -248,9 +248,7 @@ class CPDFWorker {
     })
 
     messageHandler.on('GetRenderAnnot', (data) => {
-      const { annotPtr, rect, scale } = data
-      const width = parseInt(rect.right * scale - rect.left * scale + 1)
-      const height = parseInt(rect.bottom * scale - rect.top * scale + 1)
+      const { annotPtr, width, height } = data
       let pixelNum = width * height
 
       let imageBytes = pixelNum * 4