From 552ee9decd6be48b6d3e5452a1c2ecee58314aab Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 4 Jul 2022 09:07:10 +0200 Subject: [PATCH] Call `AnnotationLayer.setDimensions` as part of the `render`/`update`-methods (PR 15036 follow-up) Rather than forcing the user to *manually* call `setDimensions`, which is also breaking any existing third-party code, it seems that we can simply let the `AnnotationLayer.{render, update}`-methods handle that internally. As far as I can tell, based on testing manually in the viewer *and* running the browser-tests, everything still appears to work correctly with this patch. --- src/display/annotation_layer.js | 15 +++++++++------ test/driver.js | 1 - web/annotation_layer_builder.js | 3 --- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 064ee3b3e..3b589303b 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -2457,12 +2457,16 @@ class AnnotationLayer { * @memberof AnnotationLayer */ static render(parameters) { + const { annotations, div, viewport } = parameters; + + this.#setDimensions(div, viewport); + const sortedAnnotations = [], popupAnnotations = []; // Ensure that Popup annotations are handled last, since they're dependant // upon the parent annotation having already been rendered (please refer to // the `PopupAnnotationElement.render` method); fixes issue 11362. - for (const data of parameters.annotations) { + for (const data of annotations) { if (!data) { continue; } @@ -2480,14 +2484,12 @@ class AnnotationLayer { sortedAnnotations.push(...popupAnnotations); } - const div = parameters.div; - for (const data of sortedAnnotations) { const element = AnnotationElementFactory.create({ data, layer: div, page: parameters.page, - viewport: parameters.viewport, + viewport, linkService: parameters.linkService, downloadManager: parameters.downloadManager, imageResourcesPath: parameters.imageResourcesPath || "", @@ -2532,8 +2534,9 @@ class AnnotationLayer { * @memberof AnnotationLayer */ static update(parameters) { - const { annotationCanvasMap, div } = parameters; + const { annotationCanvasMap, div, viewport } = parameters; + this.#setDimensions(div, viewport); this.#setAnnotationCanvasMap(div, annotationCanvasMap); div.hidden = false; } @@ -2542,7 +2545,7 @@ class AnnotationLayer { * @param {HTMLDivElement} div * @param {PageViewport} viewport */ - static setDimensions(div, { width, height, rotation }) { + static #setDimensions(div, { width, height, rotation }) { const { style } = div; const flipOrientation = rotation % 180 !== 0, diff --git a/test/driver.js b/test/driver.js index 28578510c..3543ba91a 100644 --- a/test/driver.js +++ b/test/driver.js @@ -231,7 +231,6 @@ class Rasterize { renderForms, annotationCanvasMap: annotationImageMap, }; - AnnotationLayer.setDimensions(div, annotationViewport); AnnotationLayer.render(parameters); // Inline SVG images from text annotations. diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 97a05cff4..aa1d9ac4b 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -117,14 +117,11 @@ class AnnotationLayerBuilder { if (this.div) { // If an annotationLayer already exists, refresh its children's // transformation matrices. - AnnotationLayer.setDimensions(this.div, viewport); AnnotationLayer.update(parameters); } else { // Create an annotation layer div and render the annotations // if there is at least one annotation. this.div = document.createElement("div"); - AnnotationLayer.setDimensions(this.div, viewport); - this.div.className = "annotationLayer"; this.pageDiv.append(this.div); parameters.div = this.div;