Skip to content

Commit 2200f05

Browse files
committed
Fix #serializeBoxes bug inconsistent with deserialize function for highlight editor.
Add test for quadPoints order while serializing.
1 parent 9bf9bbd commit 2200f05

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/display/editor/highlight.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -693,15 +693,14 @@ class HighlightEditor extends AnnotationEditor {
693693
let i = 0;
694694
for (const { x, y, width, height } of boxes) {
695695
const sx = x * pageWidth + pageX;
696-
const sy = (1 - y - height) * pageHeight + pageY;
697-
// The specifications say that the rectangle should start from the bottom
698-
// left corner and go counter-clockwise.
699-
// But when opening the file in Adobe Acrobat it appears that this isn't
700-
// correct hence the 4th and 6th numbers are just swapped.
696+
const sy = (1 - y) * pageHeight + pageY;
697+
// Serializes the rectangle in the Adobe Acrobat format.
698+
// The rectangle's coordinates (b = bottom, t = top, L = left, R = right)
699+
// are ordered as follows: tL, tR, bL, bR (bL origin).
701700
quadPoints[i] = quadPoints[i + 4] = sx;
702701
quadPoints[i + 1] = quadPoints[i + 3] = sy;
703702
quadPoints[i + 2] = quadPoints[i + 6] = sx + width * pageWidth;
704-
quadPoints[i + 5] = quadPoints[i + 7] = sy + height * pageHeight;
703+
quadPoints[i + 5] = quadPoints[i + 7] = sy - height * pageHeight;
705704
i += 8;
706705
}
707706
return quadPoints;

test/integration/highlight_editor_spec.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,8 @@ describe("Highlight Editor", () => {
12721272
await page.waitForSelector(getEditorSelector(0));
12731273
await waitForSerialized(page, 1);
12741274
const quadPoints = await getFirstSerialized(page, e => e.quadPoints);
1275-
const expected = [263, 674, 346, 674, 263, 696, 346, 696];
1275+
// Expected quadPoints tL, tR, bL, bR with bL coordinate.
1276+
const expected = [263, 696, 346, 696, 263, 674, 346, 674];
12761277
expect(quadPoints.every((x, i) => Math.abs(x - expected[i]) <= 5))
12771278
.withContext(`In ${browserName}`)
12781279
.toBeTrue();
@@ -1307,7 +1308,8 @@ describe("Highlight Editor", () => {
13071308
await page.waitForSelector(getEditorSelector(0));
13081309
await waitForSerialized(page, 1);
13091310
const quadPoints = await getFirstSerialized(page, e => e.quadPoints);
1310-
const expected = [148, 624, 176, 624, 148, 637, 176, 637];
1311+
// Expected quadPoints tL, tR, bL, bR with bL coordinate.
1312+
const expected = [148, 637, 176, 637, 148, 624, 176, 624];
13111313
expect(quadPoints.every((x, i) => Math.abs(x - expected[i]) <= 5))
13121314
.withContext(`In ${browserName} (got ${quadPoints})`)
13131315
.toBeTrue();

0 commit comments

Comments
 (0)