diff --git a/src/display/editor/highlight.js b/src/display/editor/highlight.js index af21bb5be..2845afee2 100644 --- a/src/display/editor/highlight.js +++ b/src/display/editor/highlight.js @@ -361,14 +361,15 @@ class HighlightEditor extends AnnotationEditor { this.parent?.drawLayer.removeClass(this.#outlineId, "selected"); } - #serializeBoxes() { + #serializeBoxes(rect) { const [pageWidth, pageHeight] = this.pageDimensions; const boxes = this.#boxes; const quadPoints = new Array(boxes.length * 8); + const [tx, ty] = rect; let i = 0; for (const { x, y, width, height } of boxes) { - const sx = x * pageWidth; - const sy = (1 - y - height) * pageHeight; + const sx = tx + x * pageWidth; + const sy = ty + (1 - y - height) * pageHeight; // The specifications say that the rectangle should start from the bottom // left corner and go counter-clockwise. // But when opening the file in Adobe Acrobat it appears that this isn't @@ -382,12 +383,11 @@ class HighlightEditor extends AnnotationEditor { return quadPoints; } - #serializeOutlines() { + #serializeOutlines(rect) { const [pageWidth, pageHeight] = this.pageDimensions; const width = this.width * pageWidth; const height = this.height * pageHeight; - const tx = this.x * pageWidth; - const ty = (1 - this.y - this.height) * pageHeight; + const [tx, ty] = rect; const outlines = []; for (const outline of this.#highlightOutlines.outlines) { const points = new Array(outline.length); @@ -404,18 +404,22 @@ class HighlightEditor extends AnnotationEditor { static deserialize(data, parent, uiManager) { const editor = super.deserialize(data, parent, uiManager); - const { rect, color, quadPoints } = data; + const { + rect: [blX, blY, trX, trY], + color, + quadPoints, + } = data; editor.color = Util.makeHexColor(...color); editor.#opacity = data.opacity; const [pageWidth, pageHeight] = editor.pageDimensions; - editor.width = (rect[2] - rect[0]) / pageWidth; - editor.height = (rect[3] - rect[1]) / pageHeight; + editor.width = (trX - blX) / pageWidth; + editor.height = (trY - blY) / pageHeight; const boxes = (editor.#boxes = []); for (let i = 0; i < quadPoints.length; i += 8) { boxes.push({ - x: quadPoints[4] / pageWidth, - y: 1 - quadPoints[i + 5] / pageHeight, + x: (quadPoints[4] - trX) / pageWidth, + y: (trY - (1 - quadPoints[i + 5])) / pageHeight, width: (quadPoints[i + 2] - quadPoints[i]) / pageWidth, height: (quadPoints[i + 5] - quadPoints[i + 1]) / pageHeight, }); @@ -439,8 +443,8 @@ class HighlightEditor extends AnnotationEditor { annotationType: AnnotationEditorType.HIGHLIGHT, color, opacity: this.#opacity, - quadPoints: this.#serializeBoxes(), - outlines: this.#serializeOutlines(), + quadPoints: this.#serializeBoxes(rect), + outlines: this.#serializeOutlines(rect), pageIndex: this.pageIndex, rect, rotation: 0, diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index ce8b9fa1b..4d3eefaad 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -620,3 +620,4 @@ !issue17215.pdf !bug1863910.pdf !bug1865341.pdf +!bug1872721.pdf diff --git a/test/pdfs/bug1872721.pdf b/test/pdfs/bug1872721.pdf new file mode 100755 index 000000000..bb3ec1023 Binary files /dev/null and b/test/pdfs/bug1872721.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 5b9480fd7..aece61a10 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -8411,5 +8411,52 @@ "rotation": 0 } } + }, + { + "id": "bug1872721-highlight-editor-save-print", + "file": "pdfs/bug1872721.pdf", + "md5": "8318654cda60dc71df9e62a3c78cf193", + "rounds": 1, + "type": "eq", + "save": true, + "print": true, + "annotationStorage": { + "pdfjs_internal_editor_0": { + "annotationType": 9, + "color": [ 83, 255, 188 ], + "opacity": 1, + "quadPoints": [ + 209.0454157057542, + 718.4044878560951, + 270.0049972773625, + 718.4044878560951, + 209.0454157057542, + 731.7427487256604, + 270.0049972773625, + 731.7427487256604 + ], + "outlines": [ + [ + 197.85841250000001, + 709.458959, + 197.85841250000001, + 722.8621772, + 259.003853, + 722.8621772, + 259.003853, + 709.458959 + ] + ], + "pageIndex": 0, + "rect": [ + 197.85841250000001, + 709.458959, + 259.003853, + 722.8621772 + ], + "rotation": 0, + "structTreeParentId": null + } + } } ]