mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
[api-minor] Remove the annotationLayerFactory
in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this. Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things. Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication. Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary. Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration. --- [1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
This commit is contained in:
parent
7aedb8ed7a
commit
ca69da735e
5 changed files with 62 additions and 185 deletions
|
@ -22,9 +22,6 @@
|
|||
/** @typedef {import("./event_utils").EventBus} EventBus */
|
||||
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
|
||||
/** @typedef {import("./interfaces").IL10n} IL10n */
|
||||
// eslint-disable-next-line max-len
|
||||
/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */
|
||||
// eslint-disable-next-line max-len
|
||||
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
||||
// eslint-disable-next-line max-len
|
||||
/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */
|
||||
|
@ -68,7 +65,6 @@ import {
|
|||
VERTICAL_PADDING,
|
||||
watchScroll,
|
||||
} from "./ui_utils.js";
|
||||
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
|
||||
import { NullL10n } from "./l10n_utils.js";
|
||||
import { PDFPageView } from "./pdf_page_view.js";
|
||||
import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
|
||||
|
@ -210,7 +206,6 @@ class PDFPageViewBuffer {
|
|||
/**
|
||||
* Simple viewer control to display PDF content/pages.
|
||||
*
|
||||
* @implements {IPDFAnnotationLayerFactory}
|
||||
* @implements {IPDFStructTreeLayerFactory}
|
||||
* @implements {IPDFTextLayerFactory}
|
||||
* @implements {IPDFXfaLayerFactory}
|
||||
|
@ -562,6 +557,24 @@ class PDFViewer {
|
|||
get annotationEditorUIManager() {
|
||||
return self.#annotationEditorUIManager;
|
||||
},
|
||||
get annotationStorage() {
|
||||
return self.pdfDocument?.annotationStorage;
|
||||
},
|
||||
get downloadManager() {
|
||||
return self.downloadManager;
|
||||
},
|
||||
get enableScripting() {
|
||||
return !!self._scriptingManager;
|
||||
},
|
||||
get fieldObjectsPromise() {
|
||||
return self.pdfDocument?.getFieldObjects();
|
||||
},
|
||||
get hasJSActionsPromise() {
|
||||
return self.pdfDocument?.hasJSActions();
|
||||
},
|
||||
get linkService() {
|
||||
return self.linkService;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -776,8 +789,6 @@ class PDFViewer {
|
|||
textLayerFactory:
|
||||
textLayerMode !== TextLayerMode.DISABLE ? this : null,
|
||||
textLayerMode,
|
||||
annotationLayerFactory:
|
||||
annotationMode !== AnnotationMode.DISABLE ? this : null,
|
||||
annotationMode,
|
||||
xfaLayerFactory: this,
|
||||
textHighlighterFactory: this,
|
||||
|
@ -1696,59 +1707,6 @@ class PDFViewer {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} CreateAnnotationLayerBuilderParameters
|
||||
* @property {HTMLDivElement} pageDiv
|
||||
* @property {PDFPageProxy} pdfPage
|
||||
* @property {AnnotationStorage} [annotationStorage] - Storage for annotation
|
||||
* data in forms.
|
||||
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
||||
* for annotation icons. Include trailing slash.
|
||||
* @property {boolean} renderForms
|
||||
* @property {IL10n} l10n
|
||||
* @property {boolean} [enableScripting]
|
||||
* @property {Promise<boolean>} [hasJSActionsPromise]
|
||||
* @property {Promise<Object<string, Array<Object>> | null>}
|
||||
* [fieldObjectsPromise]
|
||||
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
|
||||
* annotation ids with canvases used to render them.
|
||||
* @property {TextAccessibilityManager} [accessibilityManager]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {CreateAnnotationLayerBuilderParameters}
|
||||
* @returns {AnnotationLayerBuilder}
|
||||
*/
|
||||
createAnnotationLayerBuilder({
|
||||
pageDiv,
|
||||
pdfPage,
|
||||
annotationStorage = this.pdfDocument?.annotationStorage,
|
||||
imageResourcesPath = "",
|
||||
renderForms = true,
|
||||
l10n = NullL10n,
|
||||
enableScripting = this.enableScripting,
|
||||
hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
|
||||
fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
|
||||
annotationCanvasMap = null,
|
||||
accessibilityManager = null,
|
||||
}) {
|
||||
return new AnnotationLayerBuilder({
|
||||
pageDiv,
|
||||
pdfPage,
|
||||
annotationStorage,
|
||||
imageResourcesPath,
|
||||
renderForms,
|
||||
linkService: this.linkService,
|
||||
downloadManager: this.downloadManager,
|
||||
l10n,
|
||||
enableScripting,
|
||||
hasJSActionsPromise,
|
||||
fieldObjectsPromise,
|
||||
annotationCanvasMap,
|
||||
accessibilityManager,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} CreateXfaLayerBuilderParameters
|
||||
* @property {HTMLDivElement} pageDiv
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue