Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #serializeBoxes function not output correct quadPoints values for deserialize (issue19056) #19066

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/display/editor/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,14 @@ class HighlightEditor extends AnnotationEditor {
let i = 0;
for (const { x, y, width, height } of boxes) {
const sx = x * pageWidth + pageX;
const sy = (1 - y - height) * pageHeight + pageY;
// 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
// correct hence the 4th and 6th numbers are just swapped.
const sy = (1 - y) * pageHeight + pageY;
// Serializes the rectangle in the Adobe Acrobat format.
// The rectangle's coordinates (b = bottom, t = top, L = left, R = right)
// are ordered as follows: tL, tR, bL, bR (bL origin).
quadPoints[i] = quadPoints[i + 4] = sx;
quadPoints[i + 1] = quadPoints[i + 3] = sy;
quadPoints[i + 2] = quadPoints[i + 6] = sx + width * pageWidth;
quadPoints[i + 5] = quadPoints[i + 7] = sy + height * pageHeight;
quadPoints[i + 5] = quadPoints[i + 7] = sy - height * pageHeight;
calixteman marked this conversation as resolved.
Show resolved Hide resolved
i += 8;
}
return quadPoints;
Expand Down
6 changes: 4 additions & 2 deletions test/integration/highlight_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,8 @@ describe("Highlight Editor", () => {
await page.waitForSelector(getEditorSelector(0));
await waitForSerialized(page, 1);
const quadPoints = await getFirstSerialized(page, e => e.quadPoints);
const expected = [263, 674, 346, 674, 263, 696, 346, 696];
// Expected quadPoints tL, tR, bL, bR with bL coordinate.
const expected = [263, 696, 346, 696, 263, 674, 346, 674];
expect(quadPoints.every((x, i) => Math.abs(x - expected[i]) <= 5))
.withContext(`In ${browserName}`)
.toBeTrue();
Expand Down Expand Up @@ -1307,7 +1308,8 @@ describe("Highlight Editor", () => {
await page.waitForSelector(getEditorSelector(0));
await waitForSerialized(page, 1);
const quadPoints = await getFirstSerialized(page, e => e.quadPoints);
const expected = [148, 624, 176, 624, 148, 637, 176, 637];
// Expected quadPoints tL, tR, bL, bR with bL coordinate.
const expected = [148, 637, 176, 637, 148, 624, 176, 624];
expect(quadPoints.every((x, i) => Math.abs(x - expected[i]) <= 5))
.withContext(`In ${browserName} (got ${quadPoints})`)
.toBeTrue();
Expand Down