From 1a397681fe92980c9189f3e522ffc89f667d73bf Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 13 Dec 2022 14:33:58 +0100 Subject: [PATCH] The annotation layer dimensions must be set before adding some elements (follow-up of #15770) In order to move the annotations in the DOM to have something which corresponds to the visual order, we need to have their dimensions/positions which means that the parent must have some dimensions. --- src/display/annotation_layer.js | 4 +-- test/integration/accessibility_spec.js | 33 +++++++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/fields_order.pdf | Bin 0 -> 7661 bytes 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100755 test/pdfs/fields_order.pdf diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 35248dced..1eb5f9c5d 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -2585,6 +2585,7 @@ class AnnotationLayer { */ static render(parameters) { const { annotations, div, viewport, accessibilityManager } = parameters; + setLayerDimensions(div, viewport); let zIndex = 0; @@ -2652,7 +2653,6 @@ class AnnotationLayer { } this.#setAnnotationCanvasMap(div, parameters.annotationCanvasMap); - setLayerDimensions(div, viewport); } /** @@ -2664,9 +2664,9 @@ class AnnotationLayer { */ static update(parameters) { const { annotationCanvasMap, div, viewport } = parameters; + setLayerDimensions(div, { rotation: viewport.rotation }); this.#setAnnotationCanvasMap(div, annotationCanvasMap); - setLayerDimensions(div, { rotation: viewport.rotation }); div.hidden = false; } diff --git a/test/integration/accessibility_spec.js b/test/integration/accessibility_spec.js index 8ca890aae..0d25586b1 100644 --- a/test/integration/accessibility_spec.js +++ b/test/integration/accessibility_spec.js @@ -106,4 +106,37 @@ describe("accessibility", () => { ); }); }); + + describe("Annotations order", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("fields_order.pdf", ".annotationLayer"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the text fields are in the visual order", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + const ids = await page.evaluate(() => { + const elements = document.querySelectorAll( + ".annotationLayer .textWidgetAnnotation" + ); + const results = []; + for (const element of elements) { + results.push(element.getAttribute("data-annotation-id")); + } + return results; + }); + + expect(ids) + .withContext(`In ${browserName}`) + .toEqual(["32R", "30R", "31R", "34R", "29R", "33R"]); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 50738a2c2..92a9c74a4 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -560,3 +560,4 @@ !issue15759.pdf !issue15753.pdf !issue15789.pdf +!fields_order.pdf diff --git a/test/pdfs/fields_order.pdf b/test/pdfs/fields_order.pdf new file mode 100755 index 0000000000000000000000000000000000000000..c3115c788c15738a277d6b6edfb44bb6891e6ea5 GIT binary patch literal 7661 zcmeHM2~-nT7iL#dsHklfwK{?}qQBW}!R?f#|H6-eNH<)#xeGsF_WvAQYBDe1bsXL z5(py@0-gvSr$Brz4~1i)bO`4OK%+1tEXQ(9U8Q~Z$X{M|ya9nh{m@knCC44>>8Hq;_2#!T^ z34|vRqBs&Q;YUYu!^BY$XcQ5N#6(Gi1XqBAFM%Ss1drfG3owB|7?uIY=~Yx=ItUy? znHx0?p*V0*4ofM0wmApl@fmMsF@a*RoTkkX$^;;XCjn?6E&-<$87O#)oKnMS=_rIj zD1g9ZHd3U{o0Zd%m8J4gD6$j{?t{Fl!{_I577LvHhfb_CjIQTFKku!Ww`2wB8SCll z@7y_|YvXz+XAh^D3!b~<%>p3Wtk~c*nMtF$&`7DhS%^0)AV88B? z5Q++WLlOukP zZPHt_G`d2<{e|X-9iy{V7}o%Oh-5f#QX>p16RHfTr*%9 z;34_gRzO@}sn-!XWuo(qN(xXJa8^#60b3!&$`8h4JLecrY|cg6TSs|}2biU61`Z}R zX7pL9hzVdBX*OyAU2VQH(sutdU^^cGZE58s%A5{^K@K&_nhIn}IJjLbn!0JF?onychGs&#$n__Z0wwK8gTv4C!`wb(`B$Tb0 z6E$`7rxKr!+uiG0OLQmY!Rd9W-TMk!H(wszj~q~bn!jcYt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