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:
commit
8e11cf9b1c
@ -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) {
|
this._pageIndex,
|
||||||
promise = this._transport.getAnnotations(
|
intentArgs.renderingIntent
|
||||||
this._pageIndex,
|
);
|
||||||
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();
|
||||||
|
@ -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) {
|
||||||
this.pdfPage.getAnnotations({ intent }),
|
return;
|
||||||
this._hasJSActionsPromise,
|
}
|
||||||
this._fieldObjectsPromise,
|
// If an annotationLayer already exists, refresh its children's
|
||||||
]);
|
// transformation matrices.
|
||||||
|
AnnotationLayer.update({
|
||||||
if (this._cancelled || annotations.length === 0) {
|
viewport: viewport.clone({ dontFlip: true }),
|
||||||
|
div: this.div,
|
||||||
|
annotationCanvasMap: this._annotationCanvasMap,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parameters = {
|
const [annotations, hasJSActions, fieldObjects] = await Promise.all([
|
||||||
|
this.pdfPage.getAnnotations({ intent }),
|
||||||
|
this._hasJSActionsPromise,
|
||||||
|
this._fieldObjectsPromise,
|
||||||
|
]);
|
||||||
|
if (this._cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#numAnnotations = annotations.length;
|
||||||
|
|
||||||
|
// 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,36 +147,22 @@ class AnnotationLayerBuilder {
|
|||||||
mouseState: this._mouseState,
|
mouseState: this._mouseState,
|
||||||
annotationCanvasMap: this._annotationCanvasMap,
|
annotationCanvasMap: this._annotationCanvasMap,
|
||||||
accessibilityManager: this._accessibilityManager,
|
accessibilityManager: this._accessibilityManager,
|
||||||
};
|
});
|
||||||
|
this.l10n.translate(this.div);
|
||||||
|
|
||||||
if (this.div) {
|
// Ensure that interactive form elements in the annotationLayer are
|
||||||
// If an annotationLayer already exists, refresh its children's
|
// disabled while PresentationMode is active (see issue 12232).
|
||||||
// transformation matrices.
|
if (this.linkService.isInPresentationMode) {
|
||||||
AnnotationLayer.update(parameters);
|
this.#updatePresentationModeState(PresentationModeState.FULLSCREEN);
|
||||||
} else {
|
}
|
||||||
// Create an annotation layer div and render the annotations
|
if (!this.#onPresentationModeChanged) {
|
||||||
// if there is at least one annotation.
|
this.#onPresentationModeChanged = evt => {
|
||||||
this.div = parameters.div = document.createElement("div");
|
this.#updatePresentationModeState(evt.state);
|
||||||
this.div.className = "annotationLayer";
|
};
|
||||||
this.pageDiv.append(this.div);
|
this._eventBus?._on(
|
||||||
|
"presentationmodechanged",
|
||||||
AnnotationLayer.render(parameters);
|
this.#onPresentationModeChanged
|
||||||
this.l10n.translate(this.div);
|
);
|
||||||
|
|
||||||
// Ensure that interactive form elements in the annotationLayer are
|
|
||||||
// disabled while PresentationMode is active (see issue 12232).
|
|
||||||
if (this.linkService.isInPresentationMode) {
|
|
||||||
this.#updatePresentationModeState(PresentationModeState.FULLSCREEN);
|
|
||||||
}
|
|
||||||
if (!this.#onPresentationModeChanged) {
|
|
||||||
this.#onPresentationModeChanged = evt => {
|
|
||||||
this.#updatePresentationModeState(evt.state);
|
|
||||||
};
|
|
||||||
this._eventBus?._on(
|
|
||||||
"presentationmodechanged",
|
|
||||||
this.#onPresentationModeChanged
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user