[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.
This commit is contained in:
parent
4c78290028
commit
c393148748
@ -20,45 +20,11 @@
|
|||||||
/** @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 */
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */
|
|
||||||
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
|
/** @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 { SimpleLinkService } from "./pdf_link_service.js";
|
||||||
import { TextLayerBuilder } from "./text_layer_builder.js";
|
|
||||||
import { XfaLayerBuilder } from "./xfa_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
|
* @implements IPDFXfaLayerFactory
|
||||||
*/
|
*/
|
||||||
@ -85,4 +51,4 @@ class DefaultXfaLayerFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { DefaultTextLayerFactory, DefaultXfaLayerFactory };
|
export { DefaultXfaLayerFactory };
|
||||||
|
@ -17,13 +17,8 @@
|
|||||||
/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */
|
/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */
|
||||||
// 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("./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("./ui_utils").RenderingStates} RenderingStates */
|
||||||
/** @typedef {import("./xfa_layer_builder").XfaLayerBuilder} XfaLayerBuilder */
|
/** @typedef {import("./xfa_layer_builder").XfaLayerBuilder} XfaLayerBuilder */
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
@ -155,28 +150,6 @@ class IRenderableView {
|
|||||||
draw() {}
|
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
|
* @interface
|
||||||
*/
|
*/
|
||||||
@ -266,7 +239,6 @@ export {
|
|||||||
IDownloadManager,
|
IDownloadManager,
|
||||||
IL10n,
|
IL10n,
|
||||||
IPDFLinkService,
|
IPDFLinkService,
|
||||||
IPDFTextLayerFactory,
|
|
||||||
IPDFXfaLayerFactory,
|
IPDFXfaLayerFactory,
|
||||||
IRenderableView,
|
IRenderableView,
|
||||||
};
|
};
|
||||||
|
@ -19,8 +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 */
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */
|
|
||||||
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
|
/** @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
|
||||||
@ -54,6 +52,7 @@ import { SimpleLinkService } from "./pdf_link_service.js";
|
|||||||
import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
|
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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFPageViewOptions
|
* @typedef {Object} PDFPageViewOptions
|
||||||
@ -66,7 +65,6 @@ import { TextHighlighter } from "./text_highlighter.js";
|
|||||||
* A promise that is resolved with an {@link OptionalContentConfig} instance.
|
* A promise that is resolved with an {@link OptionalContentConfig} instance.
|
||||||
* The default value is `null`.
|
* The default value is `null`.
|
||||||
* @property {PDFRenderingQueue} [renderingQueue] - The rendering queue object.
|
* @property {PDFRenderingQueue} [renderingQueue] - The rendering queue object.
|
||||||
* @property {IPDFTextLayerFactory} [textLayerFactory]
|
|
||||||
* @property {number} [textLayerMode] - Controls if the text layer used for
|
* @property {number} [textLayerMode] - Controls if the text layer used for
|
||||||
* selection and searching is created. The constants from {TextLayerMode}
|
* selection and searching is created. The constants from {TextLayerMode}
|
||||||
* should be used. The default value is `TextLayerMode.ENABLE`.
|
* should be used. The default value is `TextLayerMode.ENABLE`.
|
||||||
@ -156,7 +154,6 @@ class PDFPageView {
|
|||||||
|
|
||||||
this.eventBus = options.eventBus;
|
this.eventBus = options.eventBus;
|
||||||
this.renderingQueue = options.renderingQueue;
|
this.renderingQueue = options.renderingQueue;
|
||||||
this.textLayerFactory = options.textLayerFactory;
|
|
||||||
this.xfaLayerFactory = options.xfaLayerFactory;
|
this.xfaLayerFactory = options.xfaLayerFactory;
|
||||||
if (
|
if (
|
||||||
typeof PDFJSDev === "undefined" ||
|
typeof PDFJSDev === "undefined" ||
|
||||||
@ -763,12 +760,11 @@ class PDFPageView {
|
|||||||
if (
|
if (
|
||||||
!this.textLayer &&
|
!this.textLayer &&
|
||||||
this.textLayerMode !== TextLayerMode.DISABLE &&
|
this.textLayerMode !== TextLayerMode.DISABLE &&
|
||||||
!pdfPage.isPureXfa &&
|
!pdfPage.isPureXfa
|
||||||
this.textLayerFactory
|
|
||||||
) {
|
) {
|
||||||
this._accessibilityManager ||= new TextAccessibilityManager();
|
this._accessibilityManager ||= new TextAccessibilityManager();
|
||||||
|
|
||||||
this.textLayer = this.textLayerFactory.createTextLayerBuilder({
|
this.textLayer = new TextLayerBuilder({
|
||||||
highlighter: this._textHighlighter,
|
highlighter: this._textHighlighter,
|
||||||
accessibilityManager: this._accessibilityManager,
|
accessibilityManager: this._accessibilityManager,
|
||||||
isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
||||||
|
@ -13,10 +13,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
|
||||||
DefaultTextLayerFactory,
|
|
||||||
DefaultXfaLayerFactory,
|
|
||||||
} from "./default_factory.js";
|
|
||||||
import {
|
import {
|
||||||
LinkTarget,
|
LinkTarget,
|
||||||
PDFLinkService,
|
PDFLinkService,
|
||||||
@ -30,6 +26,7 @@ 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";
|
||||||
@ -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 {
|
export {
|
||||||
AnnotationLayerBuilder,
|
AnnotationLayerBuilder,
|
||||||
DefaultAnnotationLayerFactory,
|
DefaultAnnotationLayerFactory,
|
||||||
|
@ -23,13 +23,7 @@
|
|||||||
/** @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 */
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */
|
|
||||||
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
|
/** @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 {
|
import {
|
||||||
AnnotationEditorType,
|
AnnotationEditorType,
|
||||||
@ -69,7 +63,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 { TextLayerBuilder } from "./text_layer_builder.js";
|
|
||||||
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
|
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
|
||||||
|
|
||||||
const DEFAULT_CACHE_SIZE = 10;
|
const DEFAULT_CACHE_SIZE = 10;
|
||||||
@ -204,7 +197,6 @@ class PDFPageViewBuffer {
|
|||||||
/**
|
/**
|
||||||
* Simple viewer control to display PDF content/pages.
|
* Simple viewer control to display PDF content/pages.
|
||||||
*
|
*
|
||||||
* @implements {IPDFTextLayerFactory}
|
|
||||||
* @implements {IPDFXfaLayerFactory}
|
* @implements {IPDFXfaLayerFactory}
|
||||||
*/
|
*/
|
||||||
class PDFViewer {
|
class PDFViewer {
|
||||||
@ -786,8 +778,6 @@ class PDFViewer {
|
|||||||
defaultViewport: viewport.clone(),
|
defaultViewport: viewport.clone(),
|
||||||
optionalContentConfigPromise,
|
optionalContentConfigPromise,
|
||||||
renderingQueue: this.renderingQueue,
|
renderingQueue: this.renderingQueue,
|
||||||
textLayerFactory:
|
|
||||||
textLayerMode !== TextLayerMode.DISABLE ? this : null,
|
|
||||||
textLayerMode,
|
textLayerMode,
|
||||||
annotationMode,
|
annotationMode,
|
||||||
xfaLayerFactory: this,
|
xfaLayerFactory: this,
|
||||||
@ -1664,29 +1654,6 @@ class PDFViewer {
|
|||||||
return false;
|
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
|
* @typedef {Object} CreateXfaLayerBuilderParameters
|
||||||
* @property {HTMLDivElement} pageDiv
|
* @property {HTMLDivElement} pageDiv
|
||||||
|
Loading…
x
Reference in New Issue
Block a user