mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
[api-minor] Pass CanvasFactory
/FilterFactory
, rather than instances, to getDocument
This unifies the various factory-options, since it's consistent with `CMapReaderFactory`/`StandardFontDataFactory`, and ensures that any needed parameters will always be consistently provided when creating `CanvasFactory`/`FilterFactory`-instances. As shown in the modified example this may simplify some custom implementations, since we now provide the ability to access the `CanvasFactory`-instance used with a particular `getDocument`-invocation.
This commit is contained in:
parent
ddd7b63406
commit
bb302dd993
7 changed files with 37 additions and 51 deletions
|
@ -43,6 +43,7 @@ import {
|
|||
SerializableEmpty,
|
||||
} from "./annotation_storage.js";
|
||||
import {
|
||||
deprecated,
|
||||
DOMCanvasFactory,
|
||||
DOMCMapReaderFactory,
|
||||
DOMFilterFactory,
|
||||
|
@ -209,10 +210,11 @@ const DefaultStandardFontDataFactory =
|
|||
* disabling of pre-fetching to work correctly.
|
||||
* @property {boolean} [pdfBug] - Enables special hooks for debugging PDF.js
|
||||
* (see `web/debugger.js`). The default value is `false`.
|
||||
* @property {Object} [canvasFactory] - The factory instance that will be used
|
||||
* when creating canvases. The default value is {new DOMCanvasFactory()}.
|
||||
* @property {Object} [filterFactory] - A factory instance that will be used
|
||||
* to create SVG filters when rendering some images on the main canvas.
|
||||
* @property {Object} [CanvasFactory] - The factory that will be used when
|
||||
* creating canvases. The default value is {DOMCanvasFactory}.
|
||||
* @property {Object} [FilterFactory] - The factory that will be used to
|
||||
* create SVG filters when rendering some images on the main canvas.
|
||||
* The default value is {DOMFilterFactory}.
|
||||
* @property {boolean} [enableHWA] - Enables hardware acceleration for
|
||||
* rendering. The default value is `false`.
|
||||
*/
|
||||
|
@ -291,6 +293,8 @@ function getDocument(src = {}) {
|
|||
const disableStream = src.disableStream === true;
|
||||
const disableAutoFetch = src.disableAutoFetch === true;
|
||||
const pdfBug = src.pdfBug === true;
|
||||
const CanvasFactory = src.CanvasFactory || DefaultCanvasFactory;
|
||||
const FilterFactory = src.FilterFactory || DefaultFilterFactory;
|
||||
const enableHWA = src.enableHWA === true;
|
||||
|
||||
// Parameters whose default values depend on other parameters.
|
||||
|
@ -309,10 +313,19 @@ function getDocument(src = {}) {
|
|||
standardFontDataUrl &&
|
||||
isValidFetchUrl(cMapUrl, document.baseURI) &&
|
||||
isValidFetchUrl(standardFontDataUrl, document.baseURI));
|
||||
const canvasFactory =
|
||||
src.canvasFactory || new DefaultCanvasFactory({ ownerDocument, enableHWA });
|
||||
const filterFactory =
|
||||
src.filterFactory || new DefaultFilterFactory({ docId, ownerDocument });
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
if (src.canvasFactory) {
|
||||
deprecated(
|
||||
"`canvasFactory`-instance option, please use `CanvasFactory` instead."
|
||||
);
|
||||
}
|
||||
if (src.filterFactory) {
|
||||
deprecated(
|
||||
"`filterFactory`-instance option, please use `FilterFactory` instead."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Parameters only intended for development/testing purposes.
|
||||
const styleElement =
|
||||
|
@ -326,8 +339,8 @@ function getDocument(src = {}) {
|
|||
// Ensure that the various factories can be initialized, when necessary,
|
||||
// since the user may provide *custom* ones.
|
||||
const transportFactory = {
|
||||
canvasFactory,
|
||||
filterFactory,
|
||||
canvasFactory: new CanvasFactory({ ownerDocument, enableHWA }),
|
||||
filterFactory: new FilterFactory({ docId, ownerDocument }),
|
||||
};
|
||||
if (!useWorkerFetch) {
|
||||
transportFactory.cMapReaderFactory = new CMapReaderFactory({
|
||||
|
@ -781,6 +794,13 @@ class PDFDocumentProxy {
|
|||
return this._transport.annotationStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Object} The canvas factory instance.
|
||||
*/
|
||||
get canvasFactory() {
|
||||
return this._transport.canvasFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Object} The filter factory instance.
|
||||
*/
|
||||
|
|
|
@ -51,7 +51,7 @@ class BaseFilterFactory {
|
|||
class BaseCanvasFactory {
|
||||
#enableHWA = false;
|
||||
|
||||
constructor({ enableHWA = false } = {}) {
|
||||
constructor({ enableHWA = false }) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||
this.constructor === BaseCanvasFactory
|
||||
|
|
|
@ -63,7 +63,7 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
|
||||
#id = 0;
|
||||
|
||||
constructor({ docId, ownerDocument = globalThis.document } = {}) {
|
||||
constructor({ docId, ownerDocument = globalThis.document }) {
|
||||
super();
|
||||
this.#docId = docId;
|
||||
this.#document = ownerDocument;
|
||||
|
@ -496,7 +496,7 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
}
|
||||
|
||||
class DOMCanvasFactory extends BaseCanvasFactory {
|
||||
constructor({ ownerDocument = globalThis.document, enableHWA = false } = {}) {
|
||||
constructor({ ownerDocument = globalThis.document, enableHWA = false }) {
|
||||
super({ enableHWA });
|
||||
this._document = ownerDocument;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue