Merge pull request #12147 from Snuffleupagus/fix-AnnotationStorage-usage
[api-minor] Fix the `AnnotationStorage` usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
This commit is contained in:
commit
b037e59abf
@ -29,6 +29,7 @@ import {
|
|||||||
Util,
|
Util,
|
||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
|
import { AnnotationStorage } from "./annotation_storage.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} AnnotationElementParameters
|
* @typedef {Object} AnnotationElementParameters
|
||||||
@ -38,6 +39,7 @@ import {
|
|||||||
* @property {PageViewport} viewport
|
* @property {PageViewport} viewport
|
||||||
* @property {IPDFLinkService} linkService
|
* @property {IPDFLinkService} linkService
|
||||||
* @property {DownloadManager} downloadManager
|
* @property {DownloadManager} downloadManager
|
||||||
|
* @property {AnnotationStorage} [annotationStorage]
|
||||||
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
||||||
* for annotation icons. Include trailing slash.
|
* for annotation icons. Include trailing slash.
|
||||||
* @property {boolean} renderInteractiveForms
|
* @property {boolean} renderInteractiveForms
|
||||||
@ -1463,7 +1465,8 @@ class AnnotationLayer {
|
|||||||
imageResourcesPath: parameters.imageResourcesPath || "",
|
imageResourcesPath: parameters.imageResourcesPath || "",
|
||||||
renderInteractiveForms: parameters.renderInteractiveForms || false,
|
renderInteractiveForms: parameters.renderInteractiveForms || false,
|
||||||
svgFactory: new DOMSVGFactory(),
|
svgFactory: new DOMSVGFactory(),
|
||||||
annotationStorage: parameters.annotationStorage,
|
annotationStorage:
|
||||||
|
parameters.annotationStorage || new AnnotationStorage(),
|
||||||
});
|
});
|
||||||
if (element.isRenderable) {
|
if (element.isRenderable) {
|
||||||
parameters.div.appendChild(element.render());
|
parameters.div.appendChild(element.render());
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
class AnnotationStorage {
|
class AnnotationStorage {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._storage = {};
|
this._storage = Object.create(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +50,6 @@ import {
|
|||||||
VerbosityLevel,
|
VerbosityLevel,
|
||||||
} from "./shared/util.js";
|
} from "./shared/util.js";
|
||||||
import { AnnotationLayer } from "./display/annotation_layer.js";
|
import { AnnotationLayer } from "./display/annotation_layer.js";
|
||||||
import { AnnotationStorage } from "./display/annotation_storage.js";
|
|
||||||
import { apiCompatibilityParams } from "./display/api_compatibility.js";
|
import { apiCompatibilityParams } from "./display/api_compatibility.js";
|
||||||
import { GlobalWorkerOptions } from "./display/worker_options.js";
|
import { GlobalWorkerOptions } from "./display/worker_options.js";
|
||||||
import { renderTextLayer } from "./display/text_layer.js";
|
import { renderTextLayer } from "./display/text_layer.js";
|
||||||
@ -157,8 +156,6 @@ export {
|
|||||||
VerbosityLevel,
|
VerbosityLevel,
|
||||||
// From "./display/annotation_layer.js":
|
// From "./display/annotation_layer.js":
|
||||||
AnnotationLayer,
|
AnnotationLayer,
|
||||||
// From "./display/annotation_storage.js":
|
|
||||||
AnnotationStorage,
|
|
||||||
// From "./display/api_compatibility.js":
|
// From "./display/api_compatibility.js":
|
||||||
apiCompatibilityParams,
|
apiCompatibilityParams,
|
||||||
// From "./display/worker_options.js":
|
// From "./display/worker_options.js":
|
||||||
|
@ -220,7 +220,6 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
|||||||
linkService: new pdfjsViewer.SimpleLinkService(),
|
linkService: new pdfjsViewer.SimpleLinkService(),
|
||||||
imageResourcesPath,
|
imageResourcesPath,
|
||||||
renderInteractiveForms,
|
renderInteractiveForms,
|
||||||
annotationStorage: new pdfjsLib.AnnotationStorage(),
|
|
||||||
};
|
};
|
||||||
pdfjsLib.AnnotationLayer.render(parameters);
|
pdfjsLib.AnnotationLayer.render(parameters);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import { SimpleLinkService } from "./pdf_link_service.js";
|
|||||||
* @typedef {Object} AnnotationLayerBuilderOptions
|
* @typedef {Object} AnnotationLayerBuilderOptions
|
||||||
* @property {HTMLDivElement} pageDiv
|
* @property {HTMLDivElement} pageDiv
|
||||||
* @property {PDFPage} pdfPage
|
* @property {PDFPage} pdfPage
|
||||||
|
* @property {AnnotationStorage} [annotationStorage]
|
||||||
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
||||||
* for annotation icons. Include trailing slash.
|
* for annotation icons. Include trailing slash.
|
||||||
* @property {boolean} renderInteractiveForms
|
* @property {boolean} renderInteractiveForms
|
||||||
@ -38,7 +39,7 @@ class AnnotationLayerBuilder {
|
|||||||
pdfPage,
|
pdfPage,
|
||||||
linkService,
|
linkService,
|
||||||
downloadManager,
|
downloadManager,
|
||||||
annotationStorage,
|
annotationStorage = null,
|
||||||
imageResourcesPath = "",
|
imageResourcesPath = "",
|
||||||
renderInteractiveForms = false,
|
renderInteractiveForms = false,
|
||||||
l10n = NullL10n,
|
l10n = NullL10n,
|
||||||
@ -65,6 +66,9 @@ class AnnotationLayerBuilder {
|
|||||||
if (this._cancelled) {
|
if (this._cancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (annotations.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const parameters = {
|
const parameters = {
|
||||||
viewport: viewport.clone({ dontFlip: true }),
|
viewport: viewport.clone({ dontFlip: true }),
|
||||||
@ -85,9 +89,6 @@ class AnnotationLayerBuilder {
|
|||||||
} else {
|
} else {
|
||||||
// Create an annotation layer div and render the annotations
|
// Create an annotation layer div and render the annotations
|
||||||
// if there is at least one annotation.
|
// if there is at least one annotation.
|
||||||
if (annotations.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.div = document.createElement("div");
|
this.div = document.createElement("div");
|
||||||
this.div.className = "annotationLayer";
|
this.div.className = "annotationLayer";
|
||||||
this.pageDiv.appendChild(this.div);
|
this.pageDiv.appendChild(this.div);
|
||||||
@ -118,6 +119,7 @@ class DefaultAnnotationLayerFactory {
|
|||||||
/**
|
/**
|
||||||
* @param {HTMLDivElement} pageDiv
|
* @param {HTMLDivElement} pageDiv
|
||||||
* @param {PDFPage} pdfPage
|
* @param {PDFPage} pdfPage
|
||||||
|
* @param {AnnotationStorage} [annotationStorage]
|
||||||
* @param {string} [imageResourcesPath] - Path for image resources, mainly
|
* @param {string} [imageResourcesPath] - Path for image resources, mainly
|
||||||
* for annotation icons. Include trailing slash.
|
* for annotation icons. Include trailing slash.
|
||||||
* @param {boolean} renderInteractiveForms
|
* @param {boolean} renderInteractiveForms
|
||||||
@ -127,7 +129,7 @@ class DefaultAnnotationLayerFactory {
|
|||||||
createAnnotationLayerBuilder(
|
createAnnotationLayerBuilder(
|
||||||
pageDiv,
|
pageDiv,
|
||||||
pdfPage,
|
pdfPage,
|
||||||
annotationStorage,
|
annotationStorage = null,
|
||||||
imageResourcesPath = "",
|
imageResourcesPath = "",
|
||||||
renderInteractiveForms = false,
|
renderInteractiveForms = false,
|
||||||
l10n = NullL10n
|
l10n = NullL10n
|
||||||
|
@ -165,6 +165,7 @@ class IPDFAnnotationLayerFactory {
|
|||||||
/**
|
/**
|
||||||
* @param {HTMLDivElement} pageDiv
|
* @param {HTMLDivElement} pageDiv
|
||||||
* @param {PDFPage} pdfPage
|
* @param {PDFPage} pdfPage
|
||||||
|
* @param {AnnotationStorage} [annotationStorage]
|
||||||
* @param {string} [imageResourcesPath] - Path for image resources, mainly
|
* @param {string} [imageResourcesPath] - Path for image resources, mainly
|
||||||
* for annotation icons. Include trailing slash.
|
* for annotation icons. Include trailing slash.
|
||||||
* @param {boolean} renderInteractiveForms
|
* @param {boolean} renderInteractiveForms
|
||||||
@ -174,6 +175,7 @@ class IPDFAnnotationLayerFactory {
|
|||||||
createAnnotationLayerBuilder(
|
createAnnotationLayerBuilder(
|
||||||
pageDiv,
|
pageDiv,
|
||||||
pdfPage,
|
pdfPage,
|
||||||
|
annotationStorage = null,
|
||||||
imageResourcesPath = "",
|
imageResourcesPath = "",
|
||||||
renderInteractiveForms = false,
|
renderInteractiveForms = false,
|
||||||
l10n = undefined
|
l10n = undefined
|
||||||
|
Loading…
x
Reference in New Issue
Block a user