From ee72b32dc28d69ae49a7bd784f4400e9ced3e1bc Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 15 Jan 2024 18:10:28 +0100 Subject: [PATCH] [Editor] Slightly simplify the serialization of an highlight annotation We were computing width and height of the annotation before serializing which is useless because the rect already contains this information. --- src/display/editor/highlight.js | 8 +------- src/display/editor/outliner.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/display/editor/highlight.js b/src/display/editor/highlight.js index 4bc00f7d0..70db98849 100644 --- a/src/display/editor/highlight.js +++ b/src/display/editor/highlight.js @@ -384,13 +384,7 @@ class HighlightEditor extends AnnotationEditor { } #serializeOutlines(rect) { - const [pageWidth, pageHeight] = this.pageDimensions; - return this.#highlightOutlines.serialize( - rect[0], - rect[1], - this.width * pageWidth, - this.height * pageHeight - ); + return this.#highlightOutlines.serialize(rect, 0); } /** @inheritdoc */ diff --git a/src/display/editor/outliner.js b/src/display/editor/outliner.js index 9d0425e9e..a62009098 100644 --- a/src/display/editor/outliner.js +++ b/src/display/editor/outliner.js @@ -267,6 +267,10 @@ class Outline { get box() { throw new Error("Abstract getter `box` must be implemented."); } + + serialize(_bbox, _rotation) { + throw new Error("Abstract method `serialize` must be implemented."); + } } class HighlightOutline extends Outline { @@ -301,13 +305,21 @@ class HighlightOutline extends Outline { return buffer.join(" "); } - serialize(x, y, width, height) { + /** + * Serialize the outlines into the PDF page coordinate system. + * @param {Array} _bbox - the bounding box of the annotation. + * @param {number} _rotation - the rotation of the annotation. + * @returns {Array>} + */ + serialize([blX, blY, trX, trY], _rotation) { const outlines = []; + const width = trX - blX; + const height = trY - blY; for (const outline of this.#outlines) { const points = new Array(outline.length); for (let i = 0; i < outline.length; i += 2) { - points[i] = x + outline[i] * width; - points[i + 1] = y + (1 - outline[i + 1]) * height; + points[i] = blX + outline[i] * width; + points[i + 1] = trY - outline[i + 1] * height; } outlines.push(points); }