Merge pull request #17517 from calixteman/editor_highlight_simplify_ser

[Editor] Slightly simplify the serialization of an highlight annotation
This commit is contained in:
calixteman 2024-01-15 18:50:37 +01:00 committed by GitHub
commit 3110865484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -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 */

View File

@ -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<number>} _bbox - the bounding box of the annotation.
* @param {number} _rotation - the rotation of the annotation.
* @returns {Array<Array<number>>}
*/
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);
}