Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle possibly undefined parameters *once* per AnnotationLayer.render invocation #15824

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 62 additions & 58 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2562,13 +2562,16 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
* @property {PDFPageProxy} page
* @property {IPDFLinkService} linkService
* @property {IDownloadManager} downloadManager
* @property {AnnotationStorage} [annotationStorage]
* @property {string} [imageResourcesPath] - Path for image resources, mainly
* for annotation icons. Include trailing slash.
* @property {boolean} renderForms
* @property {boolean} [enableScripting] - Enable embedded script execution.
* @property {boolean} [hasJSActions] - Some fields have JS actions.
* The default value is `false`.
* @property {Object<string, Array<Object>> | null} [fieldObjects]
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
* @property {TextAccessibilityManager} [accessibilityManager]
*/

class AnnotationLayer {
Expand All @@ -2588,14 +2591,28 @@ class AnnotationLayer {
/**
* Render a new annotation layer with all annotation elements.
*
* @public
* @param {AnnotationLayerParameters} parameters
* @param {AnnotationLayerParameters} params
* @memberof AnnotationLayer
*/
static render(parameters) {
const { annotations, div, viewport, accessibilityManager } = parameters;
static render(params) {
const { annotations, div, viewport, accessibilityManager } = params;
setLayerDimensions(div, viewport);

const elementParams = {
data: null,
layer: div,
page: params.page,
viewport,
linkService: params.linkService,
downloadManager: params.downloadManager,
imageResourcesPath: params.imageResourcesPath || "",
renderForms: params.renderForms !== false,
svgFactory: new DOMSVGFactory(),
annotationStorage: params.annotationStorage || new AnnotationStorage(),
enableScripting: params.enableScripting === true,
hasJSActions: params.hasJSActions,
fieldObjects: params.fieldObjects,
};
let zIndex = 0;

for (const data of annotations) {
Expand All @@ -2605,73 +2622,60 @@ class AnnotationLayer {
continue; // Ignore empty annotations.
}
}
const element = AnnotationElementFactory.create({
data,
layer: div,
page: parameters.page,
viewport,
linkService: parameters.linkService,
downloadManager: parameters.downloadManager,
imageResourcesPath: parameters.imageResourcesPath || "",
renderForms: parameters.renderForms !== false,
svgFactory: new DOMSVGFactory(),
annotationStorage:
parameters.annotationStorage || new AnnotationStorage(),
enableScripting: parameters.enableScripting,
hasJSActions: parameters.hasJSActions,
fieldObjects: parameters.fieldObjects,
});
if (element.isRenderable) {
const rendered = element.render();
if (data.hidden) {
rendered.style.visibility = "hidden";
elementParams.data = data;
const element = AnnotationElementFactory.create(elementParams);

if (!element.isRenderable) {
continue;
}
const rendered = element.render();
if (data.hidden) {
rendered.style.visibility = "hidden";
}
if (Array.isArray(rendered)) {
for (const renderedElement of rendered) {
renderedElement.style.zIndex = zIndex++;
AnnotationLayer.#appendElement(
renderedElement,
data.id,
div,
accessibilityManager
);
}
if (Array.isArray(rendered)) {
for (const renderedElement of rendered) {
renderedElement.style.zIndex = zIndex++;
AnnotationLayer.#appendElement(
renderedElement,
data.id,
div,
accessibilityManager
);
}
} else {
// The accessibility manager will move the annotation in the DOM in
// order to match the visual ordering.
// But if an annotation is above an other one, then we must draw it
// after the other one whatever the order is in the DOM, hence the
// use of the z-index.
rendered.style.zIndex = zIndex++;

if (element instanceof PopupAnnotationElement) {
// Popup annotation elements should not be on top of other
// annotation elements to prevent interfering with mouse events.
div.prepend(rendered);
} else {
// The accessibility manager will move the annotation in the DOM in
// order to match the visual ordering.
// But if an annotation is above an other one, then we must draw it
// after the other one whatever the order is in the DOM, hence the
// use of the z-index.
rendered.style.zIndex = zIndex++;

if (element instanceof PopupAnnotationElement) {
// Popup annotation elements should not be on top of other
// annotation elements to prevent interfering with mouse events.
div.prepend(rendered);
} else {
AnnotationLayer.#appendElement(
rendered,
data.id,
div,
accessibilityManager
);
}
AnnotationLayer.#appendElement(
rendered,
data.id,
div,
accessibilityManager
);
}
}
}

this.#setAnnotationCanvasMap(div, parameters.annotationCanvasMap);
this.#setAnnotationCanvasMap(div, params.annotationCanvasMap);
}

/**
* Update the annotation elements on existing annotation layer.
*
* @public
* @param {AnnotationLayerParameters} parameters
* @param {AnnotationLayerParameters} params
* @memberof AnnotationLayer
*/
static update(parameters) {
const { annotationCanvasMap, div, viewport } = parameters;
static update(params) {
const { annotationCanvasMap, div, viewport } = params;
setLayerDimensions(div, { rotation: viewport.rotation });

this.#setAnnotationCanvasMap(div, annotationCanvasMap);
Expand Down
2 changes: 1 addition & 1 deletion web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { PresentationModeState } from "./ui_utils.js";
* @property {Promise<Object<string, Array<Object>> | null>}
* [fieldObjectsPromise]
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
* @property {TextAccessibilityManager} accessibilityManager
* @property {TextAccessibilityManager} [accessibilityManager]
*/

class AnnotationLayerBuilder {
Expand Down