mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
[api-minor] Use the NodeCanvasFactory
/NodeCMapReaderFactory
classes as defaults in Node.js environments (issue 11900)
This moves, and slightly simplifies, code that's currently residing in the unit-test utils into the actual library, such that it's bundled with `GENERIC`-builds and used in e.g. the API-code. As an added bonus, this also brings out-of-the-box support for CMaps in e.g. the Node.js examples.
This commit is contained in:
parent
fe3df495cc
commit
4a7e29865d
10 changed files with 164 additions and 123 deletions
|
@ -47,6 +47,7 @@ import {
|
|||
StatTimer,
|
||||
} from "./display_utils.js";
|
||||
import { FontFaceObject, FontLoader } from "./font_loader.js";
|
||||
import { NodeCanvasFactory, NodeCMapReaderFactory } from "./node_utils.js";
|
||||
import { apiCompatibilityParams } from "./api_compatibility.js";
|
||||
import { CanvasGraphics } from "./canvas.js";
|
||||
import { GlobalWorkerOptions } from "./worker_options.js";
|
||||
|
@ -59,6 +60,15 @@ import { WebGLContext } from "./webgl.js";
|
|||
const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
||||
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
||||
|
||||
const DefaultCanvasFactory =
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
||||
? NodeCanvasFactory
|
||||
: DOMCanvasFactory;
|
||||
const DefaultCMapReaderFactory =
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
||||
? NodeCMapReaderFactory
|
||||
: DOMCMapReaderFactory;
|
||||
|
||||
/**
|
||||
* @typedef {function} IPDFStreamFactory
|
||||
* @param {DocumentInitParameters} params - The document initialization
|
||||
|
@ -242,7 +252,8 @@ function getDocument(src) {
|
|||
}
|
||||
|
||||
params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
|
||||
params.CMapReaderFactory = params.CMapReaderFactory || DOMCMapReaderFactory;
|
||||
params.CMapReaderFactory =
|
||||
params.CMapReaderFactory || DefaultCMapReaderFactory;
|
||||
params.ignoreErrors = params.stopAtErrors !== true;
|
||||
params.fontExtraProperties = params.fontExtraProperties === true;
|
||||
params.pdfBug = params.pdfBug === true;
|
||||
|
@ -863,9 +874,9 @@ class PDFDocumentProxy {
|
|||
* just before viewport transform.
|
||||
* @property {Object} [imageLayer] - An object that has beginLayout,
|
||||
* endLayout and appendImage functions.
|
||||
* @property {Object} [canvasFactory] - The factory that will be used
|
||||
* @property {Object} [canvasFactory] - The factory instance that will be used
|
||||
* when creating canvases. The default value is
|
||||
* {DOMCanvasFactory}.
|
||||
* {new DOMCanvasFactory()}.
|
||||
* @property {Object} [background] - Background to use for the canvas.
|
||||
* Can use any valid canvas.fillStyle: A DOMString parsed as
|
||||
* CSS <color> value, a CanvasGradient object (a linear or
|
||||
|
@ -1015,7 +1026,7 @@ class PDFPageProxy {
|
|||
intentState.streamReaderCancelTimeout = null;
|
||||
}
|
||||
|
||||
const canvasFactoryInstance = canvasFactory || new DOMCanvasFactory();
|
||||
const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory();
|
||||
const webGLContext = new WebGLContext({
|
||||
enable: enableWebGL,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue