From ded02941f22aeb501e5d909048f93db89bdf18dd Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 6 Dec 2022 13:38:19 +0100 Subject: [PATCH 1/9] [api-minor] Move, most of, the `isPureXfa`-handling from `PDFViewer` and into `PDFPageView` By moving this code the "pageviewer"-component example will become slightly more usable on its own, it may simplify a future addition of XFA Foreground document support, and finally also serves as preparation for the following patches. --- src/display/api.js | 9 ++++++++- web/pdf_page_view.js | 3 ++- web/pdf_viewer.js | 26 ++++++++++---------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index d868304bd..1dfa78b65 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -783,7 +783,7 @@ class PDFDocumentProxy { * @type {boolean} True if only XFA form. */ get isPureXfa() { - return !!this._transport._htmlForXfa; + return shadow(this, "isPureXfa", !!this._transport._htmlForXfa); } /** @@ -1343,6 +1343,13 @@ class PDFPageProxy { )); } + /** + * @type {boolean} True if only XFA form. + */ + get isPureXfa() { + return shadow(this, "isPureXfa", !!this._transport._htmlForXfa); + } + /** * @returns {Promise} A promise that is resolved with * an {Object} with a fake DOM object (a tree structure where elements diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 416ff69fc..b962c3894 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -753,6 +753,7 @@ class PDFPageView { if ( !this.textLayer && this.textLayerMode !== TextLayerMode.DISABLE && + !pdfPage.isPureXfa && this.textLayerFactory ) { this._accessibilityManager ||= new TextAccessibilityManager(); @@ -878,7 +879,7 @@ class PDFPageView { } ); - if (this.xfaLayerFactory) { + if (pdfPage.isPureXfa && this.xfaLayerFactory) { this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({ pageDiv: div, pdfPage, diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index e5b8b9da0..f8686bab3 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -658,7 +658,6 @@ class PDFViewer { if (!pdfDocument) { return; } - const isPureXfa = pdfDocument.isPureXfa; const pagesCount = pdfDocument.numPages; const firstPagePromise = pdfDocument.getPage(1); // Rendering (potentially) depends on this, hence fetching it immediately. @@ -732,13 +731,13 @@ class PDFViewer { if (annotationEditorMode !== AnnotationEditorType.DISABLE) { const mode = annotationEditorMode; - if (isPureXfa) { + if (pdfDocument.isPureXfa) { console.warn("Warning: XFA-editing is not implemented."); } else if (isValidAnnotationEditorMode(mode)) { this.#annotationEditorUIManager = new AnnotationEditorUIManager( this.container, this.eventBus, - this.pdfDocument?.annotationStorage + pdfDocument?.annotationStorage ); if (mode !== AnnotationEditorType.NONE) { this.#annotationEditorUIManager.updateMode(mode); @@ -758,15 +757,6 @@ class PDFViewer { // see issue 15795. docStyle.setProperty("--scale-factor", viewport.scale); - const textLayerFactory = - textLayerMode !== TextLayerMode.DISABLE && !isPureXfa ? this : null; - const annotationLayerFactory = - annotationMode !== AnnotationMode.DISABLE ? this : null; - const xfaLayerFactory = isPureXfa ? this : null; - const annotationEditorLayerFactory = this.#annotationEditorUIManager - ? this - : null; - for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { const pageView = new PDFPageView({ container: viewerElement, @@ -776,12 +766,16 @@ class PDFViewer { defaultViewport: viewport.clone(), optionalContentConfigPromise, renderingQueue: this.renderingQueue, - textLayerFactory, + textLayerFactory: + textLayerMode !== TextLayerMode.DISABLE ? this : null, textLayerMode, - annotationLayerFactory, + annotationLayerFactory: + annotationMode !== AnnotationMode.DISABLE ? this : null, annotationMode, - xfaLayerFactory, - annotationEditorLayerFactory, + xfaLayerFactory: this, + annotationEditorLayerFactory: this.#annotationEditorUIManager + ? this + : null, textHighlighterFactory: this, structTreeLayerFactory: this, imageResourcesPath: this.imageResourcesPath, From 8fa8310ec91297a4a0c6b4894473a9e15010ec9a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 7 Dec 2022 17:27:02 +0100 Subject: [PATCH 2/9] Decouple the `annotationLayer` and `annotationEditorLayer` in the viewer Currently we'll only initialize and render the `annotationEditorLayer` once the regular `annotationLayer` has been rendered. While it obviously makes sense to render the `annotationEditorLayer` *last*, the way that the code is currently written means that if a third-party user disables the `annotationLayer` then the editing-functionality indirectly becomes disabled as well. Given that this seems like a somewhat arbitrary limitation, this patch simply decouples these two layers while still keeping the rendering order consistent. --- web/pdf_page_view.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index b962c3894..49826c438 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -853,24 +853,23 @@ class PDFPageView { const resultPromise = paintTask.promise.then( () => { - return finishPaintTask(null).then(() => { + return finishPaintTask(null).then(async () => { this.#renderTextLayer(); if (this.annotationLayer) { - this.#renderAnnotationLayer().then(() => { - if (this.annotationEditorLayerFactory) { - this.annotationEditorLayer ||= - this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder( - { - pageDiv: div, - pdfPage, - l10n: this.l10n, - accessibilityManager: this._accessibilityManager, - } - ); - this.#renderAnnotationEditorLayer(); - } - }); + await this.#renderAnnotationLayer(); + } + if (this.annotationEditorLayerFactory) { + this.annotationEditorLayer ||= + this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder( + { + pageDiv: div, + pdfPage, + l10n: this.l10n, + accessibilityManager: this._accessibilityManager, + } + ); + this.#renderAnnotationEditorLayer(); } }); }, From 7aedb8ed7a7f58d185b71f43ff6b60adf2753d7e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 6 Dec 2022 14:21:51 +0100 Subject: [PATCH 3/9] [api-minor] Remove the `annotationEditorLayerFactory` 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 `annotationEditorLayerFactory` 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. --- web/annotation_editor_layer_builder.js | 2 +- web/default_factory.js | 37 --------------------- web/interfaces.js | 29 ---------------- web/pdf_page_view.js | 45 ++++++++++++++++--------- web/pdf_viewer.js | 46 ++++++-------------------- 5 files changed, 42 insertions(+), 117 deletions(-) diff --git a/web/annotation_editor_layer_builder.js b/web/annotation_editor_layer_builder.js index 06f59526e..09bc560ba 100644 --- a/web/annotation_editor_layer_builder.js +++ b/web/annotation_editor_layer_builder.js @@ -30,7 +30,7 @@ import { NullL10n } from "./l10n_utils.js"; * @property {AnnotationEditorUIManager} [uiManager] * @property {HTMLDivElement} pageDiv * @property {PDFPageProxy} pdfPage - * @property {IL10n} l10n + * @property {IL10n} [l10n] * @property {TextAccessibilityManager} [accessibilityManager] */ diff --git a/web/default_factory.js b/web/default_factory.js index bba1cd115..deec730fe 100644 --- a/web/default_factory.js +++ b/web/default_factory.js @@ -22,7 +22,6 @@ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ // eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFAnnotationEditorLayerFactory} IPDFAnnotationEditorLayerFactory */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ @@ -33,7 +32,6 @@ // eslint-disable-next-line max-len /** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ -import { AnnotationEditorLayerBuilder } from "./annotation_editor_layer_builder.js"; import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; import { NullL10n } from "./l10n_utils.js"; import { SimpleLinkService } from "./pdf_link_service.js"; @@ -98,40 +96,6 @@ class DefaultAnnotationLayerFactory { } } -/** - * @implements IPDFAnnotationEditorLayerFactory - */ -class DefaultAnnotationEditorLayerFactory { - /** - * @typedef {Object} CreateAnnotationEditorLayerBuilderParameters - * @property {AnnotationEditorUIManager} [uiManager] - * @property {HTMLDivElement} pageDiv - * @property {PDFPageProxy} pdfPage - * @property {IL10n} l10n - * @property {TextAccessibilityManager} [accessibilityManager] - */ - - /** - * @param {CreateAnnotationEditorLayerBuilderParameters} - * @returns {AnnotationEditorLayerBuilder} - */ - createAnnotationEditorLayerBuilder({ - uiManager = null, - pageDiv, - pdfPage, - accessibilityManager = null, - l10n, - }) { - return new AnnotationEditorLayerBuilder({ - uiManager, - pageDiv, - pdfPage, - accessibilityManager, - l10n, - }); - } -} - /** * @implements IPDFStructTreeLayerFactory */ @@ -199,7 +163,6 @@ class DefaultXfaLayerFactory { } export { - DefaultAnnotationEditorLayerFactory, DefaultAnnotationLayerFactory, DefaultStructTreeLayerFactory, DefaultTextLayerFactory, diff --git a/web/interfaces.js b/web/interfaces.js index fce1898d9..faac8d7b9 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -20,8 +20,6 @@ // eslint-disable-next-line max-len /** @typedef {import("./annotation_layer_builder").AnnotationLayerBuilder} AnnotationLayerBuilder */ // eslint-disable-next-line max-len -/** @typedef {import("./annotation_editor_layer_builder").AnnotationEditorLayerBuilder} AnnotationEditorLayerBuilder */ -// eslint-disable-next-line max-len /** @typedef {import("./struct_tree_builder").StructTreeLayerBuilder} StructTreeLayerBuilder */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ // eslint-disable-next-line max-len @@ -225,32 +223,6 @@ class IPDFAnnotationLayerFactory { }) {} } -/** - * @interface - */ -class IPDFAnnotationEditorLayerFactory { - /** - * @typedef {Object} CreateAnnotationEditorLayerBuilderParameters - * @property {AnnotationEditorUIManager} [uiManager] - * @property {HTMLDivElement} pageDiv - * @property {PDFPageProxy} pdfPage - * @property {IL10n} l10n - * @property {TextAccessibilityManager} [accessibilityManager] - */ - - /** - * @param {CreateAnnotationEditorLayerBuilderParameters} - * @returns {AnnotationEditorLayerBuilder} - */ - createAnnotationEditorLayerBuilder({ - uiManager = null, - pageDiv, - pdfPage, - l10n, - accessibilityManager, - }) {} -} - /** * @interface */ @@ -349,7 +321,6 @@ class IL10n { export { IDownloadManager, IL10n, - IPDFAnnotationEditorLayerFactory, IPDFAnnotationLayerFactory, IPDFLinkService, IPDFStructTreeLayerFactory, diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 49826c438..475b79820 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -22,8 +22,6 @@ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ // eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFAnnotationEditorLayerFactory} IPDFAnnotationEditorLayerFactory */ -// eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ @@ -52,6 +50,7 @@ import { roundToDivide, TextLayerMode, } from "./ui_utils.js"; +import { AnnotationEditorLayerBuilder } from "./annotation_editor_layer_builder.js"; import { compatibilityParams } from "./app_options.js"; import { NullL10n } from "./l10n_utils.js"; import { TextAccessibilityManager } from "./text_accessibility.js"; @@ -77,7 +76,6 @@ import { TextAccessibilityManager } from "./text_accessibility.js"; * see also {@link RenderParameters} and {@link GetOperatorListParameters}. * The default value is `AnnotationMode.ENABLE_FORMS`. * @property {IPDFAnnotationLayerFactory} [annotationLayerFactory] - * @property {IPDFAnnotationEditorLayerFactory} [annotationEditorLayerFactory] * @property {IPDFXfaLayerFactory} [xfaLayerFactory] * @property {IPDFStructTreeLayerFactory} [structTreeLayerFactory] * @property {Object} [textHighlighterFactory] @@ -94,16 +92,29 @@ import { TextAccessibilityManager } from "./text_accessibility.js"; * with user defined ones in order to improve readability in high contrast * mode. * @property {IL10n} [l10n] - Localization service. + * @property {function} [layerProperties] - The function that is used to lookup + * the necessary layer-properties. */ const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216; +const DEFAULT_LAYER_PROPERTIES = () => { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("COMPONENTS")) { + return null; + } + return { + annotationEditorUIManager: null, + }; +}; + /** * @implements {IRenderableView} */ class PDFPageView { #annotationMode = AnnotationMode.ENABLE_FORMS; + #layerProperties = null; + #useThumbnailCanvas = { initialOptionalContent: true, regularAnnotations: true, @@ -118,6 +129,7 @@ class PDFPageView { this.id = options.id; this.renderingId = "page" + this.id; + this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES; this.pdfPage = null; this.pageLabel = null; @@ -142,7 +154,6 @@ class PDFPageView { this.renderingQueue = options.renderingQueue; this.textLayerFactory = options.textLayerFactory; this.annotationLayerFactory = options.annotationLayerFactory; - this.annotationEditorLayerFactory = options.annotationEditorLayerFactory; this.xfaLayerFactory = options.xfaLayerFactory; this._textHighlighterFactory = options.textHighlighterFactory; this.structTreeLayerFactory = options.structTreeLayerFactory; @@ -859,18 +870,22 @@ class PDFPageView { if (this.annotationLayer) { await this.#renderAnnotationLayer(); } - if (this.annotationEditorLayerFactory) { - this.annotationEditorLayer ||= - this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder( - { - pageDiv: div, - pdfPage, - l10n: this.l10n, - accessibilityManager: this._accessibilityManager, - } - ); - this.#renderAnnotationEditorLayer(); + + if (!this.annotationEditorLayer) { + const { annotationEditorUIManager } = this.#layerProperties(); + + if (!annotationEditorUIManager) { + return; + } + this.annotationEditorLayer = new AnnotationEditorLayerBuilder({ + uiManager: annotationEditorUIManager, + pageDiv: div, + pdfPage, + l10n: this.l10n, + accessibilityManager: this._accessibilityManager, + }); } + this.#renderAnnotationEditorLayer(); }); }, function (reason) { diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index f8686bab3..8d6d76ffc 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -25,7 +25,6 @@ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ // eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFAnnotationEditorLayerFactory} IPDFAnnotationEditorLayerFactory */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ @@ -69,7 +68,6 @@ import { VERTICAL_PADDING, watchScroll, } from "./ui_utils.js"; -import { AnnotationEditorLayerBuilder } from "./annotation_editor_layer_builder.js"; import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; import { NullL10n } from "./l10n_utils.js"; import { PDFPageView } from "./pdf_page_view.js"; @@ -213,7 +211,6 @@ class PDFPageViewBuffer { * Simple viewer control to display PDF content/pages. * * @implements {IPDFAnnotationLayerFactory} - * @implements {IPDFAnnotationEditorLayerFactory} * @implements {IPDFStructTreeLayerFactory} * @implements {IPDFTextLayerFactory} * @implements {IPDFXfaLayerFactory} @@ -559,6 +556,15 @@ class PDFViewer { return this.pdfDocument ? this._pagesCapability.promise : null; } + #layerProperties() { + const self = this; + return { + get annotationEditorUIManager() { + return self.#annotationEditorUIManager; + }, + }; + } + /** * Currently only *some* permissions are supported. * @returns {Object} @@ -747,6 +753,7 @@ class PDFViewer { } } + const layerProperties = this.#layerProperties.bind(this); const viewerElement = this._scrollMode === ScrollMode.PAGE ? null : this.viewer; const scale = this.currentScale; @@ -773,9 +780,6 @@ class PDFViewer { annotationMode !== AnnotationMode.DISABLE ? this : null, annotationMode, xfaLayerFactory: this, - annotationEditorLayerFactory: this.#annotationEditorUIManager - ? this - : null, textHighlighterFactory: this, structTreeLayerFactory: this, imageResourcesPath: this.imageResourcesPath, @@ -789,6 +793,7 @@ class PDFViewer { maxCanvasPixels: this.maxCanvasPixels, pageColors: this.pageColors, l10n: this.l10n, + layerProperties, }); this._pages.push(pageView); } @@ -1744,35 +1749,6 @@ class PDFViewer { }); } - /** - * @typedef {Object} CreateAnnotationEditorLayerBuilderParameters - * @property {AnnotationEditorUIManager} [uiManager] - * @property {HTMLDivElement} pageDiv - * @property {PDFPageProxy} pdfPage - * @property {IL10n} l10n - * @property {TextAccessibilityManager} [accessibilityManager] - */ - - /** - * @param {CreateAnnotationEditorLayerBuilderParameters} - * @returns {AnnotationEditorLayerBuilder} - */ - createAnnotationEditorLayerBuilder({ - uiManager = this.#annotationEditorUIManager, - pageDiv, - pdfPage, - accessibilityManager = null, - l10n, - }) { - return new AnnotationEditorLayerBuilder({ - uiManager, - pageDiv, - pdfPage, - accessibilityManager, - l10n, - }); - } - /** * @typedef {Object} CreateXfaLayerBuilderParameters * @property {HTMLDivElement} pageDiv From ca69da735e72dc9df2144861c4d1b2406c84dca5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 6 Dec 2022 23:34:55 +0100 Subject: [PATCH 4/9] [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. --- web/default_factory.js | 63 ------------------------------ web/interfaces.js | 45 --------------------- web/pdf_page_view.js | 50 ++++++++++++++++-------- web/pdf_viewer.component.js | 11 +++++- web/pdf_viewer.js | 78 +++++++++---------------------------- 5 files changed, 62 insertions(+), 185 deletions(-) diff --git a/web/default_factory.js b/web/default_factory.js index deec730fe..0ff79bfa9 100644 --- a/web/default_factory.js +++ b/web/default_factory.js @@ -19,9 +19,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 */ @@ -32,70 +29,11 @@ // eslint-disable-next-line max-len /** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ -import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; -import { NullL10n } from "./l10n_utils.js"; import { SimpleLinkService } from "./pdf_link_service.js"; import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextLayerBuilder } from "./text_layer_builder.js"; import { XfaLayerBuilder } from "./xfa_layer_builder.js"; -/** - * @implements IPDFAnnotationLayerFactory - */ -class DefaultAnnotationLayerFactory { - /** - * @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} [hasJSActionsPromise] - * @property {Promise> | null>} - * [fieldObjectsPromise] - * @property {Map} [annotationCanvasMap] - Map some - * annotation ids with canvases used to render them. - * @property {TextAccessibilityManager} [accessibilityManager] - */ - - /** - * @param {CreateAnnotationLayerBuilderParameters} - * @returns {AnnotationLayerBuilder} - */ - createAnnotationLayerBuilder({ - pageDiv, - pdfPage, - annotationStorage = null, - imageResourcesPath = "", - renderForms = true, - l10n = NullL10n, - enableScripting = false, - hasJSActionsPromise = null, - fieldObjectsPromise = null, - annotationCanvasMap = null, - accessibilityManager = null, - }) { - return new AnnotationLayerBuilder({ - pageDiv, - pdfPage, - imageResourcesPath, - renderForms, - linkService: new SimpleLinkService(), - l10n, - annotationStorage, - enableScripting, - hasJSActionsPromise, - fieldObjectsPromise, - annotationCanvasMap, - accessibilityManager, - }); - } -} - /** * @implements IPDFStructTreeLayerFactory */ @@ -163,7 +101,6 @@ class DefaultXfaLayerFactory { } export { - DefaultAnnotationLayerFactory, DefaultStructTreeLayerFactory, DefaultTextLayerFactory, DefaultXfaLayerFactory, diff --git a/web/interfaces.js b/web/interfaces.js index faac8d7b9..c963cac50 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -18,8 +18,6 @@ // eslint-disable-next-line max-len /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ // eslint-disable-next-line max-len -/** @typedef {import("./annotation_layer_builder").AnnotationLayerBuilder} AnnotationLayerBuilder */ -// eslint-disable-next-line max-len /** @typedef {import("./struct_tree_builder").StructTreeLayerBuilder} StructTreeLayerBuilder */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ // eslint-disable-next-line max-len @@ -181,48 +179,6 @@ class IPDFTextLayerFactory { }) {} } -/** - * @interface - */ -class IPDFAnnotationLayerFactory { - /** - * @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} [hasJSActionsPromise] - * @property {Promise> | null>} - * [fieldObjectsPromise] - * @property {Map} [annotationCanvasMap] - Map some - * annotation ids with canvases used to render them. - * @property {TextAccessibilityManager} [accessibilityManager] - */ - - /** - * @param {CreateAnnotationLayerBuilderParameters} - * @returns {AnnotationLayerBuilder} - */ - createAnnotationLayerBuilder({ - pageDiv, - pdfPage, - annotationStorage = null, - imageResourcesPath = "", - renderForms = true, - l10n = undefined, - enableScripting = false, - hasJSActionsPromise = null, - fieldObjectsPromise = null, - annotationCanvasMap = null, - accessibilityManager = null, - }) {} -} - /** * @interface */ @@ -321,7 +277,6 @@ class IL10n { export { IDownloadManager, IL10n, - IPDFAnnotationLayerFactory, IPDFLinkService, IPDFStructTreeLayerFactory, IPDFTextLayerFactory, diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 475b79820..a3638041b 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -20,8 +20,6 @@ /** @typedef {import("./event_utils").EventBus} EventBus */ /** @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").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ @@ -51,8 +49,10 @@ import { TextLayerMode, } from "./ui_utils.js"; import { AnnotationEditorLayerBuilder } from "./annotation_editor_layer_builder.js"; +import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; import { compatibilityParams } from "./app_options.js"; import { NullL10n } from "./l10n_utils.js"; +import { SimpleLinkService } from "./pdf_link_service.js"; import { TextAccessibilityManager } from "./text_accessibility.js"; /** @@ -75,7 +75,6 @@ import { TextAccessibilityManager } from "./text_accessibility.js"; * being rendered. The constants from {@link AnnotationMode} should be used; * see also {@link RenderParameters} and {@link GetOperatorListParameters}. * The default value is `AnnotationMode.ENABLE_FORMS`. - * @property {IPDFAnnotationLayerFactory} [annotationLayerFactory] * @property {IPDFXfaLayerFactory} [xfaLayerFactory] * @property {IPDFStructTreeLayerFactory} [structTreeLayerFactory] * @property {Object} [textHighlighterFactory] @@ -104,6 +103,12 @@ const DEFAULT_LAYER_PROPERTIES = () => { } return { annotationEditorUIManager: null, + annotationStorage: null, + downloadManager: null, + enableScripting: false, + fieldObjectsPromise: null, + hasJSActionsPromise: null, + linkService: new SimpleLinkService(), }; }; @@ -153,7 +158,6 @@ class PDFPageView { this.eventBus = options.eventBus; this.renderingQueue = options.renderingQueue; this.textLayerFactory = options.textLayerFactory; - this.annotationLayerFactory = options.annotationLayerFactory; this.xfaLayerFactory = options.xfaLayerFactory; this._textHighlighterFactory = options.textHighlighterFactory; this.structTreeLayerFactory = options.structTreeLayerFactory; @@ -778,20 +782,34 @@ class PDFPageView { } if ( - this.#annotationMode !== AnnotationMode.DISABLE && - this.annotationLayerFactory + !this.annotationLayer && + this.#annotationMode !== AnnotationMode.DISABLE ) { + const { + annotationStorage, + downloadManager, + enableScripting, + fieldObjectsPromise, + hasJSActionsPromise, + linkService, + } = this.#layerProperties(); + this._annotationCanvasMap ||= new Map(); - this.annotationLayer ||= - this.annotationLayerFactory.createAnnotationLayerBuilder({ - pageDiv: div, - pdfPage, - imageResourcesPath: this.imageResourcesPath, - renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS, - l10n: this.l10n, - annotationCanvasMap: this._annotationCanvasMap, - accessibilityManager: this._accessibilityManager, - }); + this.annotationLayer = new AnnotationLayerBuilder({ + pageDiv: div, + pdfPage, + annotationStorage, + imageResourcesPath: this.imageResourcesPath, + renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS, + linkService, + downloadManager, + l10n: this.l10n, + enableScripting, + hasJSActionsPromise, + fieldObjectsPromise, + annotationCanvasMap: this._annotationCanvasMap, + accessibilityManager: this._accessibilityManager, + }); } if (this.xfaLayer?.div) { diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js index bf25bcbb8..cd4ba1fc5 100644 --- a/web/pdf_viewer.component.js +++ b/web/pdf_viewer.component.js @@ -14,7 +14,6 @@ */ import { - DefaultAnnotationLayerFactory, DefaultStructTreeLayerFactory, DefaultTextLayerFactory, DefaultXfaLayerFactory, @@ -51,6 +50,16 @@ const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION"); // eslint-disable-next-line no-unused-vars const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD"); +class DefaultAnnotationLayerFactory { + constructor() { + throw new Error( + "The `DefaultAnnotationLayerFactory` has been removed, " + + "please use the `annotationMode` option when initializing " + + "the `PDFPageView`-instance to control AnnotationLayer rendering." + ); + } +} + export { AnnotationLayerBuilder, DefaultAnnotationLayerFactory, diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 8d6d76ffc..481fc01f8 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -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} [hasJSActionsPromise] - * @property {Promise> | null>} - * [fieldObjectsPromise] - * @property {Map} [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 From f1d1f6edfd032e956d1298d0aa21fa6bce7dd11e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 6 Dec 2022 23:43:09 +0100 Subject: [PATCH 5/9] [api-minor] Remove the `structTreeLayerFactory` 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 `structTreeLayerFactory` 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. --- web/default_factory.js | 21 +-------------------- web/interfaces.js | 13 ------------- web/pdf_page_view.js | 12 +++--------- web/pdf_viewer.component.js | 10 +++++++++- web/pdf_viewer.js | 12 ------------ 5 files changed, 13 insertions(+), 55 deletions(-) diff --git a/web/default_factory.js b/web/default_factory.js index 0ff79bfa9..ae24a5e7c 100644 --- a/web/default_factory.js +++ b/web/default_factory.js @@ -21,8 +21,6 @@ /** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ // eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ -// eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ @@ -30,22 +28,9 @@ /** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ import { SimpleLinkService } from "./pdf_link_service.js"; -import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextLayerBuilder } from "./text_layer_builder.js"; import { XfaLayerBuilder } from "./xfa_layer_builder.js"; -/** - * @implements IPDFStructTreeLayerFactory - */ -class DefaultStructTreeLayerFactory { - /** - * @returns {StructTreeLayerBuilder} - */ - createStructTreeLayerBuilder() { - return new StructTreeLayerBuilder(); - } -} - /** * @implements IPDFTextLayerFactory */ @@ -100,8 +85,4 @@ class DefaultXfaLayerFactory { } } -export { - DefaultStructTreeLayerFactory, - DefaultTextLayerFactory, - DefaultXfaLayerFactory, -}; +export { DefaultTextLayerFactory, DefaultXfaLayerFactory }; diff --git a/web/interfaces.js b/web/interfaces.js index c963cac50..3afcd4e4d 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -17,8 +17,6 @@ /** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ // eslint-disable-next-line max-len /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ -// eslint-disable-next-line max-len -/** @typedef {import("./struct_tree_builder").StructTreeLayerBuilder} StructTreeLayerBuilder */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ // eslint-disable-next-line max-len /** @typedef {import("./text_layer_builder").TextLayerBuilder} TextLayerBuilder */ @@ -198,16 +196,6 @@ class IPDFXfaLayerFactory { createXfaLayerBuilder({ pageDiv, pdfPage, annotationStorage = null }) {} } -/** - * @interface - */ -class IPDFStructTreeLayerFactory { - /** - * @returns {StructTreeLayerBuilder} - */ - createStructTreeLayerBuilder() {} -} - /** * @interface */ @@ -278,7 +266,6 @@ export { IDownloadManager, IL10n, IPDFLinkService, - IPDFStructTreeLayerFactory, IPDFTextLayerFactory, IPDFXfaLayerFactory, IRenderableView, diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index a3638041b..746e6a633 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -20,8 +20,6 @@ /** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IL10n} IL10n */ // eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ -// eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IRenderableView} IRenderableView */ @@ -53,6 +51,7 @@ import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; import { compatibilityParams } from "./app_options.js"; import { NullL10n } from "./l10n_utils.js"; import { SimpleLinkService } from "./pdf_link_service.js"; +import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextAccessibilityManager } from "./text_accessibility.js"; /** @@ -76,7 +75,6 @@ import { TextAccessibilityManager } from "./text_accessibility.js"; * see also {@link RenderParameters} and {@link GetOperatorListParameters}. * The default value is `AnnotationMode.ENABLE_FORMS`. * @property {IPDFXfaLayerFactory} [xfaLayerFactory] - * @property {IPDFStructTreeLayerFactory} [structTreeLayerFactory] * @property {Object} [textHighlighterFactory] * @property {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. @@ -160,7 +158,6 @@ class PDFPageView { this.textLayerFactory = options.textLayerFactory; this.xfaLayerFactory = options.xfaLayerFactory; this._textHighlighterFactory = options.textHighlighterFactory; - this.structTreeLayerFactory = options.structTreeLayerFactory; if ( typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC") @@ -351,9 +348,7 @@ class PDFPageView { error, }); - if (this.structTreeLayerFactory) { - this.#renderStructTreeLayer(); - } + this.#renderStructTreeLayer(); } /** @@ -367,8 +362,7 @@ class PDFPageView { if (!this.textLayer) { return; } - this.structTreeLayer ||= - this.structTreeLayerFactory.createStructTreeLayerBuilder(); + this.structTreeLayer ||= new StructTreeLayerBuilder(); const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js index cd4ba1fc5..b560e58da 100644 --- a/web/pdf_viewer.component.js +++ b/web/pdf_viewer.component.js @@ -14,7 +14,6 @@ */ import { - DefaultStructTreeLayerFactory, DefaultTextLayerFactory, DefaultXfaLayerFactory, } from "./default_factory.js"; @@ -60,6 +59,15 @@ class DefaultAnnotationLayerFactory { } } +class DefaultStructTreeLayerFactory { + constructor() { + throw new Error( + "The `DefaultStructTreeLayerFactory` has been removed, " + + "this functionality is automatically enabled when the TextLayer is used." + ); + } +} + export { AnnotationLayerBuilder, DefaultAnnotationLayerFactory, diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 481fc01f8..0dfb3e668 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -24,8 +24,6 @@ /** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ // eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ -// eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ // eslint-disable-next-line max-len @@ -69,7 +67,6 @@ import { NullL10n } from "./l10n_utils.js"; import { PDFPageView } from "./pdf_page_view.js"; import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { SimpleLinkService } from "./pdf_link_service.js"; -import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextHighlighter } from "./text_highlighter.js"; import { TextLayerBuilder } from "./text_layer_builder.js"; import { XfaLayerBuilder } from "./xfa_layer_builder.js"; @@ -206,7 +203,6 @@ class PDFPageViewBuffer { /** * Simple viewer control to display PDF content/pages. * - * @implements {IPDFStructTreeLayerFactory} * @implements {IPDFTextLayerFactory} * @implements {IPDFXfaLayerFactory} */ @@ -792,7 +788,6 @@ class PDFViewer { annotationMode, xfaLayerFactory: this, textHighlighterFactory: this, - structTreeLayerFactory: this, imageResourcesPath: this.imageResourcesPath, renderer: typeof PDFJSDev === "undefined" || @@ -1732,13 +1727,6 @@ class PDFViewer { }); } - /** - * @returns {StructTreeLayerBuilder} - */ - createStructTreeLayerBuilder() { - return new StructTreeLayerBuilder(); - } - /** * @type {boolean} Whether all pages of the PDF document have identical * widths and heights. From 4c78290028ff976e392aa046ffaf29a40f9c8e0a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 6 Dec 2022 23:55:23 +0100 Subject: [PATCH 6/9] [api-minor] Remove the `textHighlighterFactory` 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 `textHighlighterFactory` 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. --- web/pdf_page_view.js | 7 ++++--- web/pdf_viewer.js | 25 +++++-------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 746e6a633..af8fdb8a9 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -53,6 +53,7 @@ import { NullL10n } from "./l10n_utils.js"; import { SimpleLinkService } from "./pdf_link_service.js"; import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextAccessibilityManager } from "./text_accessibility.js"; +import { TextHighlighter } from "./text_highlighter.js"; /** * @typedef {Object} PDFPageViewOptions @@ -75,7 +76,6 @@ import { TextAccessibilityManager } from "./text_accessibility.js"; * see also {@link RenderParameters} and {@link GetOperatorListParameters}. * The default value is `AnnotationMode.ENABLE_FORMS`. * @property {IPDFXfaLayerFactory} [xfaLayerFactory] - * @property {Object} [textHighlighterFactory] * @property {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. * @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default @@ -105,6 +105,7 @@ const DEFAULT_LAYER_PROPERTIES = () => { downloadManager: null, enableScripting: false, fieldObjectsPromise: null, + findController: null, hasJSActionsPromise: null, linkService: new SimpleLinkService(), }; @@ -157,7 +158,6 @@ class PDFPageView { this.renderingQueue = options.renderingQueue; this.textLayerFactory = options.textLayerFactory; this.xfaLayerFactory = options.xfaLayerFactory; - this._textHighlighterFactory = options.textHighlighterFactory; if ( typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC") @@ -260,9 +260,10 @@ class PDFPageView { return shadow( this, "_textHighlighter", - this._textHighlighterFactory?.createTextHighlighter({ + new TextHighlighter({ pageIndex: this.id - 1, eventBus: this.eventBus, + findController: this.#layerProperties().findController, }) ); } diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 0dfb3e668..bed0e708a 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -28,6 +28,8 @@ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ // eslint-disable-next-line max-len /** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ +// eslint-disable-next-line max-len +/** @typedef {import("./text_highlighter.js").TextHighlighter} TextHighlighter */ import { AnnotationEditorType, @@ -67,7 +69,6 @@ import { NullL10n } from "./l10n_utils.js"; import { PDFPageView } from "./pdf_page_view.js"; import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { SimpleLinkService } from "./pdf_link_service.js"; -import { TextHighlighter } from "./text_highlighter.js"; import { TextLayerBuilder } from "./text_layer_builder.js"; import { XfaLayerBuilder } from "./xfa_layer_builder.js"; @@ -565,6 +566,9 @@ class PDFViewer { get fieldObjectsPromise() { return self.pdfDocument?.getFieldObjects(); }, + get findController() { + return self.findController; + }, get hasJSActionsPromise() { return self.pdfDocument?.hasJSActions(); }, @@ -787,7 +791,6 @@ class PDFViewer { textLayerMode, annotationMode, xfaLayerFactory: this, - textHighlighterFactory: this, imageResourcesPath: this.imageResourcesPath, renderer: typeof PDFJSDev === "undefined" || @@ -1684,24 +1687,6 @@ class PDFViewer { }); } - /** - * @typedef {Object} CreateTextHighlighterParameters - * @property {number} pageIndex - * @property {EventBus} eventBus - */ - - /** - * @param {CreateTextHighlighterParameters} - * @returns {TextHighlighter} - */ - createTextHighlighter({ pageIndex, eventBus }) { - return new TextHighlighter({ - eventBus, - pageIndex, - findController: this.findController, - }); - } - /** * @typedef {Object} CreateXfaLayerBuilderParameters * @property {HTMLDivElement} pageDiv From c393148748d2d097dfe5bbe7ebefb7fb11b713db Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 7 Dec 2022 00:09:14 +0100 Subject: [PATCH 7/9] [api-minor] Remove the `textLayerFactory` 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 `textLayerFactory` 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. --- web/default_factory.js | 36 +----------------------------------- web/interfaces.js | 28 ---------------------------- web/pdf_page_view.js | 10 +++------- web/pdf_viewer.component.js | 15 +++++++++++---- web/pdf_viewer.js | 33 --------------------------------- 5 files changed, 15 insertions(+), 107 deletions(-) diff --git a/web/default_factory.js b/web/default_factory.js index ae24a5e7c..5b1b6a318 100644 --- a/web/default_factory.js +++ b/web/default_factory.js @@ -20,45 +20,11 @@ /** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ /** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -// eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ -/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ -// eslint-disable-next-line max-len -/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ import { SimpleLinkService } from "./pdf_link_service.js"; -import { TextLayerBuilder } from "./text_layer_builder.js"; import { XfaLayerBuilder } from "./xfa_layer_builder.js"; -/** - * @implements IPDFTextLayerFactory - */ -class DefaultTextLayerFactory { - /** - * @typedef {Object} CreateTextLayerBuilderParameters - * @property {TextHighlighter} highlighter - * @property {TextAccessibilityManager} [accessibilityManager] - * @property {boolean} [isOffscreenCanvasSupported] - */ - - /** - * @param {CreateTextLayerBuilderParameters} - * @returns {TextLayerBuilder} - */ - createTextLayerBuilder({ - highlighter, - accessibilityManager = null, - isOffscreenCanvasSupported = true, - }) { - return new TextLayerBuilder({ - highlighter, - accessibilityManager, - isOffscreenCanvasSupported, - }); - } -} - /** * @implements IPDFXfaLayerFactory */ @@ -85,4 +51,4 @@ class DefaultXfaLayerFactory { } } -export { DefaultTextLayerFactory, DefaultXfaLayerFactory }; +export { DefaultXfaLayerFactory }; diff --git a/web/interfaces.js b/web/interfaces.js index 3afcd4e4d..806fe5efb 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -17,13 +17,8 @@ /** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ // eslint-disable-next-line max-len /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ -/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ -// eslint-disable-next-line max-len -/** @typedef {import("./text_layer_builder").TextLayerBuilder} TextLayerBuilder */ /** @typedef {import("./ui_utils").RenderingStates} RenderingStates */ /** @typedef {import("./xfa_layer_builder").XfaLayerBuilder} XfaLayerBuilder */ -// eslint-disable-next-line max-len -/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ /** * @interface @@ -155,28 +150,6 @@ class IRenderableView { draw() {} } -/** - * @interface - */ -class IPDFTextLayerFactory { - /** - * @typedef {Object} CreateTextLayerBuilderParameters - * @property {TextHighlighter} highlighter - * @property {TextAccessibilityManager} [accessibilityManager] - * @property {boolean} [isOffscreenCanvasSupported] - */ - - /** - * @param {CreateTextLayerBuilderParameters} - * @returns {TextLayerBuilder} - */ - createTextLayerBuilder({ - highlighter, - accessibilityManager, - isOffscreenCanvasSupported, - }) {} -} - /** * @interface */ @@ -266,7 +239,6 @@ export { IDownloadManager, IL10n, IPDFLinkService, - IPDFTextLayerFactory, IPDFXfaLayerFactory, IRenderableView, }; diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index af8fdb8a9..7b12be219 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -19,8 +19,6 @@ /** @typedef {import("../src/display/optional_content_config").OptionalContentConfig} OptionalContentConfig */ /** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IL10n} IL10n */ -// eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IRenderableView} IRenderableView */ // eslint-disable-next-line max-len @@ -54,6 +52,7 @@ import { SimpleLinkService } from "./pdf_link_service.js"; import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextAccessibilityManager } from "./text_accessibility.js"; import { TextHighlighter } from "./text_highlighter.js"; +import { TextLayerBuilder } from "./text_layer_builder.js"; /** * @typedef {Object} PDFPageViewOptions @@ -66,7 +65,6 @@ import { TextHighlighter } from "./text_highlighter.js"; * A promise that is resolved with an {@link OptionalContentConfig} instance. * The default value is `null`. * @property {PDFRenderingQueue} [renderingQueue] - The rendering queue object. - * @property {IPDFTextLayerFactory} [textLayerFactory] * @property {number} [textLayerMode] - Controls if the text layer used for * selection and searching is created. The constants from {TextLayerMode} * should be used. The default value is `TextLayerMode.ENABLE`. @@ -156,7 +154,6 @@ class PDFPageView { this.eventBus = options.eventBus; this.renderingQueue = options.renderingQueue; - this.textLayerFactory = options.textLayerFactory; this.xfaLayerFactory = options.xfaLayerFactory; if ( typeof PDFJSDev === "undefined" || @@ -763,12 +760,11 @@ class PDFPageView { if ( !this.textLayer && this.textLayerMode !== TextLayerMode.DISABLE && - !pdfPage.isPureXfa && - this.textLayerFactory + !pdfPage.isPureXfa ) { this._accessibilityManager ||= new TextAccessibilityManager(); - this.textLayer = this.textLayerFactory.createTextLayerBuilder({ + this.textLayer = new TextLayerBuilder({ highlighter: this._textHighlighter, accessibilityManager: this._accessibilityManager, isOffscreenCanvasSupported: this.isOffscreenCanvasSupported, diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js index b560e58da..3a369ea56 100644 --- a/web/pdf_viewer.component.js +++ b/web/pdf_viewer.component.js @@ -13,10 +13,6 @@ * limitations under the License. */ -import { - DefaultTextLayerFactory, - DefaultXfaLayerFactory, -} from "./default_factory.js"; import { LinkTarget, PDFLinkService, @@ -30,6 +26,7 @@ import { SpreadMode, } from "./ui_utils.js"; import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; +import { DefaultXfaLayerFactory } from "./default_factory.js"; import { DownloadManager } from "./download_manager.js"; import { EventBus } from "./event_utils.js"; import { GenericL10n } from "./genericl10n.js"; @@ -68,6 +65,16 @@ class DefaultStructTreeLayerFactory { } } +class DefaultTextLayerFactory { + constructor() { + throw new Error( + "The `DefaultTextLayerFactory` has been removed, " + + "please use the `textLayerMode` option when initializing " + + "the `PDFPageView`-instance to control TextLayer rendering." + ); + } +} + export { AnnotationLayerBuilder, DefaultAnnotationLayerFactory, diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index bed0e708a..256936881 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -23,13 +23,7 @@ /** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ /** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -// eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ -// eslint-disable-next-line max-len -/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ -// eslint-disable-next-line max-len -/** @typedef {import("./text_highlighter.js").TextHighlighter} TextHighlighter */ import { AnnotationEditorType, @@ -69,7 +63,6 @@ import { NullL10n } from "./l10n_utils.js"; import { PDFPageView } from "./pdf_page_view.js"; import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { SimpleLinkService } from "./pdf_link_service.js"; -import { TextLayerBuilder } from "./text_layer_builder.js"; import { XfaLayerBuilder } from "./xfa_layer_builder.js"; const DEFAULT_CACHE_SIZE = 10; @@ -204,7 +197,6 @@ class PDFPageViewBuffer { /** * Simple viewer control to display PDF content/pages. * - * @implements {IPDFTextLayerFactory} * @implements {IPDFXfaLayerFactory} */ class PDFViewer { @@ -786,8 +778,6 @@ class PDFViewer { defaultViewport: viewport.clone(), optionalContentConfigPromise, renderingQueue: this.renderingQueue, - textLayerFactory: - textLayerMode !== TextLayerMode.DISABLE ? this : null, textLayerMode, annotationMode, xfaLayerFactory: this, @@ -1664,29 +1654,6 @@ class PDFViewer { return false; } - /** - * @typedef {Object} CreateTextLayerBuilderParameters - * @property {TextHighlighter} highlighter - * @property {TextAccessibilityManager} [accessibilityManager] - * @property {boolean} [isOffscreenCanvasSupported] - */ - - /** - * @param {CreateTextLayerBuilderParameters} - * @returns {TextLayerBuilder} - */ - createTextLayerBuilder({ - highlighter, - accessibilityManager = null, - isOffscreenCanvasSupported = true, - }) { - return new TextLayerBuilder({ - highlighter, - accessibilityManager, - isOffscreenCanvasSupported, - }); - } - /** * @typedef {Object} CreateXfaLayerBuilderParameters * @property {HTMLDivElement} pageDiv From 8b8d89006411edacad1af3fc28bbb35ff32fd31f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 7 Dec 2022 00:13:44 +0100 Subject: [PATCH 8/9] [api-minor] Remove the `xfaLayerFactory` 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 `xfaLayerFactory` 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. --- web/default_factory.js | 54 ------------------------------------- web/interfaces.js | 28 +------------------ web/pdf_page_view.js | 20 ++++++++------ web/pdf_viewer.component.js | 11 +++++++- web/pdf_viewer.js | 30 --------------------- 5 files changed, 23 insertions(+), 120 deletions(-) delete mode 100644 web/default_factory.js diff --git a/web/default_factory.js b/web/default_factory.js deleted file mode 100644 index 5b1b6a318..000000000 --- a/web/default_factory.js +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2014 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ -// eslint-disable-next-line max-len -/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ -/** @typedef {import("./event_utils").EventBus} EventBus */ -/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ -/** @typedef {import("./interfaces").IL10n} IL10n */ -/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ - -import { SimpleLinkService } from "./pdf_link_service.js"; -import { XfaLayerBuilder } from "./xfa_layer_builder.js"; - -/** - * @implements IPDFXfaLayerFactory - */ -class DefaultXfaLayerFactory { - /** - * @typedef {Object} CreateXfaLayerBuilderParameters - * @property {HTMLDivElement} pageDiv - * @property {PDFPageProxy} pdfPage - * @property {AnnotationStorage} [annotationStorage] - Storage for annotation - * data in forms. - */ - - /** - * @param {CreateXfaLayerBuilderParameters} - * @returns {XfaLayerBuilder} - */ - createXfaLayerBuilder({ pageDiv, pdfPage, annotationStorage = null }) { - return new XfaLayerBuilder({ - pageDiv, - pdfPage, - annotationStorage, - linkService: new SimpleLinkService(), - }); - } -} - -export { DefaultXfaLayerFactory }; diff --git a/web/interfaces.js b/web/interfaces.js index 806fe5efb..0b6294cb0 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -18,7 +18,6 @@ // eslint-disable-next-line max-len /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ /** @typedef {import("./ui_utils").RenderingStates} RenderingStates */ -/** @typedef {import("./xfa_layer_builder").XfaLayerBuilder} XfaLayerBuilder */ /** * @interface @@ -150,25 +149,6 @@ class IRenderableView { draw() {} } -/** - * @interface - */ -class IPDFXfaLayerFactory { - /** - * @typedef {Object} CreateXfaLayerBuilderParameters - * @property {HTMLDivElement} pageDiv - * @property {PDFPageProxy} pdfPage - * @property {AnnotationStorage} [annotationStorage] - Storage for annotation - * data in forms. - */ - - /** - * @param {CreateXfaLayerBuilderParameters} - * @returns {XfaLayerBuilder} - */ - createXfaLayerBuilder({ pageDiv, pdfPage, annotationStorage = null }) {} -} - /** * @interface */ @@ -235,10 +215,4 @@ class IL10n { async translate(element) {} } -export { - IDownloadManager, - IL10n, - IPDFLinkService, - IPDFXfaLayerFactory, - IRenderableView, -}; +export { IDownloadManager, IL10n, IPDFLinkService, IRenderableView }; diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 7b12be219..0cff72159 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -19,7 +19,6 @@ /** @typedef {import("../src/display/optional_content_config").OptionalContentConfig} OptionalContentConfig */ /** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IL10n} IL10n */ -/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IRenderableView} IRenderableView */ // eslint-disable-next-line max-len /** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ @@ -53,6 +52,7 @@ import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextAccessibilityManager } from "./text_accessibility.js"; import { TextHighlighter } from "./text_highlighter.js"; import { TextLayerBuilder } from "./text_layer_builder.js"; +import { XfaLayerBuilder } from "./xfa_layer_builder.js"; /** * @typedef {Object} PDFPageViewOptions @@ -73,7 +73,6 @@ import { TextLayerBuilder } from "./text_layer_builder.js"; * being rendered. The constants from {@link AnnotationMode} should be used; * see also {@link RenderParameters} and {@link GetOperatorListParameters}. * The default value is `AnnotationMode.ENABLE_FORMS`. - * @property {IPDFXfaLayerFactory} [xfaLayerFactory] * @property {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. * @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default @@ -154,7 +153,6 @@ class PDFPageView { this.eventBus = options.eventBus; this.renderingQueue = options.renderingQueue; - this.xfaLayerFactory = options.xfaLayerFactory; if ( typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC") @@ -902,11 +900,17 @@ class PDFPageView { } ); - if (pdfPage.isPureXfa && this.xfaLayerFactory) { - this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({ - pageDiv: div, - pdfPage, - }); + if (pdfPage.isPureXfa) { + if (!this.xfaLayer) { + const { annotationStorage, linkService } = this.#layerProperties(); + + this.xfaLayer = new XfaLayerBuilder({ + pageDiv: div, + pdfPage, + annotationStorage, + linkService, + }); + } this.#renderXfaLayer(); } diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js index 3a369ea56..eeb9272d5 100644 --- a/web/pdf_viewer.component.js +++ b/web/pdf_viewer.component.js @@ -26,7 +26,6 @@ import { SpreadMode, } from "./ui_utils.js"; import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; -import { DefaultXfaLayerFactory } from "./default_factory.js"; import { DownloadManager } from "./download_manager.js"; import { EventBus } from "./event_utils.js"; import { GenericL10n } from "./genericl10n.js"; @@ -75,6 +74,16 @@ class DefaultTextLayerFactory { } } +class DefaultXfaLayerFactory { + constructor() { + throw new Error( + "The `DefaultXfaLayerFactory` has been removed, " + + "please use the `enableXfa` option when calling " + + "the `getDocument`-function to control XfaLayer rendering." + ); + } +} + export { AnnotationLayerBuilder, DefaultAnnotationLayerFactory, diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 256936881..4de3dd382 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -23,7 +23,6 @@ /** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ /** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ import { AnnotationEditorType, @@ -63,7 +62,6 @@ import { NullL10n } from "./l10n_utils.js"; import { PDFPageView } from "./pdf_page_view.js"; import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { SimpleLinkService } from "./pdf_link_service.js"; -import { XfaLayerBuilder } from "./xfa_layer_builder.js"; const DEFAULT_CACHE_SIZE = 10; const ENABLE_PERMISSIONS_CLASS = "enablePermissions"; @@ -196,8 +194,6 @@ class PDFPageViewBuffer { /** * Simple viewer control to display PDF content/pages. - * - * @implements {IPDFXfaLayerFactory} */ class PDFViewer { #buffer = null; @@ -780,7 +776,6 @@ class PDFViewer { renderingQueue: this.renderingQueue, textLayerMode, annotationMode, - xfaLayerFactory: this, imageResourcesPath: this.imageResourcesPath, renderer: typeof PDFJSDev === "undefined" || @@ -1654,31 +1649,6 @@ class PDFViewer { return false; } - /** - * @typedef {Object} CreateXfaLayerBuilderParameters - * @property {HTMLDivElement} pageDiv - * @property {PDFPageProxy} pdfPage - * @property {AnnotationStorage} [annotationStorage] - Storage for annotation - * data in forms. - */ - - /** - * @param {CreateXfaLayerBuilderParameters} - * @returns {XfaLayerBuilder} - */ - createXfaLayerBuilder({ - pageDiv, - pdfPage, - annotationStorage = this.pdfDocument?.annotationStorage, - }) { - return new XfaLayerBuilder({ - pageDiv, - pdfPage, - annotationStorage, - linkService: this.linkService, - }); - } - /** * @type {boolean} Whether all pages of the PDF document have identical * widths and heights. From d9cdc46f841c752b808655ca2a673ecba759a514 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 7 Dec 2022 12:18:05 +0100 Subject: [PATCH 9/9] Update the "pageviewer" example to account for the previous patches This uses a simple version number check, to prevent breakage if the example is used with older PDF.js versions. --- examples/components/pageviewer.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/components/pageviewer.js b/examples/components/pageviewer.js index b2a6ef22e..01a31161b 100644 --- a/examples/components/pageviewer.js +++ b/examples/components/pageviewer.js @@ -51,6 +51,21 @@ const loadingTask = pdfjsLib.getDocument({ const pdfDocument = await loadingTask.promise; // Document loaded, retrieving the page. const pdfPage = await pdfDocument.getPage(PAGE_TO_VIEW); + + const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(pdfjsLib.version); + if (match && (match[1] | 0) >= 3 && (match[2] | 0) >= 2) { + // Creating the page view with default parameters. + const pdfPageView = new pdfjsViewer.PDFPageView({ + container, + id: PAGE_TO_VIEW, + scale: SCALE, + defaultViewport: pdfPage.getViewport({ scale: SCALE }), + eventBus, + }); + // Associate the actual page with the view, and draw it. + pdfPageView.setPdfPage(pdfPage); + return pdfPageView.draw(); + } // Creating the page view with default parameters. const pdfPageView = new pdfjsViewer.PDFPageView({ container,