[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.
This commit is contained in:
Jonas Jenwald 2022-12-06 23:55:23 +01:00
parent f1d1f6edfd
commit 4c78290028
2 changed files with 9 additions and 23 deletions

View File

@ -53,6 +53,7 @@ import { NullL10n } from "./l10n_utils.js";
import { SimpleLinkService } from "./pdf_link_service.js"; 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";
/** /**
* @typedef {Object} PDFPageViewOptions * @typedef {Object} PDFPageViewOptions
@ -75,7 +76,6 @@ import { TextAccessibilityManager } from "./text_accessibility.js";
* 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 {IPDFXfaLayerFactory} [xfaLayerFactory]
* @property {Object} [textHighlighterFactory]
* @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
@ -105,6 +105,7 @@ const DEFAULT_LAYER_PROPERTIES = () => {
downloadManager: null, downloadManager: null,
enableScripting: false, enableScripting: false,
fieldObjectsPromise: null, fieldObjectsPromise: null,
findController: null,
hasJSActionsPromise: null, hasJSActionsPromise: null,
linkService: new SimpleLinkService(), linkService: new SimpleLinkService(),
}; };
@ -157,7 +158,6 @@ class PDFPageView {
this.renderingQueue = options.renderingQueue; this.renderingQueue = options.renderingQueue;
this.textLayerFactory = options.textLayerFactory; this.textLayerFactory = options.textLayerFactory;
this.xfaLayerFactory = options.xfaLayerFactory; this.xfaLayerFactory = options.xfaLayerFactory;
this._textHighlighterFactory = options.textHighlighterFactory;
if ( if (
typeof PDFJSDev === "undefined" || typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC") PDFJSDev.test("!PRODUCTION || GENERIC")
@ -260,9 +260,10 @@ class PDFPageView {
return shadow( return shadow(
this, this,
"_textHighlighter", "_textHighlighter",
this._textHighlighterFactory?.createTextHighlighter({ new TextHighlighter({
pageIndex: this.id - 1, pageIndex: this.id - 1,
eventBus: this.eventBus, eventBus: this.eventBus,
findController: this.#layerProperties().findController,
}) })
); );
} }

View File

@ -28,6 +28,8 @@
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ /** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
// eslint-disable-next-line max-len
/** @typedef {import("./text_highlighter.js").TextHighlighter} TextHighlighter */
import { import {
AnnotationEditorType, AnnotationEditorType,
@ -67,7 +69,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 { 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"; import { XfaLayerBuilder } from "./xfa_layer_builder.js";
@ -565,6 +566,9 @@ class PDFViewer {
get fieldObjectsPromise() { get fieldObjectsPromise() {
return self.pdfDocument?.getFieldObjects(); return self.pdfDocument?.getFieldObjects();
}, },
get findController() {
return self.findController;
},
get hasJSActionsPromise() { get hasJSActionsPromise() {
return self.pdfDocument?.hasJSActions(); return self.pdfDocument?.hasJSActions();
}, },
@ -787,7 +791,6 @@ class PDFViewer {
textLayerMode, textLayerMode,
annotationMode, annotationMode,
xfaLayerFactory: this, xfaLayerFactory: this,
textHighlighterFactory: this,
imageResourcesPath: this.imageResourcesPath, imageResourcesPath: this.imageResourcesPath,
renderer: renderer:
typeof PDFJSDev === "undefined" || 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 * @typedef {Object} CreateXfaLayerBuilderParameters
* @property {HTMLDivElement} pageDiv * @property {HTMLDivElement} pageDiv