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.
This commit is contained in:
Jonas Jenwald 2022-07-04 09:07:10 +02:00
parent ca8b112e8c
commit 552ee9decd
3 changed files with 9 additions and 10 deletions

View File

@ -2457,12 +2457,16 @@ class AnnotationLayer {
* @memberof AnnotationLayer * @memberof AnnotationLayer
*/ */
static render(parameters) { static render(parameters) {
const { annotations, div, viewport } = parameters;
this.#setDimensions(div, viewport);
const sortedAnnotations = [], const sortedAnnotations = [],
popupAnnotations = []; popupAnnotations = [];
// Ensure that Popup annotations are handled last, since they're dependant // Ensure that Popup annotations are handled last, since they're dependant
// upon the parent annotation having already been rendered (please refer to // upon the parent annotation having already been rendered (please refer to
// the `PopupAnnotationElement.render` method); fixes issue 11362. // the `PopupAnnotationElement.render` method); fixes issue 11362.
for (const data of parameters.annotations) { for (const data of annotations) {
if (!data) { if (!data) {
continue; continue;
} }
@ -2480,14 +2484,12 @@ class AnnotationLayer {
sortedAnnotations.push(...popupAnnotations); sortedAnnotations.push(...popupAnnotations);
} }
const div = parameters.div;
for (const data of sortedAnnotations) { for (const data of sortedAnnotations) {
const element = AnnotationElementFactory.create({ const element = AnnotationElementFactory.create({
data, data,
layer: div, layer: div,
page: parameters.page, page: parameters.page,
viewport: parameters.viewport, viewport,
linkService: parameters.linkService, linkService: parameters.linkService,
downloadManager: parameters.downloadManager, downloadManager: parameters.downloadManager,
imageResourcesPath: parameters.imageResourcesPath || "", imageResourcesPath: parameters.imageResourcesPath || "",
@ -2532,8 +2534,9 @@ class AnnotationLayer {
* @memberof AnnotationLayer * @memberof AnnotationLayer
*/ */
static update(parameters) { static update(parameters) {
const { annotationCanvasMap, div } = parameters; const { annotationCanvasMap, div, viewport } = parameters;
this.#setDimensions(div, viewport);
this.#setAnnotationCanvasMap(div, annotationCanvasMap); this.#setAnnotationCanvasMap(div, annotationCanvasMap);
div.hidden = false; div.hidden = false;
} }
@ -2542,7 +2545,7 @@ class AnnotationLayer {
* @param {HTMLDivElement} div * @param {HTMLDivElement} div
* @param {PageViewport} viewport * @param {PageViewport} viewport
*/ */
static setDimensions(div, { width, height, rotation }) { static #setDimensions(div, { width, height, rotation }) {
const { style } = div; const { style } = div;
const flipOrientation = rotation % 180 !== 0, const flipOrientation = rotation % 180 !== 0,

View File

@ -231,7 +231,6 @@ class Rasterize {
renderForms, renderForms,
annotationCanvasMap: annotationImageMap, annotationCanvasMap: annotationImageMap,
}; };
AnnotationLayer.setDimensions(div, annotationViewport);
AnnotationLayer.render(parameters); AnnotationLayer.render(parameters);
// Inline SVG images from text annotations. // Inline SVG images from text annotations.

View File

@ -117,14 +117,11 @@ class AnnotationLayerBuilder {
if (this.div) { if (this.div) {
// If an annotationLayer already exists, refresh its children's // If an annotationLayer already exists, refresh its children's
// transformation matrices. // transformation matrices.
AnnotationLayer.setDimensions(this.div, viewport);
AnnotationLayer.update(parameters); AnnotationLayer.update(parameters);
} else { } else {
// Create an annotation layer div and render the annotations // Create an annotation layer div and render the annotations
// if there is at least one annotation. // if there is at least one annotation.
this.div = document.createElement("div"); this.div = document.createElement("div");
AnnotationLayer.setDimensions(this.div, viewport);
this.div.className = "annotationLayer"; this.div.className = "annotationLayer";
this.pageDiv.append(this.div); this.pageDiv.append(this.div);
parameters.div = this.div; parameters.div = this.div;