mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-29 10:27:21 +02:00
[api-minor] Replace the CMapReaderFactory, StandardFontDataFactory, and WasmFactory API options with a single factory/option
Currently we have no less than three different, but very similar, factories for reading built-in CMap files, standard font files, and wasm files on the main-thread.[1] These factories were added at different points in time, since I cannot imagine that we'd add essentially three copies of the same code otherwise. Nowadays these factories are often not even used[2], since worker-thread fetching is used whenever possible to improve performance. In particular, they will *only* be used when either: - The PDF.js library runs in Node.js environments. - The user manually sets `useWorkerFetch = false` when calling `getDocument`. - The user provides custom `CMapReaderFactory`, `StandardFontDataFactory`, and/or `WasmFactory` instances when calling `getDocument`. By replacing these factories with *a single* new `BinaryDataFactory` factory/option the number of `getDocument` options are thus reduced, which cannot hurt. This also reduces the total bundle-size of the Firefox PDF Viewer a little bit, and it slightly reduces the number of import maps that need to be maintained. *Please note:* For users that provide custom `CMapReaderFactory`, `StandardFontDataFactory`, and `WasmFactory` instances when calling `getDocument` this will be a breaking change, however it's unlikely that (many) such users exist. (The *internal* format data-format of `CMapReaderFactory` was changed in PR 18951, and there hasn't been a single question/complaint about it in well over a year.) --- [1] Any new functionality could easily lead to more such factories being added in the future, which wouldn't be great. [2] Note that the Firefox PDF Viewer no longer use these factories, since it "forcibly" sets `useWorkerFetch = true` during building.
This commit is contained in:
parent
9fa5cb9b30
commit
3a372fde94
22
gulpfile.mjs
22
gulpfile.mjs
@ -195,9 +195,7 @@ function createWebpackAlias(defines) {
|
|||||||
"fluent-dom": "node_modules/@fluent/dom/esm/index.js",
|
"fluent-dom": "node_modules/@fluent/dom/esm/index.js",
|
||||||
};
|
};
|
||||||
const libraryAlias = {
|
const libraryAlias = {
|
||||||
"display-cmap_reader_factory": "src/display/stubs.js",
|
"display-binary_data_factory": "src/display/stubs.js",
|
||||||
"display-standard_fontdata_factory": "src/display/stubs.js",
|
|
||||||
"display-wasm_factory": "src/display/stubs.js",
|
|
||||||
"display-fetch_stream": "src/display/stubs.js",
|
"display-fetch_stream": "src/display/stubs.js",
|
||||||
"display-network": "src/display/stubs.js",
|
"display-network": "src/display/stubs.js",
|
||||||
"display-node_stream": "src/display/stubs.js",
|
"display-node_stream": "src/display/stubs.js",
|
||||||
@ -227,11 +225,8 @@ function createWebpackAlias(defines) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (defines.CHROME) {
|
if (defines.CHROME) {
|
||||||
libraryAlias["display-cmap_reader_factory"] =
|
libraryAlias["display-binary_data_factory"] =
|
||||||
"src/display/cmap_reader_factory.js";
|
"src/display/binary_data_factory.js";
|
||||||
libraryAlias["display-standard_fontdata_factory"] =
|
|
||||||
"src/display/standard_fontdata_factory.js";
|
|
||||||
libraryAlias["display-wasm_factory"] = "src/display/wasm_factory.js";
|
|
||||||
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
|
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
|
||||||
libraryAlias["display-network"] = "src/display/network.js";
|
libraryAlias["display-network"] = "src/display/network.js";
|
||||||
|
|
||||||
@ -244,11 +239,8 @@ function createWebpackAlias(defines) {
|
|||||||
// Aliases defined here must also be replicated in the paths section of
|
// Aliases defined here must also be replicated in the paths section of
|
||||||
// the tsconfig.json file for the type generation to work.
|
// the tsconfig.json file for the type generation to work.
|
||||||
// In the tsconfig.json files, the .js extension must be omitted.
|
// In the tsconfig.json files, the .js extension must be omitted.
|
||||||
libraryAlias["display-cmap_reader_factory"] =
|
libraryAlias["display-binary_data_factory"] =
|
||||||
"src/display/cmap_reader_factory.js";
|
"src/display/binary_data_factory.js";
|
||||||
libraryAlias["display-standard_fontdata_factory"] =
|
|
||||||
"src/display/standard_fontdata_factory.js";
|
|
||||||
libraryAlias["display-wasm_factory"] = "src/display/wasm_factory.js";
|
|
||||||
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
|
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
|
||||||
libraryAlias["display-network"] = "src/display/network.js";
|
libraryAlias["display-network"] = "src/display/network.js";
|
||||||
libraryAlias["display-node_stream"] = "src/display/node_stream.js";
|
libraryAlias["display-node_stream"] = "src/display/node_stream.js";
|
||||||
@ -1547,9 +1539,7 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
|||||||
defines: bundleDefines,
|
defines: bundleDefines,
|
||||||
map: {
|
map: {
|
||||||
"pdfjs-lib": "../pdf.js",
|
"pdfjs-lib": "../pdf.js",
|
||||||
"display-cmap_reader_factory": "./cmap_reader_factory.js",
|
"display-binary_data_factory": "./binary_data_factory.js",
|
||||||
"display-standard_fontdata_factory": "./standard_fontdata_factory.js",
|
|
||||||
"display-wasm_factory": "./wasm_factory.js",
|
|
||||||
"display-fetch_stream": "./fetch_stream.js",
|
"display-fetch_stream": "./fetch_stream.js",
|
||||||
"display-network": "./network.js",
|
"display-network": "./network.js",
|
||||||
"display-node_stream": "./node_stream.js",
|
"display-node_stream": "./node_stream.js",
|
||||||
|
|||||||
@ -416,7 +416,7 @@ class PartialEvaluator {
|
|||||||
// Get the data on the main-thread instead.
|
// Get the data on the main-thread instead.
|
||||||
data = {
|
data = {
|
||||||
cMapData: await this.handler.sendWithPromise("FetchBinaryData", {
|
cMapData: await this.handler.sendWithPromise("FetchBinaryData", {
|
||||||
type: "cMapReaderFactory",
|
kind: "cMapUrl",
|
||||||
filename: `${name}${this.options.cMapPacked ? ".bcmap" : ""}`,
|
filename: `${name}${this.options.cMapPacked ? ".bcmap" : ""}`,
|
||||||
}),
|
}),
|
||||||
isCompressed: this.options.cMapPacked,
|
isCompressed: this.options.cMapPacked,
|
||||||
@ -459,7 +459,7 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
// Get the data on the main-thread instead.
|
// Get the data on the main-thread instead.
|
||||||
data = await this.handler.sendWithPromise("FetchBinaryData", {
|
data = await this.handler.sendWithPromise("FetchBinaryData", {
|
||||||
type: "standardFontDataFactory",
|
kind: "standardFontDataUrl",
|
||||||
filename,
|
filename,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class JBig2CCITTFaxWasmImage {
|
|||||||
}
|
}
|
||||||
this.#buffer = await this.#handler.sendWithPromise(
|
this.#buffer = await this.#handler.sendWithPromise(
|
||||||
"FetchBinaryData",
|
"FetchBinaryData",
|
||||||
{ type: "wasmFactory", filename }
|
{ kind: "wasmUrl", filename }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,7 +77,7 @@ class JpxImage {
|
|||||||
}
|
}
|
||||||
this.#buffer = await this.#handler.sendWithPromise(
|
this.#buffer = await this.#handler.sendWithPromise(
|
||||||
"FetchBinaryData",
|
"FetchBinaryData",
|
||||||
{ type: "wasmFactory", filename }
|
{ kind: "wasmUrl", filename }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,18 +66,14 @@ import {
|
|||||||
} from "./api_utils.js";
|
} from "./api_utils.js";
|
||||||
import { MessageHandler, wrapReason } from "../shared/message_handler.js";
|
import { MessageHandler, wrapReason } from "../shared/message_handler.js";
|
||||||
import {
|
import {
|
||||||
|
NodeBinaryDataFactory,
|
||||||
NodeCanvasFactory,
|
NodeCanvasFactory,
|
||||||
NodeCMapReaderFactory,
|
|
||||||
NodeFilterFactory,
|
NodeFilterFactory,
|
||||||
NodeStandardFontDataFactory,
|
|
||||||
NodeWasmFactory,
|
|
||||||
} from "display-node_utils";
|
} from "display-node_utils";
|
||||||
import { CanvasGraphics } from "./canvas.js";
|
import { CanvasGraphics } from "./canvas.js";
|
||||||
|
import { DOMBinaryDataFactory } from "display-binary_data_factory";
|
||||||
import { DOMCanvasFactory } from "./canvas_factory.js";
|
import { DOMCanvasFactory } from "./canvas_factory.js";
|
||||||
import { DOMCMapReaderFactory } from "display-cmap_reader_factory";
|
|
||||||
import { DOMFilterFactory } from "./filter_factory.js";
|
import { DOMFilterFactory } from "./filter_factory.js";
|
||||||
import { DOMStandardFontDataFactory } from "display-standard_fontdata_factory";
|
|
||||||
import { DOMWasmFactory } from "display-wasm_factory";
|
|
||||||
import { GlobalWorkerOptions } from "./worker_options.js";
|
import { GlobalWorkerOptions } from "./worker_options.js";
|
||||||
import { initWebGPUMesh } from "./webgpu_mesh.js";
|
import { initWebGPUMesh } from "./webgpu_mesh.js";
|
||||||
import { Metadata } from "./metadata.js";
|
import { Metadata } from "./metadata.js";
|
||||||
@ -140,9 +136,6 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
|||||||
* located. Include the trailing slash.
|
* located. Include the trailing slash.
|
||||||
* @property {boolean} [cMapPacked] - Specifies if the Adobe CMaps are binary
|
* @property {boolean} [cMapPacked] - Specifies if the Adobe CMaps are binary
|
||||||
* packed or not. The default value is `true`.
|
* packed or not. The default value is `true`.
|
||||||
* @property {Object} [CMapReaderFactory] - The factory that will be used when
|
|
||||||
* reading built-in CMap files.
|
|
||||||
* The default value is {DOMCMapReaderFactory}.
|
|
||||||
* @property {string} [iccUrl] - The URL where the predefined ICC profiles are
|
* @property {string} [iccUrl] - The URL where the predefined ICC profiles are
|
||||||
* located. Include the trailing slash.
|
* located. Include the trailing slash.
|
||||||
* @property {boolean} [useSystemFonts] - When `true`, fonts that aren't
|
* @property {boolean} [useSystemFonts] - When `true`, fonts that aren't
|
||||||
@ -152,18 +145,11 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
|||||||
* regardless of the environment (to prevent completely broken fonts).
|
* regardless of the environment (to prevent completely broken fonts).
|
||||||
* @property {string} [standardFontDataUrl] - The URL where the standard font
|
* @property {string} [standardFontDataUrl] - The URL where the standard font
|
||||||
* files are located. Include the trailing slash.
|
* files are located. Include the trailing slash.
|
||||||
* @property {Object} [StandardFontDataFactory] - The factory that will be used
|
|
||||||
* when reading the standard font files.
|
|
||||||
* The default value is {DOMStandardFontDataFactory}.
|
|
||||||
* @property {string} [wasmUrl] - The URL where the wasm files are located.
|
* @property {string} [wasmUrl] - The URL where the wasm files are located.
|
||||||
* Include the trailing slash.
|
* Include the trailing slash.
|
||||||
* @property {Object} [WasmFactory] - The factory that will be used
|
|
||||||
* when reading the wasm files.
|
|
||||||
* The default value is {DOMWasmFactory}.
|
|
||||||
* @property {boolean} [useWorkerFetch] - Enable using the Fetch API in the
|
* @property {boolean} [useWorkerFetch] - Enable using the Fetch API in the
|
||||||
* worker-thread when reading CMap and standard font files. When `true`,
|
* worker-thread when reading built-in CMap files, standard font files,
|
||||||
* the `CMapReaderFactory`, `StandardFontDataFactory`, and `WasmFactory`
|
* and wasm files. If `true`, the `BinaryDataFactory` option is ignored.
|
||||||
* options are ignored.
|
|
||||||
* The default value is `true` in web environments and `false` in Node.js.
|
* The default value is `true` in web environments and `false` in Node.js.
|
||||||
* @property {boolean} [useWasm] - Attempt to use WebAssembly in order to
|
* @property {boolean} [useWasm] - Attempt to use WebAssembly in order to
|
||||||
* improve e.g. image decoding performance.
|
* improve e.g. image decoding performance.
|
||||||
@ -235,6 +221,10 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
|||||||
* @property {Object} [FilterFactory] - The factory that will be used to
|
* @property {Object} [FilterFactory] - The factory that will be used to
|
||||||
* create SVG filters when rendering some images on the main canvas.
|
* create SVG filters when rendering some images on the main canvas.
|
||||||
* The default value is {DOMFilterFactory}.
|
* The default value is {DOMFilterFactory}.
|
||||||
|
* @property {Object} [BinaryDataFactory] - The factory that will be used when
|
||||||
|
* falling back to reading built-in CMap files, standard font files,
|
||||||
|
* and wasm files in the main-thread.
|
||||||
|
* The default value is {DOMBinaryDataFactory}.
|
||||||
* @property {boolean} [enableHWA] - Enables hardware acceleration for
|
* @property {boolean} [enableHWA] - Enables hardware acceleration for
|
||||||
* rendering. The default value is `false`.
|
* rendering. The default value is `false`.
|
||||||
* @property {Object} [pagesMapper] - The pages mapper that will be used to map
|
* @property {Object} [pagesMapper] - The pages mapper that will be used to map
|
||||||
@ -287,24 +277,9 @@ function getDocument(src = {}) {
|
|||||||
: null;
|
: null;
|
||||||
const cMapUrl = getFactoryUrlProp(src.cMapUrl);
|
const cMapUrl = getFactoryUrlProp(src.cMapUrl);
|
||||||
const cMapPacked = src.cMapPacked !== false;
|
const cMapPacked = src.cMapPacked !== false;
|
||||||
const CMapReaderFactory =
|
|
||||||
src.CMapReaderFactory ||
|
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeCMapReaderFactory
|
|
||||||
: DOMCMapReaderFactory);
|
|
||||||
const iccUrl = getFactoryUrlProp(src.iccUrl);
|
const iccUrl = getFactoryUrlProp(src.iccUrl);
|
||||||
const standardFontDataUrl = getFactoryUrlProp(src.standardFontDataUrl);
|
const standardFontDataUrl = getFactoryUrlProp(src.standardFontDataUrl);
|
||||||
const StandardFontDataFactory =
|
|
||||||
src.StandardFontDataFactory ||
|
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeStandardFontDataFactory
|
|
||||||
: DOMStandardFontDataFactory);
|
|
||||||
const wasmUrl = getFactoryUrlProp(src.wasmUrl);
|
const wasmUrl = getFactoryUrlProp(src.wasmUrl);
|
||||||
const WasmFactory =
|
|
||||||
src.WasmFactory ||
|
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeWasmFactory
|
|
||||||
: DOMWasmFactory);
|
|
||||||
const ignoreErrors = src.stopAtErrors !== true;
|
const ignoreErrors = src.stopAtErrors !== true;
|
||||||
const maxImageSize =
|
const maxImageSize =
|
||||||
Number.isInteger(src.maxImageSize) && src.maxImageSize > -1
|
Number.isInteger(src.maxImageSize) && src.maxImageSize > -1
|
||||||
@ -347,6 +322,11 @@ function getDocument(src = {}) {
|
|||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
? NodeFilterFactory
|
? NodeFilterFactory
|
||||||
: DOMFilterFactory);
|
: DOMFilterFactory);
|
||||||
|
const BinaryDataFactory =
|
||||||
|
src.BinaryDataFactory ||
|
||||||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
|
? NodeBinaryDataFactory
|
||||||
|
: DOMBinaryDataFactory);
|
||||||
const enableHWA = src.enableHWA === true;
|
const enableHWA = src.enableHWA === true;
|
||||||
const enableWebGPU = src.enableWebGPU === true;
|
const enableWebGPU = src.enableWebGPU === true;
|
||||||
const useWasm = src.useWasm !== false;
|
const useWasm = src.useWasm !== false;
|
||||||
@ -362,9 +342,7 @@ function getDocument(src = {}) {
|
|||||||
? src.useWorkerFetch
|
? src.useWorkerFetch
|
||||||
: (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
: (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
||||||
!!(
|
!!(
|
||||||
CMapReaderFactory === DOMCMapReaderFactory &&
|
BinaryDataFactory === DOMBinaryDataFactory &&
|
||||||
StandardFontDataFactory === DOMStandardFontDataFactory &&
|
|
||||||
WasmFactory === DOMWasmFactory &&
|
|
||||||
cMapUrl &&
|
cMapUrl &&
|
||||||
cMapPacked &&
|
cMapPacked &&
|
||||||
standardFontDataUrl &&
|
standardFontDataUrl &&
|
||||||
@ -388,21 +366,11 @@ function getDocument(src = {}) {
|
|||||||
const transportFactory = {
|
const transportFactory = {
|
||||||
canvasFactory: new CanvasFactory({ ownerDocument, enableHWA }),
|
canvasFactory: new CanvasFactory({ ownerDocument, enableHWA }),
|
||||||
filterFactory: new FilterFactory({ docId, ownerDocument }),
|
filterFactory: new FilterFactory({ docId, ownerDocument }),
|
||||||
cMapReaderFactory:
|
binaryDataFactory:
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
||||||
useWorkerFetch
|
useWorkerFetch
|
||||||
? null
|
? null
|
||||||
: new CMapReaderFactory({ baseUrl: cMapUrl }),
|
: new BinaryDataFactory({ cMapUrl, standardFontDataUrl, wasmUrl }),
|
||||||
standardFontDataFactory:
|
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
|
||||||
useWorkerFetch
|
|
||||||
? null
|
|
||||||
: new StandardFontDataFactory({ baseUrl: standardFontDataUrl }),
|
|
||||||
wasmFactory:
|
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
|
||||||
useWorkerFetch
|
|
||||||
? null
|
|
||||||
: new WasmFactory({ baseUrl: wasmUrl }),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!worker) {
|
if (!worker) {
|
||||||
@ -2474,9 +2442,7 @@ class WorkerTransport {
|
|||||||
this.canvasFactory = factory.canvasFactory;
|
this.canvasFactory = factory.canvasFactory;
|
||||||
this.filterFactory = factory.filterFactory;
|
this.filterFactory = factory.filterFactory;
|
||||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
||||||
this.cMapReaderFactory = factory.cMapReaderFactory;
|
this.binaryDataFactory = factory.binaryDataFactory;
|
||||||
this.standardFontDataFactory = factory.standardFontDataFactory;
|
|
||||||
this.wasmFactory = factory.wasmFactory;
|
|
||||||
}
|
}
|
||||||
this.pagesMapper = pagesMapper;
|
this.pagesMapper = pagesMapper;
|
||||||
|
|
||||||
@ -2943,14 +2909,12 @@ class WorkerTransport {
|
|||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
throw new Error("Worker was destroyed.");
|
throw new Error("Worker was destroyed.");
|
||||||
}
|
}
|
||||||
const factory = this[data.type];
|
if (!this.binaryDataFactory) {
|
||||||
|
|
||||||
if (!factory) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${data.type} not initialized, see the \`useWorkerFetch\` parameter.`
|
"`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return factory.fetch(data);
|
return this.binaryDataFactory.fetch(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
79
src/display/binary_data_factory.js
Normal file
79
src/display/binary_data_factory.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/* Copyright 2015 Mozilla Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { stringToBytes, unreachable } from "../shared/util.js";
|
||||||
|
import { fetchData } from "./display_utils.js";
|
||||||
|
|
||||||
|
class BaseBinaryDataFactory {
|
||||||
|
#errorStr = Object.freeze({
|
||||||
|
cMapUrl: "CMap",
|
||||||
|
standardFontDataUrl: "font",
|
||||||
|
wasmUrl: "wasm",
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor({ cMapUrl = null, standardFontDataUrl = null, wasmUrl = null }) {
|
||||||
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseBinaryDataFactory
|
||||||
|
) {
|
||||||
|
unreachable("Cannot initialize BaseBinaryDataFactory.");
|
||||||
|
}
|
||||||
|
this.cMapUrl = cMapUrl;
|
||||||
|
this.standardFontDataUrl = standardFontDataUrl;
|
||||||
|
this.wasmUrl = wasmUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetch({ kind, filename }) {
|
||||||
|
switch (kind) {
|
||||||
|
case "cMapUrl":
|
||||||
|
case "standardFontDataUrl":
|
||||||
|
case "wasmUrl":
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
unreachable(`Not implemented: ${kind}`);
|
||||||
|
}
|
||||||
|
const baseUrl = this[kind];
|
||||||
|
if (!baseUrl) {
|
||||||
|
throw new Error(`Ensure that the \`${kind}\` API parameter is provided.`);
|
||||||
|
}
|
||||||
|
const url = `${baseUrl}${filename}`;
|
||||||
|
|
||||||
|
return this._fetch(url, kind).catch(reason => {
|
||||||
|
throw new Error(`Unable to load ${this.#errorStr[kind]} data at: ${url}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
* @returns {Promise<Uint8Array>}
|
||||||
|
*/
|
||||||
|
async _fetch(url, kind) {
|
||||||
|
unreachable("Abstract method `_fetch` called.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DOMBinaryDataFactory extends BaseBinaryDataFactory {
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
async _fetch(url, kind) {
|
||||||
|
const type =
|
||||||
|
kind === "cMapUrl" && !url.endsWith(".bcmap") ? "text" : "bytes";
|
||||||
|
const data = await fetchData(url, type);
|
||||||
|
return data instanceof Uint8Array ? data : stringToBytes(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { BaseBinaryDataFactory, DOMBinaryDataFactory };
|
||||||
@ -1,63 +0,0 @@
|
|||||||
/* Copyright 2015 Mozilla Foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { stringToBytes, unreachable } from "../shared/util.js";
|
|
||||||
import { fetchData } from "./display_utils.js";
|
|
||||||
|
|
||||||
class BaseCMapReaderFactory {
|
|
||||||
constructor({ baseUrl = null }) {
|
|
||||||
if (
|
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
|
||||||
this.constructor === BaseCMapReaderFactory
|
|
||||||
) {
|
|
||||||
unreachable("Cannot initialize BaseCMapReaderFactory.");
|
|
||||||
}
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetch({ filename }) {
|
|
||||||
if (!this.baseUrl) {
|
|
||||||
throw new Error("Ensure that the `cMapUrl` API parameter is provided.");
|
|
||||||
}
|
|
||||||
const url = `${this.baseUrl}${filename}`;
|
|
||||||
|
|
||||||
return this._fetch(url).catch(reason => {
|
|
||||||
throw new Error(`Unable to load CMap data at: ${url}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
* @returns {Promise<Uint8Array>}
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
unreachable("Abstract method `_fetch` called.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DOMCMapReaderFactory extends BaseCMapReaderFactory {
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
const data = await fetchData(
|
|
||||||
url,
|
|
||||||
/* type = */ url.endsWith(".bcmap") ? "bytes" : "text"
|
|
||||||
);
|
|
||||||
return data instanceof Uint8Array ? data : stringToBytes(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { BaseCMapReaderFactory, DOMCMapReaderFactory };
|
|
||||||
@ -15,11 +15,9 @@
|
|||||||
/* globals process */
|
/* globals process */
|
||||||
|
|
||||||
import { isNodeJS, warn } from "../shared/util.js";
|
import { isNodeJS, warn } from "../shared/util.js";
|
||||||
|
import { BaseBinaryDataFactory } from "./binary_data_factory.js";
|
||||||
import { BaseCanvasFactory } from "./canvas_factory.js";
|
import { BaseCanvasFactory } from "./canvas_factory.js";
|
||||||
import { BaseCMapReaderFactory } from "./cmap_reader_factory.js";
|
|
||||||
import { BaseFilterFactory } from "./filter_factory.js";
|
import { BaseFilterFactory } from "./filter_factory.js";
|
||||||
import { BaseStandardFontDataFactory } from "./standard_fontdata_factory.js";
|
|
||||||
import { BaseWasmFactory } from "./wasm_factory.js";
|
|
||||||
|
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -98,38 +96,18 @@ class NodeCanvasFactory extends BaseCanvasFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NodeCMapReaderFactory extends BaseCMapReaderFactory {
|
class NodeBinaryDataFactory extends BaseBinaryDataFactory {
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
async _fetch(url) {
|
async _fetch(url, kind) {
|
||||||
return fetchData(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NodeStandardFontDataFactory extends BaseStandardFontDataFactory {
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
return fetchData(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NodeWasmFactory extends BaseWasmFactory {
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
return fetchData(url);
|
return fetchData(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
fetchData,
|
fetchData,
|
||||||
|
NodeBinaryDataFactory,
|
||||||
NodeCanvasFactory,
|
NodeCanvasFactory,
|
||||||
NodeCMapReaderFactory,
|
|
||||||
NodeFilterFactory,
|
NodeFilterFactory,
|
||||||
NodeStandardFontDataFactory,
|
|
||||||
NodeWasmFactory,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
/* Copyright 2015 Mozilla Foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { fetchData } from "./display_utils.js";
|
|
||||||
import { unreachable } from "../shared/util.js";
|
|
||||||
|
|
||||||
class BaseStandardFontDataFactory {
|
|
||||||
constructor({ baseUrl = null }) {
|
|
||||||
if (
|
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
|
||||||
this.constructor === BaseStandardFontDataFactory
|
|
||||||
) {
|
|
||||||
unreachable("Cannot initialize BaseStandardFontDataFactory.");
|
|
||||||
}
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetch({ filename }) {
|
|
||||||
if (!this.baseUrl) {
|
|
||||||
throw new Error(
|
|
||||||
"Ensure that the `standardFontDataUrl` API parameter is provided."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const url = `${this.baseUrl}${filename}`;
|
|
||||||
|
|
||||||
return this._fetch(url).catch(reason => {
|
|
||||||
throw new Error(`Unable to load font data at: ${url}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
* @returns {Promise<Uint8Array>}
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
unreachable("Abstract method `_fetch` called.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DOMStandardFontDataFactory extends BaseStandardFontDataFactory {
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
return fetchData(url, /* type = */ "bytes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { BaseStandardFontDataFactory, DOMStandardFontDataFactory };
|
|
||||||
@ -13,27 +13,19 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const DOMCMapReaderFactory = null;
|
const DOMBinaryDataFactory = null;
|
||||||
const DOMWasmFactory = null;
|
const NodeBinaryDataFactory = null;
|
||||||
const DOMStandardFontDataFactory = null;
|
|
||||||
const NodeCanvasFactory = null;
|
const NodeCanvasFactory = null;
|
||||||
const NodeCMapReaderFactory = null;
|
|
||||||
const NodeFilterFactory = null;
|
const NodeFilterFactory = null;
|
||||||
const NodeWasmFactory = null;
|
|
||||||
const NodeStandardFontDataFactory = null;
|
|
||||||
const PDFFetchStream = null;
|
const PDFFetchStream = null;
|
||||||
const PDFNetworkStream = null;
|
const PDFNetworkStream = null;
|
||||||
const PDFNodeStream = null;
|
const PDFNodeStream = null;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
DOMCMapReaderFactory,
|
DOMBinaryDataFactory,
|
||||||
DOMStandardFontDataFactory,
|
NodeBinaryDataFactory,
|
||||||
DOMWasmFactory,
|
|
||||||
NodeCanvasFactory,
|
NodeCanvasFactory,
|
||||||
NodeCMapReaderFactory,
|
|
||||||
NodeFilterFactory,
|
NodeFilterFactory,
|
||||||
NodeStandardFontDataFactory,
|
|
||||||
NodeWasmFactory,
|
|
||||||
PDFFetchStream,
|
PDFFetchStream,
|
||||||
PDFNetworkStream,
|
PDFNetworkStream,
|
||||||
PDFNodeStream,
|
PDFNodeStream,
|
||||||
|
|||||||
@ -1,59 +0,0 @@
|
|||||||
/* Copyright 2015 Mozilla Foundation
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { fetchData } from "./display_utils.js";
|
|
||||||
import { unreachable } from "../shared/util.js";
|
|
||||||
|
|
||||||
class BaseWasmFactory {
|
|
||||||
constructor({ baseUrl = null }) {
|
|
||||||
if (
|
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
|
||||||
this.constructor === BaseWasmFactory
|
|
||||||
) {
|
|
||||||
unreachable("Cannot initialize BaseWasmFactory.");
|
|
||||||
}
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetch({ filename }) {
|
|
||||||
if (!this.baseUrl) {
|
|
||||||
throw new Error("Ensure that the `wasmUrl` API parameter is provided.");
|
|
||||||
}
|
|
||||||
const url = `${this.baseUrl}${filename}`;
|
|
||||||
|
|
||||||
return this._fetch(url).catch(reason => {
|
|
||||||
throw new Error(`Unable to load wasm data at: ${url}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
* @returns {Promise<Uint8Array>}
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
unreachable("Abstract method `_fetch` called.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DOMWasmFactory extends BaseWasmFactory {
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
async _fetch(url) {
|
|
||||||
return fetchData(url, /* type = */ "bytes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { BaseWasmFactory, DOMWasmFactory };
|
|
||||||
@ -43,9 +43,7 @@ limitations under the License.
|
|||||||
"pdfjs/": "../../src/",
|
"pdfjs/": "../../src/",
|
||||||
"pdfjs-lib": "../../src/pdf.js",
|
"pdfjs-lib": "../../src/pdf.js",
|
||||||
|
|
||||||
"display-cmap_reader_factory": "../../src/display/cmap_reader_factory.js",
|
"display-binary_data_factory": "../../src/display/binary_data_factory.js",
|
||||||
"display-standard_fontdata_factory": "../../src/display/standard_fontdata_factory.js",
|
|
||||||
"display-wasm_factory": "../../src/display/wasm_factory.js",
|
|
||||||
"display-fetch_stream": "../../src/display/fetch_stream.js",
|
"display-fetch_stream": "../../src/display/fetch_stream.js",
|
||||||
"display-network": "../../src/display/network.js",
|
"display-network": "../../src/display/network.js",
|
||||||
"display-node_stream": "../../src/display/stubs.js",
|
"display-node_stream": "../../src/display/stubs.js",
|
||||||
|
|||||||
@ -35,8 +35,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
CMAP_URL,
|
CMAP_URL,
|
||||||
createIdFactory,
|
createIdFactory,
|
||||||
DefaultCMapReaderFactory,
|
DefaultBinaryDataFactory,
|
||||||
DefaultStandardFontDataFactory,
|
|
||||||
fetchBuiltInCMapHelper,
|
fetchBuiltInCMapHelper,
|
||||||
STANDARD_FONT_DATA_URL,
|
STANDARD_FONT_DATA_URL,
|
||||||
XRefMock,
|
XRefMock,
|
||||||
@ -83,10 +82,14 @@ describe("annotation", function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fontDataReader = new DefaultStandardFontDataFactory({
|
const binaryDataFactory = new DefaultBinaryDataFactory({
|
||||||
baseUrl: STANDARD_FONT_DATA_URL,
|
cMapUrl: CMAP_URL,
|
||||||
|
standardFontDataUrl: STANDARD_FONT_DATA_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fetchBuiltInCMap = name =>
|
||||||
|
fetchBuiltInCMapHelper(binaryDataFactory, /* cMapPacked = */ true, name);
|
||||||
|
|
||||||
class HandlerMock {
|
class HandlerMock {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
@ -96,11 +99,11 @@ describe("annotation", function () {
|
|||||||
this.inputs.push({ name, data });
|
this.inputs.push({ name, data });
|
||||||
}
|
}
|
||||||
|
|
||||||
sendWithPromise(name, data) {
|
async sendWithPromise(name, data) {
|
||||||
if (name !== "FetchStandardFontData") {
|
if (name === "FetchBinaryData") {
|
||||||
return Promise.reject(new Error(`Unsupported mock ${name}.`));
|
return binaryDataFactory.fetch(data);
|
||||||
}
|
}
|
||||||
return fontDataReader.fetch(data);
|
throw new Error(`Unsupported mock ${name}.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,12 +117,6 @@ describe("annotation", function () {
|
|||||||
annotationGlobalsMock =
|
annotationGlobalsMock =
|
||||||
await AnnotationFactory.createGlobals(pdfManagerMock);
|
await AnnotationFactory.createGlobals(pdfManagerMock);
|
||||||
|
|
||||||
const CMapReaderFactory = new DefaultCMapReaderFactory({
|
|
||||||
baseUrl: CMAP_URL,
|
|
||||||
});
|
|
||||||
const fetchBuiltInCMap = name =>
|
|
||||||
fetchBuiltInCMapHelper(CMapReaderFactory, /* cMapPacked = */ true, name);
|
|
||||||
|
|
||||||
const builtInCMapCache = new Map();
|
const builtInCMapCache = new Map();
|
||||||
for (const name of ["UniJIS-UTF16-H", "Adobe-Japan1-UCS2"]) {
|
for (const name of ["UniJIS-UTF16-H", "Adobe-Japan1-UCS2"]) {
|
||||||
builtInCMapCache.set(name, await fetchBuiltInCMap(name));
|
builtInCMapCache.set(name, await fetchBuiltInCMap(name));
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
import { CMap, CMapFactory, IdentityCMap } from "../../src/core/cmap.js";
|
import { CMap, CMapFactory, IdentityCMap } from "../../src/core/cmap.js";
|
||||||
import {
|
import {
|
||||||
CMAP_URL,
|
CMAP_URL,
|
||||||
DefaultCMapReaderFactory,
|
DefaultBinaryDataFactory,
|
||||||
fetchBuiltInCMapHelper,
|
fetchBuiltInCMapHelper,
|
||||||
} from "./test_utils.js";
|
} from "./test_utils.js";
|
||||||
import { Name } from "../../src/core/primitives.js";
|
import { Name } from "../../src/core/primitives.js";
|
||||||
@ -26,12 +26,12 @@ describe("cmap", function () {
|
|||||||
let fetchBuiltInCMap;
|
let fetchBuiltInCMap;
|
||||||
|
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
const CMapReaderFactory = new DefaultCMapReaderFactory({
|
const binaryDataFactory = new DefaultBinaryDataFactory({
|
||||||
baseUrl: CMAP_URL,
|
cMapUrl: CMAP_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchBuiltInCMap = name =>
|
fetchBuiltInCMap = name =>
|
||||||
fetchBuiltInCMapHelper(CMapReaderFactory, /* cMapPacked = */ true, name);
|
fetchBuiltInCMapHelper(binaryDataFactory, /* cMapPacked = */ true, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(function () {
|
afterAll(function () {
|
||||||
@ -205,9 +205,9 @@ describe("cmap", function () {
|
|||||||
|
|
||||||
it("attempts to load a built-in CMap without the necessary API parameters", async function () {
|
it("attempts to load a built-in CMap without the necessary API parameters", async function () {
|
||||||
function tmpFetchBuiltInCMap(name) {
|
function tmpFetchBuiltInCMap(name) {
|
||||||
const CMapReaderFactory = new DefaultCMapReaderFactory({});
|
const binaryDataFactory = new DefaultBinaryDataFactory({});
|
||||||
return fetchBuiltInCMapHelper(
|
return fetchBuiltInCMapHelper(
|
||||||
CMapReaderFactory,
|
binaryDataFactory,
|
||||||
/* cMapPacked = */ true,
|
/* cMapPacked = */ true,
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
@ -232,11 +232,11 @@ describe("cmap", function () {
|
|||||||
|
|
||||||
it("attempts to load a built-in CMap with inconsistent API parameters", async function () {
|
it("attempts to load a built-in CMap with inconsistent API parameters", async function () {
|
||||||
function tmpFetchBuiltInCMap(name) {
|
function tmpFetchBuiltInCMap(name) {
|
||||||
const CMapReaderFactory = new DefaultCMapReaderFactory({
|
const binaryDataFactory = new DefaultBinaryDataFactory({
|
||||||
baseUrl: CMAP_URL,
|
cMapUrl: CMAP_URL,
|
||||||
});
|
});
|
||||||
return fetchBuiltInCMapHelper(
|
return fetchBuiltInCMapHelper(
|
||||||
CMapReaderFactory,
|
binaryDataFactory,
|
||||||
/* cMapPacked = */ false,
|
/* cMapPacked = */ false,
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
|
|||||||
@ -16,13 +16,11 @@
|
|||||||
import { assert, isNodeJS } from "../../src/shared/util.js";
|
import { assert, isNodeJS } from "../../src/shared/util.js";
|
||||||
import {
|
import {
|
||||||
fetchData as fetchDataNode,
|
fetchData as fetchDataNode,
|
||||||
NodeCMapReaderFactory,
|
NodeBinaryDataFactory,
|
||||||
NodeStandardFontDataFactory,
|
|
||||||
} from "../../src/display/node_utils.js";
|
} from "../../src/display/node_utils.js";
|
||||||
import { NullStream, StringStream } from "../../src/core/stream.js";
|
import { NullStream, StringStream } from "../../src/core/stream.js";
|
||||||
import { Page, PDFDocument } from "../../src/core/document.js";
|
import { Page, PDFDocument } from "../../src/core/document.js";
|
||||||
import { DOMCMapReaderFactory } from "../../src/display/cmap_reader_factory.js";
|
import { DOMBinaryDataFactory } from "../../src/display/binary_data_factory.js";
|
||||||
import { DOMStandardFontDataFactory } from "../../src/display/standard_fontdata_factory.js";
|
|
||||||
import { fetchData as fetchDataDOM } from "../../src/display/display_utils.js";
|
import { fetchData as fetchDataDOM } from "../../src/display/display_utils.js";
|
||||||
import { Ref } from "../../src/core/primitives.js";
|
import { Ref } from "../../src/core/primitives.js";
|
||||||
|
|
||||||
@ -45,19 +43,15 @@ class DefaultFileReaderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultCMapReaderFactory =
|
const DefaultBinaryDataFactory =
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
||||||
? NodeCMapReaderFactory
|
? NodeBinaryDataFactory
|
||||||
: DOMCMapReaderFactory;
|
: DOMBinaryDataFactory;
|
||||||
|
|
||||||
const DefaultStandardFontDataFactory =
|
async function fetchBuiltInCMapHelper(binaryDataFactory, cMapPacked, name) {
|
||||||
typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
|
|
||||||
? NodeStandardFontDataFactory
|
|
||||||
: DOMStandardFontDataFactory;
|
|
||||||
|
|
||||||
async function fetchBuiltInCMapHelper(cMapReaderFactory, cMapPacked, name) {
|
|
||||||
return {
|
return {
|
||||||
cMapData: await cMapReaderFactory.fetch({
|
cMapData: await binaryDataFactory.fetch({
|
||||||
|
kind: "cMapUrl",
|
||||||
filename: `${name}${cMapPacked ? ".bcmap" : ""}`,
|
filename: `${name}${cMapPacked ? ".bcmap" : ""}`,
|
||||||
}),
|
}),
|
||||||
isCompressed: cMapPacked,
|
isCompressed: cMapPacked,
|
||||||
@ -258,9 +252,8 @@ export {
|
|||||||
buildGetDocumentParams,
|
buildGetDocumentParams,
|
||||||
CMAP_URL,
|
CMAP_URL,
|
||||||
createIdFactory,
|
createIdFactory,
|
||||||
DefaultCMapReaderFactory,
|
DefaultBinaryDataFactory,
|
||||||
DefaultFileReaderFactory,
|
DefaultFileReaderFactory,
|
||||||
DefaultStandardFontDataFactory,
|
|
||||||
fetchBuiltInCMapHelper,
|
fetchBuiltInCMapHelper,
|
||||||
getCrossOriginHostname,
|
getCrossOriginHostname,
|
||||||
STANDARD_FONT_DATA_URL,
|
STANDARD_FONT_DATA_URL,
|
||||||
|
|||||||
@ -20,9 +20,7 @@
|
|||||||
"fluent-dom": "../../node_modules/@fluent/dom/esm/index.js",
|
"fluent-dom": "../../node_modules/@fluent/dom/esm/index.js",
|
||||||
"cached-iterable": "../../node_modules/cached-iterable/src/index.mjs",
|
"cached-iterable": "../../node_modules/cached-iterable/src/index.mjs",
|
||||||
|
|
||||||
"display-cmap_reader_factory": "../../src/display/cmap_reader_factory.js",
|
"display-binary_data_factory": "../../src/display/binary_data_factory.js",
|
||||||
"display-standard_fontdata_factory": "../../src/display/standard_fontdata_factory.js",
|
|
||||||
"display-wasm_factory": "../../src/display/wasm_factory.js",
|
|
||||||
"display-fetch_stream": "../../src/display/fetch_stream.js",
|
"display-fetch_stream": "../../src/display/fetch_stream.js",
|
||||||
"display-network": "../../src/display/network.js",
|
"display-network": "../../src/display/network.js",
|
||||||
"display-node_stream": "../../src/display/stubs.js",
|
"display-node_stream": "../../src/display/stubs.js",
|
||||||
|
|||||||
@ -10,11 +10,7 @@
|
|||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"paths": {
|
"paths": {
|
||||||
"pdfjs-lib": ["./src/pdf"],
|
"pdfjs-lib": ["./src/pdf"],
|
||||||
"display-cmap_reader_factory": ["./src/display/cmap_reader_factory"],
|
"display-binary_data_factory": ["./src/display/binary_data_factory"],
|
||||||
"display-standard_fontdata_factory": [
|
|
||||||
"./src/display/standard_fontdata_factory"
|
|
||||||
],
|
|
||||||
"display-wasm_factory": ["./src/display/wasm_factory"],
|
|
||||||
"display-fetch_stream": ["./src/display/fetch_stream"],
|
"display-fetch_stream": ["./src/display/fetch_stream"],
|
||||||
"display-network": ["./src/display/network"],
|
"display-network": ["./src/display/network"],
|
||||||
"display-node_stream": ["./src/display/node_stream"],
|
"display-node_stream": ["./src/display/node_stream"],
|
||||||
|
|||||||
@ -126,9 +126,7 @@ limitations under the License.
|
|||||||
"pdfjs/": "../../src/",
|
"pdfjs/": "../../src/",
|
||||||
"pdfjs-lib": "../../src/pdf.js",
|
"pdfjs-lib": "../../src/pdf.js",
|
||||||
|
|
||||||
"display-cmap_reader_factory": "../../src/display/cmap_reader_factory.js",
|
"display-binary_data_factory": "../../src/display/binary_data_factory.js",
|
||||||
"display-standard_fontdata_factory": "../../src/display/standard_fontdata_factory.js",
|
|
||||||
"display-wasm_factory": "../../src/display/wasm_factory.js",
|
|
||||||
"display-fetch_stream": "../../src/display/fetch_stream.js",
|
"display-fetch_stream": "../../src/display/fetch_stream.js",
|
||||||
"display-network": "../../src/display/network.js",
|
"display-network": "../../src/display/network.js",
|
||||||
"display-node_stream": "../../src/display/stubs.js",
|
"display-node_stream": "../../src/display/stubs.js",
|
||||||
|
|||||||
@ -59,9 +59,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
"fluent-dom": "../node_modules/@fluent/dom/esm/index.js",
|
"fluent-dom": "../node_modules/@fluent/dom/esm/index.js",
|
||||||
"cached-iterable": "../node_modules/cached-iterable/src/index.mjs",
|
"cached-iterable": "../node_modules/cached-iterable/src/index.mjs",
|
||||||
|
|
||||||
"display-cmap_reader_factory": "../src/display/cmap_reader_factory.js",
|
"display-binary_data_factory": "../src/display/binary_data_factory.js",
|
||||||
"display-standard_fontdata_factory": "../src/display/standard_fontdata_factory.js",
|
|
||||||
"display-wasm_factory": "../src/display/wasm_factory.js",
|
|
||||||
"display-fetch_stream": "../src/display/fetch_stream.js",
|
"display-fetch_stream": "../src/display/fetch_stream.js",
|
||||||
"display-network": "../src/display/network.js",
|
"display-network": "../src/display/network.js",
|
||||||
"display-node_stream": "../src/display/stubs.js",
|
"display-node_stream": "../src/display/stubs.js",
|
||||||
|
|||||||
@ -62,9 +62,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
"fluent-dom": "../node_modules/@fluent/dom/esm/index.js",
|
"fluent-dom": "../node_modules/@fluent/dom/esm/index.js",
|
||||||
"cached-iterable": "../node_modules/cached-iterable/src/index.mjs",
|
"cached-iterable": "../node_modules/cached-iterable/src/index.mjs",
|
||||||
|
|
||||||
"display-cmap_reader_factory": "../src/display/cmap_reader_factory.js",
|
"display-binary_data_factory": "../src/display/binary_data_factory.js",
|
||||||
"display-standard_fontdata_factory": "../src/display/standard_fontdata_factory.js",
|
|
||||||
"display-wasm_factory": "../src/display/wasm_factory.js",
|
|
||||||
"display-fetch_stream": "../src/display/fetch_stream.js",
|
"display-fetch_stream": "../src/display/fetch_stream.js",
|
||||||
"display-network": "../src/display/network.js",
|
"display-network": "../src/display/network.js",
|
||||||
"display-node_stream": "../src/display/stubs.js",
|
"display-node_stream": "../src/display/stubs.js",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user