From a989244570b26fee6538f1414055dc0c2ac7533f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 24 Sep 2024 12:48:36 +0200 Subject: [PATCH] Slightly re-factor the `transportFactory` initialization in `getDocument` Given that the `WorkerTransport`-constructor will access all possible factory-instances, let's ensure that the `transportFactory`-object always has a consistent shape regardless of other options. Also, since `useWorkerFetch` is always true in MOZCENTRAL builds we never need to create `CMapReaderFactory`/`StandardFontDataFactory`-instances there. --- src/display/api.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 8e7a3c4b79040..d6dd653740755 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -341,16 +341,17 @@ function getDocument(src = {}) { const transportFactory = { canvasFactory: new CanvasFactory({ ownerDocument, enableHWA }), filterFactory: new FilterFactory({ docId, ownerDocument }), + cMapReaderFactory: + (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || + useWorkerFetch + ? null + : new CMapReaderFactory({ baseUrl: cMapUrl, isCompressed: cMapPacked }), + standardFontDataFactory: + (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || + useWorkerFetch + ? null + : new StandardFontDataFactory({ baseUrl: standardFontDataUrl }), }; - if (!useWorkerFetch) { - transportFactory.cMapReaderFactory = new CMapReaderFactory({ - baseUrl: cMapUrl, - isCompressed: cMapPacked, - }); - transportFactory.standardFontDataFactory = new StandardFontDataFactory({ - baseUrl: standardFontDataUrl, - }); - } if (!worker) { const workerParams = {