Merge pull request #15806 from Snuffleupagus/AnnotationLayerBuilder-no-annotations

Don't attempt to re-create the `annotationLayer`, for pages without any annotations, on zooming and rotation
This commit is contained in:
Jonas Jenwald 2022-12-11 18:32:24 +01:00 committed by GitHub
commit 8e11cf9b1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 52 deletions

View File

@ -1258,7 +1258,6 @@ class PDFPageProxy {
this.cleanupAfterRender = false; this.cleanupAfterRender = false;
this.pendingCleanup = false; this.pendingCleanup = false;
this._intentStates = new Map(); this._intentStates = new Map();
this._annotationPromises = new Map();
this.destroyed = false; this.destroyed = false;
} }
@ -1328,15 +1327,10 @@ class PDFPageProxy {
getAnnotations({ intent = "display" } = {}) { getAnnotations({ intent = "display" } = {}) {
const intentArgs = this._transport.getRenderingIntent(intent); const intentArgs = this._transport.getRenderingIntent(intent);
let promise = this._annotationPromises.get(intentArgs.cacheKey); return this._transport.getAnnotations(
if (!promise) {
promise = this._transport.getAnnotations(
this._pageIndex, this._pageIndex,
intentArgs.renderingIntent intentArgs.renderingIntent
); );
this._annotationPromises.set(intentArgs.cacheKey, promise);
}
return promise;
} }
/** /**
@ -1655,7 +1649,6 @@ class PDFPageProxy {
bitmap.close(); bitmap.close();
} }
this._bitmaps.clear(); this._bitmaps.clear();
this._annotationPromises.clear();
this._jsActionsPromise = null; this._jsActionsPromise = null;
this.pendingCleanup = false; this.pendingCleanup = false;
return Promise.all(waitOn); return Promise.all(waitOn);
@ -1689,7 +1682,6 @@ class PDFPageProxy {
this._intentStates.clear(); this._intentStates.clear();
this.objs.clear(); this.objs.clear();
this._annotationPromises.clear();
this._jsActionsPromise = null; this._jsActionsPromise = null;
if (resetStats && this._stats) { if (resetStats && this._stats) {
this._stats = new StatTimer(); this._stats = new StatTimer();

View File

@ -47,6 +47,8 @@ import { PresentationModeState } from "./ui_utils.js";
*/ */
class AnnotationLayerBuilder { class AnnotationLayerBuilder {
#numAnnotations = 0;
#onPresentationModeChanged = null; #onPresentationModeChanged = null;
/** /**
@ -77,8 +79,8 @@ class AnnotationLayerBuilder {
this.l10n = l10n; this.l10n = l10n;
this.annotationStorage = annotationStorage; this.annotationStorage = annotationStorage;
this.enableScripting = enableScripting; this.enableScripting = enableScripting;
this._hasJSActionsPromise = hasJSActionsPromise; this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
this._fieldObjectsPromise = fieldObjectsPromise; this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
this._mouseState = mouseState; this._mouseState = mouseState;
this._annotationCanvasMap = annotationCanvasMap; this._annotationCanvasMap = annotationCanvasMap;
this._accessibilityManager = accessibilityManager; this._accessibilityManager = accessibilityManager;
@ -95,18 +97,41 @@ class AnnotationLayerBuilder {
* annotations is complete. * annotations is complete.
*/ */
async render(viewport, intent = "display") { async render(viewport, intent = "display") {
const [annotations, hasJSActions = false, fieldObjects = null] = if (this.div) {
await Promise.all([ if (this._cancelled || this.#numAnnotations === 0) {
return;
}
// If an annotationLayer already exists, refresh its children's
// transformation matrices.
AnnotationLayer.update({
viewport: viewport.clone({ dontFlip: true }),
div: this.div,
annotationCanvasMap: this._annotationCanvasMap,
});
return;
}
const [annotations, hasJSActions, fieldObjects] = await Promise.all([
this.pdfPage.getAnnotations({ intent }), this.pdfPage.getAnnotations({ intent }),
this._hasJSActionsPromise, this._hasJSActionsPromise,
this._fieldObjectsPromise, this._fieldObjectsPromise,
]); ]);
if (this._cancelled) {
if (this._cancelled || annotations.length === 0) {
return; return;
} }
this.#numAnnotations = annotations.length;
const parameters = { // Create an annotation layer div and render the annotations
// if there is at least one annotation.
this.div = document.createElement("div");
this.div.className = "annotationLayer";
this.pageDiv.append(this.div);
if (this.#numAnnotations === 0) {
this.hide();
return;
}
AnnotationLayer.render({
viewport: viewport.clone({ dontFlip: true }), viewport: viewport.clone({ dontFlip: true }),
div: this.div, div: this.div,
annotations, annotations,
@ -122,20 +147,7 @@ class AnnotationLayerBuilder {
mouseState: this._mouseState, mouseState: this._mouseState,
annotationCanvasMap: this._annotationCanvasMap, annotationCanvasMap: this._annotationCanvasMap,
accessibilityManager: this._accessibilityManager, accessibilityManager: this._accessibilityManager,
}; });
if (this.div) {
// If an annotationLayer already exists, refresh its children's
// transformation matrices.
AnnotationLayer.update(parameters);
} else {
// Create an annotation layer div and render the annotations
// if there is at least one annotation.
this.div = parameters.div = document.createElement("div");
this.div.className = "annotationLayer";
this.pageDiv.append(this.div);
AnnotationLayer.render(parameters);
this.l10n.translate(this.div); this.l10n.translate(this.div);
// Ensure that interactive form elements in the annotationLayer are // Ensure that interactive form elements in the annotationLayer are
@ -153,7 +165,6 @@ class AnnotationLayerBuilder {
); );
} }
} }
}
cancel() { cancel() {
this._cancelled = true; this._cancelled = true;