Skip to content

Commit

Permalink
Handle possibly undefined parameters *once* per `AnnotationLayer.rend…
Browse files Browse the repository at this point in the history
…er` invocation

There's no reason to repeat this for every single annotation. Also, adds a couple of missing JSDoc-parameters.
  • Loading branch information
Snuffleupagus committed Dec 14, 2022
1 parent e182597 commit 72c4dad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
45 changes: 25 additions & 20 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,18 @@ 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 imageResourcesPath = params.imageResourcesPath || "",
renderForms = params.renderForms !== false,
svgFactory = new DOMSVGFactory(),
annotationStorage = params.annotationStorage || new AnnotationStorage(),
enableScripting = params.enableScripting === true;
let zIndex = 0;

for (const data of annotations) {
Expand All @@ -2608,18 +2615,17 @@ class AnnotationLayer {
const element = AnnotationElementFactory.create({
data,
layer: div,
page: parameters.page,
page: params.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,
linkService: params.linkService,
downloadManager: params.downloadManager,
imageResourcesPath,
renderForms,
svgFactory,
annotationStorage,
enableScripting,
hasJSActions: params.hasJSActions,
fieldObjects: params.fieldObjects,
});
if (element.isRenderable) {
const rendered = element.render();
Expand Down Expand Up @@ -2660,18 +2666,17 @@ class AnnotationLayer {
}
}

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

0 comments on commit 72c4dad

Please sign in to comment.