@@ -66,18 +66,14 @@ import {
6666} from "./api_utils.js" ;
6767import { MessageHandler , wrapReason } from "../shared/message_handler.js" ;
6868import {
69+ NodeBinaryDataFactory ,
6970 NodeCanvasFactory ,
70- NodeCMapReaderFactory ,
7171 NodeFilterFactory ,
72- NodeStandardFontDataFactory ,
73- NodeWasmFactory ,
7472} from "display-node_utils" ;
7573import { CanvasGraphics } from "./canvas.js" ;
74+ import { DOMBinaryDataFactory } from "display-binary_data_factory" ;
7675import { DOMCanvasFactory } from "./canvas_factory.js" ;
77- import { DOMCMapReaderFactory } from "display-cmap_reader_factory" ;
7876import { DOMFilterFactory } from "./filter_factory.js" ;
79- import { DOMStandardFontDataFactory } from "display-standard_fontdata_factory" ;
80- import { DOMWasmFactory } from "display-wasm_factory" ;
8177import { GlobalWorkerOptions } from "./worker_options.js" ;
8278import { initWebGPUMesh } from "./webgpu_mesh.js" ;
8379import { Metadata } from "./metadata.js" ;
@@ -140,9 +136,6 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
140136 * located. Include the trailing slash.
141137 * @property {boolean } [cMapPacked] - Specifies if the Adobe CMaps are binary
142138 * packed or not. The default value is `true`.
143- * @property {Object } [CMapReaderFactory] - The factory that will be used when
144- * reading built-in CMap files.
145- * The default value is {DOMCMapReaderFactory}.
146139 * @property {string } [iccUrl] - The URL where the predefined ICC profiles are
147140 * located. Include the trailing slash.
148141 * @property {boolean } [useSystemFonts] - When `true`, fonts that aren't
@@ -152,18 +145,11 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
152145 * regardless of the environment (to prevent completely broken fonts).
153146 * @property {string } [standardFontDataUrl] - The URL where the standard font
154147 * files are located. Include the trailing slash.
155- * @property {Object } [StandardFontDataFactory] - The factory that will be used
156- * when reading the standard font files.
157- * The default value is {DOMStandardFontDataFactory}.
158148 * @property {string } [wasmUrl] - The URL where the wasm files are located.
159149 * Include the trailing slash.
160- * @property {Object } [WasmFactory] - The factory that will be used
161- * when reading the wasm files.
162- * The default value is {DOMWasmFactory}.
163150 * @property {boolean } [useWorkerFetch] - Enable using the Fetch API in the
164- * worker-thread when reading CMap and standard font files. When `true`,
165- * the `CMapReaderFactory`, `StandardFontDataFactory`, and `WasmFactory`
166- * options are ignored.
151+ * worker-thread when reading built-in CMap files, standard font files,
152+ * and wasm files. If `true`, the `BinaryDataFactory` option is ignored.
167153 * The default value is `true` in web environments and `false` in Node.js.
168154 * @property {boolean } [useWasm] - Attempt to use WebAssembly in order to
169155 * improve e.g. image decoding performance.
@@ -235,6 +221,10 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
235221 * @property {Object } [FilterFactory] - The factory that will be used to
236222 * create SVG filters when rendering some images on the main canvas.
237223 * The default value is {DOMFilterFactory}.
224+ * @property {Object } [BinaryDataFactory] - The factory that will be used when
225+ * falling back to reading built-in CMap files, standard font files,
226+ * and wasm files in the main-thread.
227+ * The default value is {DOMBinaryDataFactory}.
238228 * @property {boolean } [enableHWA] - Enables hardware acceleration for
239229 * rendering. The default value is `false`.
240230 * @property {Object } [pagesMapper] - The pages mapper that will be used to map
@@ -287,24 +277,9 @@ function getDocument(src = {}) {
287277 : null ;
288278 const cMapUrl = getFactoryUrlProp ( src . cMapUrl ) ;
289279 const cMapPacked = src . cMapPacked !== false ;
290- const CMapReaderFactory =
291- src . CMapReaderFactory ||
292- ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "GENERIC" ) && isNodeJS
293- ? NodeCMapReaderFactory
294- : DOMCMapReaderFactory ) ;
295280 const iccUrl = getFactoryUrlProp ( src . iccUrl ) ;
296281 const standardFontDataUrl = getFactoryUrlProp ( src . standardFontDataUrl ) ;
297- const StandardFontDataFactory =
298- src . StandardFontDataFactory ||
299- ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "GENERIC" ) && isNodeJS
300- ? NodeStandardFontDataFactory
301- : DOMStandardFontDataFactory ) ;
302282 const wasmUrl = getFactoryUrlProp ( src . wasmUrl ) ;
303- const WasmFactory =
304- src . WasmFactory ||
305- ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "GENERIC" ) && isNodeJS
306- ? NodeWasmFactory
307- : DOMWasmFactory ) ;
308283 const ignoreErrors = src . stopAtErrors !== true ;
309284 const maxImageSize =
310285 Number . isInteger ( src . maxImageSize ) && src . maxImageSize > - 1
@@ -347,6 +322,11 @@ function getDocument(src = {}) {
347322 ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "GENERIC" ) && isNodeJS
348323 ? NodeFilterFactory
349324 : DOMFilterFactory ) ;
325+ const BinaryDataFactory =
326+ src . BinaryDataFactory ||
327+ ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "GENERIC" ) && isNodeJS
328+ ? NodeBinaryDataFactory
329+ : DOMBinaryDataFactory ) ;
350330 const enableHWA = src . enableHWA === true ;
351331 const enableWebGPU = src . enableWebGPU === true ;
352332 const useWasm = src . useWasm !== false ;
@@ -362,9 +342,7 @@ function getDocument(src = {}) {
362342 ? src . useWorkerFetch
363343 : ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "MOZCENTRAL" ) ) ||
364344 ! ! (
365- CMapReaderFactory === DOMCMapReaderFactory &&
366- StandardFontDataFactory === DOMStandardFontDataFactory &&
367- WasmFactory === DOMWasmFactory &&
345+ BinaryDataFactory === DOMBinaryDataFactory &&
368346 cMapUrl &&
369347 cMapPacked &&
370348 standardFontDataUrl &&
@@ -388,21 +366,11 @@ function getDocument(src = {}) {
388366 const transportFactory = {
389367 canvasFactory : new CanvasFactory ( { ownerDocument, enableHWA } ) ,
390368 filterFactory : new FilterFactory ( { docId, ownerDocument } ) ,
391- cMapReaderFactory :
369+ binaryDataFactory :
392370 ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "MOZCENTRAL" ) ) ||
393371 useWorkerFetch
394372 ? null
395- : new CMapReaderFactory ( { baseUrl : cMapUrl } ) ,
396- standardFontDataFactory :
397- ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "MOZCENTRAL" ) ) ||
398- useWorkerFetch
399- ? null
400- : new StandardFontDataFactory ( { baseUrl : standardFontDataUrl } ) ,
401- wasmFactory :
402- ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "MOZCENTRAL" ) ) ||
403- useWorkerFetch
404- ? null
405- : new WasmFactory ( { baseUrl : wasmUrl } ) ,
373+ : new BinaryDataFactory ( { cMapUrl, standardFontDataUrl, wasmUrl } ) ,
406374 } ;
407375
408376 if ( ! worker ) {
@@ -2474,9 +2442,7 @@ class WorkerTransport {
24742442 this . canvasFactory = factory . canvasFactory ;
24752443 this . filterFactory = factory . filterFactory ;
24762444 if ( typeof PDFJSDev === "undefined" || ! PDFJSDev . test ( "MOZCENTRAL" ) ) {
2477- this . cMapReaderFactory = factory . cMapReaderFactory ;
2478- this . standardFontDataFactory = factory . standardFontDataFactory ;
2479- this . wasmFactory = factory . wasmFactory ;
2445+ this . binaryDataFactory = factory . binaryDataFactory ;
24802446 }
24812447 this . pagesMapper = pagesMapper ;
24822448
@@ -2943,14 +2909,12 @@ class WorkerTransport {
29432909 if ( this . destroyed ) {
29442910 throw new Error ( "Worker was destroyed." ) ;
29452911 }
2946- const factory = this [ data . type ] ;
2947-
2948- if ( ! factory ) {
2912+ if ( ! this . binaryDataFactory ) {
29492913 throw new Error (
2950- ` ${ data . type } not initialized, see the \ `useWorkerFetch\ ` parameter.`
2914+ "`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter."
29512915 ) ;
29522916 }
2953- return factory . fetch ( data ) ;
2917+ return this . binaryDataFactory . fetch ( data ) ;
29542918 } ) ;
29552919 }
29562920 }
0 commit comments