[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.
This commit is contained in:
parent
c393148748
commit
8b8d890064
@ -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 };
|
|
@ -18,7 +18,6 @@
|
|||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
|
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
|
||||||
/** @typedef {import("./ui_utils").RenderingStates} RenderingStates */
|
/** @typedef {import("./ui_utils").RenderingStates} RenderingStates */
|
||||||
/** @typedef {import("./xfa_layer_builder").XfaLayerBuilder} XfaLayerBuilder */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
@ -150,25 +149,6 @@ class IRenderableView {
|
|||||||
draw() {}
|
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
|
* @interface
|
||||||
*/
|
*/
|
||||||
@ -235,10 +215,4 @@ class IL10n {
|
|||||||
async translate(element) {}
|
async translate(element) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export { IDownloadManager, IL10n, IPDFLinkService, IRenderableView };
|
||||||
IDownloadManager,
|
|
||||||
IL10n,
|
|
||||||
IPDFLinkService,
|
|
||||||
IPDFXfaLayerFactory,
|
|
||||||
IRenderableView,
|
|
||||||
};
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
/** @typedef {import("../src/display/optional_content_config").OptionalContentConfig} OptionalContentConfig */
|
/** @typedef {import("../src/display/optional_content_config").OptionalContentConfig} OptionalContentConfig */
|
||||||
/** @typedef {import("./event_utils").EventBus} EventBus */
|
/** @typedef {import("./event_utils").EventBus} EventBus */
|
||||||
/** @typedef {import("./interfaces").IL10n} IL10n */
|
/** @typedef {import("./interfaces").IL10n} IL10n */
|
||||||
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
|
|
||||||
/** @typedef {import("./interfaces").IRenderableView} IRenderableView */
|
/** @typedef {import("./interfaces").IRenderableView} IRenderableView */
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */
|
/** @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 { TextAccessibilityManager } from "./text_accessibility.js";
|
||||||
import { TextHighlighter } from "./text_highlighter.js";
|
import { TextHighlighter } from "./text_highlighter.js";
|
||||||
import { TextLayerBuilder } from "./text_layer_builder.js";
|
import { TextLayerBuilder } from "./text_layer_builder.js";
|
||||||
|
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFPageViewOptions
|
* @typedef {Object} PDFPageViewOptions
|
||||||
@ -73,7 +73,6 @@ import { TextLayerBuilder } from "./text_layer_builder.js";
|
|||||||
* being rendered. The constants from {@link AnnotationMode} should be used;
|
* being rendered. The constants from {@link AnnotationMode} should be used;
|
||||||
* see also {@link RenderParameters} and {@link GetOperatorListParameters}.
|
* see also {@link RenderParameters} and {@link GetOperatorListParameters}.
|
||||||
* The default value is `AnnotationMode.ENABLE_FORMS`.
|
* The default value is `AnnotationMode.ENABLE_FORMS`.
|
||||||
* @property {IPDFXfaLayerFactory} [xfaLayerFactory]
|
|
||||||
* @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} [useOnlyCssZoom] - Enables CSS only zooming. The default
|
* @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default
|
||||||
@ -154,7 +153,6 @@ class PDFPageView {
|
|||||||
|
|
||||||
this.eventBus = options.eventBus;
|
this.eventBus = options.eventBus;
|
||||||
this.renderingQueue = options.renderingQueue;
|
this.renderingQueue = options.renderingQueue;
|
||||||
this.xfaLayerFactory = options.xfaLayerFactory;
|
|
||||||
if (
|
if (
|
||||||
typeof PDFJSDev === "undefined" ||
|
typeof PDFJSDev === "undefined" ||
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||||
@ -902,11 +900,17 @@ class PDFPageView {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pdfPage.isPureXfa && this.xfaLayerFactory) {
|
if (pdfPage.isPureXfa) {
|
||||||
this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({
|
if (!this.xfaLayer) {
|
||||||
pageDiv: div,
|
const { annotationStorage, linkService } = this.#layerProperties();
|
||||||
pdfPage,
|
|
||||||
});
|
this.xfaLayer = new XfaLayerBuilder({
|
||||||
|
pageDiv: div,
|
||||||
|
pdfPage,
|
||||||
|
annotationStorage,
|
||||||
|
linkService,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.#renderXfaLayer();
|
this.#renderXfaLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import {
|
|||||||
SpreadMode,
|
SpreadMode,
|
||||||
} from "./ui_utils.js";
|
} from "./ui_utils.js";
|
||||||
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
|
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
|
||||||
import { DefaultXfaLayerFactory } from "./default_factory.js";
|
|
||||||
import { DownloadManager } from "./download_manager.js";
|
import { DownloadManager } from "./download_manager.js";
|
||||||
import { EventBus } from "./event_utils.js";
|
import { EventBus } from "./event_utils.js";
|
||||||
import { GenericL10n } from "./genericl10n.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 {
|
export {
|
||||||
AnnotationLayerBuilder,
|
AnnotationLayerBuilder,
|
||||||
DefaultAnnotationLayerFactory,
|
DefaultAnnotationLayerFactory,
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
|
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
|
||||||
/** @typedef {import("./interfaces").IL10n} IL10n */
|
/** @typedef {import("./interfaces").IL10n} IL10n */
|
||||||
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
||||||
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AnnotationEditorType,
|
AnnotationEditorType,
|
||||||
@ -63,7 +62,6 @@ import { NullL10n } from "./l10n_utils.js";
|
|||||||
import { PDFPageView } from "./pdf_page_view.js";
|
import { PDFPageView } from "./pdf_page_view.js";
|
||||||
import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
|
import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
|
||||||
import { SimpleLinkService } from "./pdf_link_service.js";
|
import { SimpleLinkService } from "./pdf_link_service.js";
|
||||||
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
|
|
||||||
|
|
||||||
const DEFAULT_CACHE_SIZE = 10;
|
const DEFAULT_CACHE_SIZE = 10;
|
||||||
const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
|
const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
|
||||||
@ -196,8 +194,6 @@ class PDFPageViewBuffer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple viewer control to display PDF content/pages.
|
* Simple viewer control to display PDF content/pages.
|
||||||
*
|
|
||||||
* @implements {IPDFXfaLayerFactory}
|
|
||||||
*/
|
*/
|
||||||
class PDFViewer {
|
class PDFViewer {
|
||||||
#buffer = null;
|
#buffer = null;
|
||||||
@ -780,7 +776,6 @@ class PDFViewer {
|
|||||||
renderingQueue: this.renderingQueue,
|
renderingQueue: this.renderingQueue,
|
||||||
textLayerMode,
|
textLayerMode,
|
||||||
annotationMode,
|
annotationMode,
|
||||||
xfaLayerFactory: this,
|
|
||||||
imageResourcesPath: this.imageResourcesPath,
|
imageResourcesPath: this.imageResourcesPath,
|
||||||
renderer:
|
renderer:
|
||||||
typeof PDFJSDev === "undefined" ||
|
typeof PDFJSDev === "undefined" ||
|
||||||
@ -1654,31 +1649,6 @@ class PDFViewer {
|
|||||||
return false;
|
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
|
* @type {boolean} Whether all pages of the PDF document have identical
|
||||||
* widths and heights.
|
* widths and heights.
|
||||||
|
Loading…
Reference in New Issue
Block a user