From 576aaf7cc1e56c17da4a350ddb277d1c96e44544 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 1 Jul 2024 23:59:37 +0200 Subject: [PATCH] [Editor] Take into account the page translation when computing the quadpoints when saving an highlight It fixes #18360. --- src/display/editor/highlight.js | 5 +-- test/integration/highlight_editor_spec.mjs | 35 +++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/issue18360.pdf | Bin 0 -> 10075 bytes 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100755 test/pdfs/issue18360.pdf diff --git a/src/display/editor/highlight.js b/src/display/editor/highlight.js index 9887b0778320f..36ca75cc51463 100644 --- a/src/display/editor/highlight.js +++ b/src/display/editor/highlight.js @@ -671,12 +671,13 @@ class HighlightEditor extends AnnotationEditor { return null; } const [pageWidth, pageHeight] = this.pageDimensions; + const [pageX, pageY] = this.pageTranslation; const boxes = this.#boxes; const quadPoints = new Float32Array(boxes.length * 8); let i = 0; for (const { x, y, width, height } of boxes) { - const sx = x * pageWidth; - const sy = (1 - y - height) * pageHeight; + 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 diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index a3c6c6d084519..6c47bbe7e0af1 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -1302,6 +1302,41 @@ describe("Highlight Editor", () => { }); }); + describe("Quadpoints must be correct when they're in a translated page", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue18360.pdf", ".annotationEditorLayer"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the quadpoints for an highlight are almost correct", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await switchToHighlight(page); + + const rect = await getSpanRectFromText(page, 1, "Hello World"); + await page.mouse.click( + rect.x + rect.width / 4, + rect.y + rect.height / 2, + { count: 2, delay: 100 } + ); + + 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]; + expect(quadPoints.every((x, i) => Math.abs(x - expected[i]) <= 5)) + .withContext(`In ${browserName} (got ${quadPoints})`) + .toBeTrue(); + }) + ); + }); + }); + describe("Editor must be unselected when the color picker is Escaped", () => { let pages; diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index b92b8e3915b02..98c3f4ace1aa7 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -652,3 +652,4 @@ !bug1539074.pdf !bug1539074.1.pdf !issue18305.pdf +!issue18360.pdf diff --git a/test/pdfs/issue18360.pdf b/test/pdfs/issue18360.pdf new file mode 100755 index 0000000000000000000000000000000000000000..43a96575ecf4f9078fecb061c8e1fe00da23349a GIT binary patch literal 10075 zcmeHNc{G&m->0%9dy4cM8$d=>&xgf`D~E5CA|S!1^Ev46Fu1U?3Q<9{ss72!ldF z!5Sb-5F7~sK@botB_$4uJ9$G0Xp@Vs1M^D0@lP^DnO7hH2`xMr;3N8Fi<#D6@!PV0}zNB zOcf8qLlH^}7!+C!p^n6005lW{ha=I4(dsBX6o*Em00mUPDaV2 zD&14MfdsG)#odACNOyI^8lMe6VPFE4N~4?fZQO_s4G4+^8~b}uz~%&sJ=n|=0)m1z z5b&aTQiyIGY>vZrc4Tf_TRU4eMqYL$l~c!+&pc%n^@FO~C8(TQ5{vhHn0PWOfr!+I zImvVBW9PkjE|pM52HrZ>ISw{Dia+H1z|)IH^rZQDQtUa{01h@WF*SX44z@oq=3s*& zegV4~Vjwj752uhQ`b^U2%?JcT|H)cgTU(N?Z6cXrOF|&C@gvqc8TNe~Y#Mg125pbH zn;+FCb03dCS#y3AWn6ks!FWKiNRPSSLtL-$PU=c^_!UtQ*e@4xRCgN1o#q9Cz`t?eJgFXs zsr0FY0&)O-+F)`R3z8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