1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #16100 from Snuffleupagus/getDocument-canvasFactory

[api-minor] Move the `canvasFactory` option into `getDocument`
This commit is contained in:
Jonas Jenwald 2023-03-01 10:34:11 +01:00 committed by GitHub
commit 9640add1f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 32 deletions

View file

@ -230,6 +230,8 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
* 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()}.
*/
/**
@ -337,6 +339,8 @@ function getDocument(src) {
StandardFontDataFactory === DOMStandardFontDataFactory &&
isValidFetchUrl(cMapUrl, document.baseURI) &&
isValidFetchUrl(standardFontDataUrl, document.baseURI));
const canvasFactory =
src.canvasFactory || new DefaultCanvasFactory({ ownerDocument });
// Parameters only intended for development/testing purposes.
const styleElement =
@ -349,17 +353,18 @@ function getDocument(src) {
// Ensure that the various factories can be initialized, when necessary,
// since the user may provide *custom* ones.
const transportFactory = useWorkerFetch
? null
: {
cMapReaderFactory: new CMapReaderFactory({
baseUrl: cMapUrl,
isCompressed: cMapPacked,
}),
standardFontDataFactory: new StandardFontDataFactory({
baseUrl: standardFontDataUrl,
}),
};
const transportFactory = {
canvasFactory,
};
if (!useWorkerFetch) {
transportFactory.cMapReaderFactory = new CMapReaderFactory({
baseUrl: cMapUrl,
isCompressed: cMapPacked,
});
transportFactory.standardFontDataFactory = new StandardFontDataFactory({
baseUrl: standardFontDataUrl,
});
}
if (!worker) {
const workerParams = {
@ -1280,10 +1285,9 @@ class PDFDocumentProxy {
* Proxy to a `PDFPage` in the worker thread.
*/
class PDFPageProxy {
constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
constructor(pageIndex, pageInfo, transport, pdfBug = false) {
this._pageIndex = pageIndex;
this._pageInfo = pageInfo;
this._ownerDocument = ownerDocument;
this._transport = transport;
this._stats = pdfBug ? new StatTimer() : null;
this._pdfBug = pdfBug;
@ -1414,6 +1418,16 @@ class PDFPageProxy {
pageColors = null,
printAnnotationStorage = null,
}) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
canvasFactory
) {
deprecated(
"render no longer accepts the `canvasFactory`-option, " +
"please pass it to the `getDocument`-function instead."
);
}
this._stats?.time("Overall");
const intentArgs = this._transport.getRenderingIntent(
@ -1441,9 +1455,6 @@ class PDFPageProxy {
intentState.streamReaderCancelTimeout = null;
}
const canvasFactoryInstance =
canvasFactory ||
new DefaultCanvasFactory({ ownerDocument: this._ownerDocument });
const intentPrint = !!(
intentArgs.renderingIntent & RenderingIntentFlag.PRINT
);
@ -1502,7 +1513,7 @@ class PDFPageProxy {
annotationCanvasMap,
operatorList: intentState.operatorList,
pageIndex: this._pageIndex,
canvasFactory: canvasFactoryInstance,
canvasFactory: canvasFactory || this._transport.canvasFactory,
useRequestAnimationFrame: !intentPrint,
pdfBug: this._pdfBug,
pageColors,
@ -2345,8 +2356,9 @@ class WorkerTransport {
});
this._params = params;
this.cMapReaderFactory = factory?.cMapReaderFactory;
this.standardFontDataFactory = factory?.standardFontDataFactory;
this.canvasFactory = factory.canvasFactory;
this.cMapReaderFactory = factory.cMapReaderFactory;
this.standardFontDataFactory = factory.standardFontDataFactory;
this.destroyed = false;
this.destroyCapability = null;
@ -2905,7 +2917,6 @@ class WorkerTransport {
pageIndex,
pageInfo,
this,
this._params.ownerDocument,
this._params.pdfBug
);
this.#pageCache.set(pageIndex, page);