Skip to content

Commit

Permalink
Merge pull request #12147 from Snuffleupagus/fix-AnnotationStorage-usage
Browse files Browse the repository at this point in the history
[api-minor] Fix the `AnnotationStorage` usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
  • Loading branch information
timvandermeij authored Jul 31, 2020
2 parents c5663f2 + 95bfc43 commit b037e59
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
Util,
warn,
} from "../shared/util.js";
import { AnnotationStorage } from "./annotation_storage.js";

/**
* @typedef {Object} AnnotationElementParameters
Expand All @@ -38,6 +39,7 @@ import {
* @property {PageViewport} viewport
* @property {IPDFLinkService} linkService
* @property {DownloadManager} downloadManager
* @property {AnnotationStorage} [annotationStorage]
* @property {string} [imageResourcesPath] - Path for image resources, mainly
* for annotation icons. Include trailing slash.
* @property {boolean} renderInteractiveForms
Expand Down Expand Up @@ -1463,7 +1465,8 @@ class AnnotationLayer {
imageResourcesPath: parameters.imageResourcesPath || "",
renderInteractiveForms: parameters.renderInteractiveForms || false,
svgFactory: new DOMSVGFactory(),
annotationStorage: parameters.annotationStorage,
annotationStorage:
parameters.annotationStorage || new AnnotationStorage(),
});
if (element.isRenderable) {
parameters.div.appendChild(element.render());
Expand Down
2 changes: 1 addition & 1 deletion src/display/annotation_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class AnnotationStorage {
constructor() {
this._storage = {};
this._storage = Object.create(null);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
VerbosityLevel,
} from "./shared/util.js";
import { AnnotationLayer } from "./display/annotation_layer.js";
import { AnnotationStorage } from "./display/annotation_storage.js";
import { apiCompatibilityParams } from "./display/api_compatibility.js";
import { GlobalWorkerOptions } from "./display/worker_options.js";
import { renderTextLayer } from "./display/text_layer.js";
Expand Down Expand Up @@ -157,8 +156,6 @@ export {
VerbosityLevel,
// From "./display/annotation_layer.js":
AnnotationLayer,
// From "./display/annotation_storage.js":
AnnotationStorage,
// From "./display/api_compatibility.js":
apiCompatibilityParams,
// From "./display/worker_options.js":
Expand Down
1 change: 0 additions & 1 deletion test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
linkService: new pdfjsViewer.SimpleLinkService(),
imageResourcesPath,
renderInteractiveForms,
annotationStorage: new pdfjsLib.AnnotationStorage(),
};
pdfjsLib.AnnotationLayer.render(parameters);

Expand Down
12 changes: 7 additions & 5 deletions web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SimpleLinkService } from "./pdf_link_service.js";
* @typedef {Object} AnnotationLayerBuilderOptions
* @property {HTMLDivElement} pageDiv
* @property {PDFPage} pdfPage
* @property {AnnotationStorage} [annotationStorage]
* @property {string} [imageResourcesPath] - Path for image resources, mainly
* for annotation icons. Include trailing slash.
* @property {boolean} renderInteractiveForms
Expand All @@ -38,7 +39,7 @@ class AnnotationLayerBuilder {
pdfPage,
linkService,
downloadManager,
annotationStorage,
annotationStorage = null,
imageResourcesPath = "",
renderInteractiveForms = false,
l10n = NullL10n,
Expand All @@ -65,6 +66,9 @@ class AnnotationLayerBuilder {
if (this._cancelled) {
return;
}
if (annotations.length === 0) {
return;
}

const parameters = {
viewport: viewport.clone({ dontFlip: true }),
Expand All @@ -85,9 +89,6 @@ class AnnotationLayerBuilder {
} else {
// Create an annotation layer div and render the annotations
// if there is at least one annotation.
if (annotations.length === 0) {
return;
}
this.div = document.createElement("div");
this.div.className = "annotationLayer";
this.pageDiv.appendChild(this.div);
Expand Down Expand Up @@ -118,6 +119,7 @@ class DefaultAnnotationLayerFactory {
/**
* @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage
* @param {AnnotationStorage} [annotationStorage]
* @param {string} [imageResourcesPath] - Path for image resources, mainly
* for annotation icons. Include trailing slash.
* @param {boolean} renderInteractiveForms
Expand All @@ -127,7 +129,7 @@ class DefaultAnnotationLayerFactory {
createAnnotationLayerBuilder(
pageDiv,
pdfPage,
annotationStorage,
annotationStorage = null,
imageResourcesPath = "",
renderInteractiveForms = false,
l10n = NullL10n
Expand Down
2 changes: 2 additions & 0 deletions web/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class IPDFAnnotationLayerFactory {
/**
* @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage
* @param {AnnotationStorage} [annotationStorage]
* @param {string} [imageResourcesPath] - Path for image resources, mainly
* for annotation icons. Include trailing slash.
* @param {boolean} renderInteractiveForms
Expand All @@ -174,6 +175,7 @@ class IPDFAnnotationLayerFactory {
createAnnotationLayerBuilder(
pageDiv,
pdfPage,
annotationStorage = null,
imageResourcesPath = "",
renderInteractiveForms = false,
l10n = undefined
Expand Down

0 comments on commit b037e59

Please sign in to comment.