[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.
This commit is contained in:
Jonas Jenwald 2022-12-06 23:43:09 +01:00
parent ca69da735e
commit f1d1f6edfd
5 changed files with 13 additions and 55 deletions

View File

@ -21,8 +21,6 @@
/** @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 // 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").IPDFTextLayerFactory} IPDFTextLayerFactory */
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */
@ -30,22 +28,9 @@
/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ /** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
import { SimpleLinkService } from "./pdf_link_service.js"; import { SimpleLinkService } from "./pdf_link_service.js";
import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.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";
/**
* @implements IPDFStructTreeLayerFactory
*/
class DefaultStructTreeLayerFactory {
/**
* @returns {StructTreeLayerBuilder}
*/
createStructTreeLayerBuilder() {
return new StructTreeLayerBuilder();
}
}
/** /**
* @implements IPDFTextLayerFactory * @implements IPDFTextLayerFactory
*/ */
@ -100,8 +85,4 @@ class DefaultXfaLayerFactory {
} }
} }
export { export { DefaultTextLayerFactory, DefaultXfaLayerFactory };
DefaultStructTreeLayerFactory,
DefaultTextLayerFactory,
DefaultXfaLayerFactory,
};

View File

@ -17,8 +17,6 @@
/** @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 */
// eslint-disable-next-line max-len
/** @typedef {import("./struct_tree_builder").StructTreeLayerBuilder} StructTreeLayerBuilder */
/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
/** @typedef {import("./text_layer_builder").TextLayerBuilder} TextLayerBuilder */ /** @typedef {import("./text_layer_builder").TextLayerBuilder} TextLayerBuilder */
@ -198,16 +196,6 @@ class IPDFXfaLayerFactory {
createXfaLayerBuilder({ pageDiv, pdfPage, annotationStorage = null }) {} createXfaLayerBuilder({ pageDiv, pdfPage, annotationStorage = null }) {}
} }
/**
* @interface
*/
class IPDFStructTreeLayerFactory {
/**
* @returns {StructTreeLayerBuilder}
*/
createStructTreeLayerBuilder() {}
}
/** /**
* @interface * @interface
*/ */
@ -278,7 +266,6 @@ export {
IDownloadManager, IDownloadManager,
IL10n, IL10n,
IPDFLinkService, IPDFLinkService,
IPDFStructTreeLayerFactory,
IPDFTextLayerFactory, IPDFTextLayerFactory,
IPDFXfaLayerFactory, IPDFXfaLayerFactory,
IRenderableView, IRenderableView,

View File

@ -20,8 +20,6 @@
/** @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 // 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").IPDFTextLayerFactory} IPDFTextLayerFactory */
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
/** @typedef {import("./interfaces").IRenderableView} IRenderableView */ /** @typedef {import("./interfaces").IRenderableView} IRenderableView */
@ -53,6 +51,7 @@ import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
import { compatibilityParams } from "./app_options.js"; import { compatibilityParams } from "./app_options.js";
import { NullL10n } from "./l10n_utils.js"; 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 { TextAccessibilityManager } from "./text_accessibility.js"; import { TextAccessibilityManager } from "./text_accessibility.js";
/** /**
@ -76,7 +75,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 {IPDFStructTreeLayerFactory} [structTreeLayerFactory]
* @property {Object} [textHighlighterFactory] * @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.
@ -160,7 +158,6 @@ class PDFPageView {
this.textLayerFactory = options.textLayerFactory; this.textLayerFactory = options.textLayerFactory;
this.xfaLayerFactory = options.xfaLayerFactory; this.xfaLayerFactory = options.xfaLayerFactory;
this._textHighlighterFactory = options.textHighlighterFactory; this._textHighlighterFactory = options.textHighlighterFactory;
this.structTreeLayerFactory = options.structTreeLayerFactory;
if ( if (
typeof PDFJSDev === "undefined" || typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC") PDFJSDev.test("!PRODUCTION || GENERIC")
@ -351,9 +348,7 @@ class PDFPageView {
error, error,
}); });
if (this.structTreeLayerFactory) { this.#renderStructTreeLayer();
this.#renderStructTreeLayer();
}
} }
/** /**
@ -367,8 +362,7 @@ class PDFPageView {
if (!this.textLayer) { if (!this.textLayer) {
return; return;
} }
this.structTreeLayer ||= this.structTreeLayer ||= new StructTreeLayerBuilder();
this.structTreeLayerFactory.createStructTreeLayerBuilder();
const tree = await (!this.structTreeLayer.renderingDone const tree = await (!this.structTreeLayer.renderingDone
? this.pdfPage.getStructTree() ? this.pdfPage.getStructTree()

View File

@ -14,7 +14,6 @@
*/ */
import { import {
DefaultStructTreeLayerFactory,
DefaultTextLayerFactory, DefaultTextLayerFactory,
DefaultXfaLayerFactory, DefaultXfaLayerFactory,
} from "./default_factory.js"; } 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 { export {
AnnotationLayerBuilder, AnnotationLayerBuilder,
DefaultAnnotationLayerFactory, DefaultAnnotationLayerFactory,

View File

@ -24,8 +24,6 @@
/** @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 // 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").IPDFTextLayerFactory} IPDFTextLayerFactory */
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
@ -69,7 +67,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 { StructTreeLayerBuilder } from "./struct_tree_layer_builder.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"; import { XfaLayerBuilder } from "./xfa_layer_builder.js";
@ -206,7 +203,6 @@ class PDFPageViewBuffer {
/** /**
* Simple viewer control to display PDF content/pages. * Simple viewer control to display PDF content/pages.
* *
* @implements {IPDFStructTreeLayerFactory}
* @implements {IPDFTextLayerFactory} * @implements {IPDFTextLayerFactory}
* @implements {IPDFXfaLayerFactory} * @implements {IPDFXfaLayerFactory}
*/ */
@ -792,7 +788,6 @@ class PDFViewer {
annotationMode, annotationMode,
xfaLayerFactory: this, xfaLayerFactory: this,
textHighlighterFactory: this, textHighlighterFactory: this,
structTreeLayerFactory: this,
imageResourcesPath: this.imageResourcesPath, imageResourcesPath: this.imageResourcesPath,
renderer: renderer:
typeof PDFJSDev === "undefined" || 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 * @type {boolean} Whether all pages of the PDF document have identical
* widths and heights. * widths and heights.