|
@@ -33,13 +33,11 @@ class TextAnnotation extends BaseAnnotation {
|
|
|
this.outerLineContainer = null
|
|
|
this.ratio = window.devicePixelRatio || 1
|
|
|
this.ctx = this.pageViewer.canvas.getContext('2d', { willReadFrequently: true })
|
|
|
- this.baseImageData = this.pageViewer.baseImageData
|
|
|
this.lineWidth = 2 * this.scale * this.ratio
|
|
|
|
|
|
this.onHandleClick = this.handleClick.bind(this)
|
|
|
this.onDelete = this.handleDelete.bind(this)
|
|
|
this.onOpenReply = this.openReply.bind(this)
|
|
|
- this.onUpdateMarkup = this.updateMarkup.bind(this)
|
|
|
|
|
|
this.render()
|
|
|
}
|
|
@@ -59,8 +57,6 @@ class TextAnnotation extends BaseAnnotation {
|
|
|
const quadPoints = annotation.quadPoints
|
|
|
if (!quadPoints) return
|
|
|
|
|
|
- this.eventBus._on('markupUpdate', this.onUpdateMarkup)
|
|
|
-
|
|
|
let positionArray = []
|
|
|
for (let i = 0; (i + 3) < quadPoints.length; i+=4) {
|
|
|
const x1 = parseInt(quadPoints[i].PointX * scale, 10),
|
|
@@ -258,15 +254,6 @@ class TextAnnotation extends BaseAnnotation {
|
|
|
this.handleOutside()
|
|
|
this.markupContainer.remove()
|
|
|
|
|
|
- this.eventBus._off('markupUpdate', this.onUpdateMarkup)
|
|
|
- this.ctx.clearRect(this.rect.left * this.ratio, this.rect.top * this.ratio, this.rect.width * this.ratio, this.rect.height * this.ratio)
|
|
|
- this.ctx.putImageData(this.baseImageData, 0, 0, this.rect.left * this.ratio, this.rect.top * this.ratio, Math.round(this.rect.width * this.ratio + this.lineWidth + 20), Math.round(this.rect.height * this.ratio + this.lineWidth + 20))
|
|
|
- this.eventBus.dispatch('markupUpdate', {
|
|
|
- name: this.annotation.name,
|
|
|
- pageIndex: this.page,
|
|
|
- rect: this.rect
|
|
|
- })
|
|
|
-
|
|
|
this.annotation.isDelete = true
|
|
|
const annotationData = {
|
|
|
type: 'delete',
|
|
@@ -281,6 +268,7 @@ class TextAnnotation extends BaseAnnotation {
|
|
|
annotationData.type = 'empty'
|
|
|
}
|
|
|
this.eventBus.dispatch('annotationChange', annotationData)
|
|
|
+ this.layer.redrawMarkups({ pageIndex: this.page })
|
|
|
}
|
|
|
|
|
|
setCss (ele, cssText) {
|
|
@@ -317,44 +305,13 @@ class TextAnnotation extends BaseAnnotation {
|
|
|
this.eventBus.dispatch('openAnnotationReply', this.annotation)
|
|
|
}
|
|
|
|
|
|
- updateMarkup (data) {
|
|
|
- if (data.pageIndex !== this.page || data.name === this.annotation.name) return
|
|
|
-
|
|
|
- const rect1 = this.rect
|
|
|
- const rect2 = data.rect
|
|
|
-
|
|
|
- if (rect1.left > rect2.left + rect2.width ||
|
|
|
- rect1.left + rect1.width < rect2.left ||
|
|
|
- rect1.top > rect2.top + rect2.height ||
|
|
|
- rect1.top + rect1.height < rect2.top
|
|
|
- ) return
|
|
|
-
|
|
|
- this.ctx.clearRect(this.rect.left * this.ratio, this.rect.top * this.ratio, this.rect.width * this.ratio, this.rect.height * this.ratio)
|
|
|
- this.ctx.putImageData(this.baseImageData, 0, 0, this.rect.left * this.ratio, this.rect.top * this.ratio, Math.round(this.rect.width * this.ratio + this.lineWidth + 20), Math.round(this.rect.height * this.ratio + this.lineWidth + 20))
|
|
|
- this.drawCanvas(this.positionArray)
|
|
|
- }
|
|
|
-
|
|
|
drawCanvas(positionArray) {
|
|
|
const annotation = this.annotation
|
|
|
if (['highlight', 'underline', 'strikeout'].includes(annotation.type)) {
|
|
|
const { R, G, B } = convertColorToRGB(annotation.color)
|
|
|
this.ctx.fillStyle = `rgba(${R}, ${G}, ${B}, ${annotation.opacity || 1})`
|
|
|
-
|
|
|
- const markupContainer = document.createElement('div')
|
|
|
- markupContainer.className = 'markup'
|
|
|
-
|
|
|
for (let i = 0; i < positionArray.length; i++) {
|
|
|
const position = positionArray[i]
|
|
|
- const container = document.createElement('div')
|
|
|
- this.setCss(container, {
|
|
|
- position: 'absolute',
|
|
|
- top: position.top + 'px',
|
|
|
- left: position.left + 'px',
|
|
|
- width: position.width + 'px',
|
|
|
- height: position.height + 'px'
|
|
|
- })
|
|
|
- markupContainer.append(container)
|
|
|
-
|
|
|
if (annotation.type === 'highlight') {
|
|
|
this.ctx.fillRect(position.left * this.ratio, position.top * this.ratio, position.width * this.ratio, position.height * this.ratio)
|
|
|
} else if (annotation.type === 'underline') {
|
|
@@ -381,6 +338,33 @@ class TextAnnotation extends BaseAnnotation {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 重绘交集区域
|
|
|
+ drawIntersectionalCanvas(rect) {
|
|
|
+ const intersectionArray = this.positionArray
|
|
|
+ .map(posRect => this.getIntersection(posRect, rect))
|
|
|
+ .filter(intersection => intersection)
|
|
|
+ this.drawCanvas(intersectionArray)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取两个rect交集区域
|
|
|
+ getIntersection(rectA, rectB) {
|
|
|
+ const left = Math.max(rectA.left, rectB.left)
|
|
|
+ const right = Math.min(rectA.left + rectA.width, rectB.right)
|
|
|
+ const top = Math.max(rectA.top, rectB.top)
|
|
|
+ const bottom = Math.min(rectA.top + rectA.height, rectB.bottom)
|
|
|
+
|
|
|
+ if (right > left && bottom > top) {
|
|
|
+ return {
|
|
|
+ left,
|
|
|
+ top,
|
|
|
+ width: right - left,
|
|
|
+ height: bottom - top
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export default TextAnnotation
|