Don't initialize CMapReaderFactory
/StandardFontDataFactory
when the useWorkerFetch
API option is set
Given that there's no fallback on the worker-thread, it shouldn't be necessary to initialize `CMapReaderFactory`/`StandardFontDataFactory` when `useWorkerFetch = true` is set. Slightly unrelated, but this patch also ensures that the `useSystemFonts` default value only does the `isNodeJS` check in builds where that's actually necessary.
This commit is contained in:
parent
312326991f
commit
2f8e2548f2
@ -163,7 +163,7 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||||||
* @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 CMap and standard font files. When `true`,
|
||||||
* the `CMapReaderFactory` and `StandardFontDataFactory` options are ignored.
|
* the `CMapReaderFactory` and `StandardFontDataFactory` options are ignored.
|
||||||
* The default value is `true` in web wenvironments and `false` in Node.js.
|
* The default value is `true` in web environments and `false` in Node.js.
|
||||||
* @property {boolean} [stopAtErrors] - Reject certain promises, e.g.
|
* @property {boolean} [stopAtErrors] - Reject certain promises, e.g.
|
||||||
* `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
|
* `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
|
||||||
* PDF data cannot be successfully parsed, instead of attempting to recover
|
* PDF data cannot be successfully parsed, instead of attempting to recover
|
||||||
@ -329,7 +329,10 @@ function getDocument(src) {
|
|||||||
params.maxImageSize = -1;
|
params.maxImageSize = -1;
|
||||||
}
|
}
|
||||||
if (typeof params.useSystemFonts !== "boolean") {
|
if (typeof params.useSystemFonts !== "boolean") {
|
||||||
params.useSystemFonts = !isNodeJS;
|
params.useSystemFonts = !(
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
||||||
|
isNodeJS
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (typeof params.useWorkerFetch !== "boolean") {
|
if (typeof params.useWorkerFetch !== "boolean") {
|
||||||
params.useWorkerFetch =
|
params.useWorkerFetch =
|
||||||
@ -2277,13 +2280,16 @@ class WorkerTransport {
|
|||||||
styleElement: params.styleElement,
|
styleElement: params.styleElement,
|
||||||
});
|
});
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this.CMapReaderFactory = new params.CMapReaderFactory({
|
|
||||||
baseUrl: params.cMapUrl,
|
if (!params.useWorkerFetch) {
|
||||||
isCompressed: params.cMapPacked,
|
this.CMapReaderFactory = new params.CMapReaderFactory({
|
||||||
});
|
baseUrl: params.cMapUrl,
|
||||||
this.StandardFontDataFactory = new params.StandardFontDataFactory({
|
isCompressed: params.cMapPacked,
|
||||||
baseUrl: params.standardFontDataUrl,
|
});
|
||||||
});
|
this.StandardFontDataFactory = new params.StandardFontDataFactory({
|
||||||
|
baseUrl: params.standardFontDataUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
this.destroyCapability = null;
|
this.destroyCapability = null;
|
||||||
@ -2684,14 +2690,28 @@ class WorkerTransport {
|
|||||||
|
|
||||||
messageHandler.on("FetchBuiltInCMap", data => {
|
messageHandler.on("FetchBuiltInCMap", data => {
|
||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
return Promise.reject(new Error("Worker was destroyed"));
|
return Promise.reject(new Error("Worker was destroyed."));
|
||||||
|
}
|
||||||
|
if (!this.CMapReaderFactory) {
|
||||||
|
return Promise.reject(
|
||||||
|
new Error(
|
||||||
|
"CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return this.CMapReaderFactory.fetch(data);
|
return this.CMapReaderFactory.fetch(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
messageHandler.on("FetchStandardFontData", data => {
|
messageHandler.on("FetchStandardFontData", data => {
|
||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
return Promise.reject(new Error("Worker was destroyed"));
|
return Promise.reject(new Error("Worker was destroyed."));
|
||||||
|
}
|
||||||
|
if (!this.StandardFontDataFactory) {
|
||||||
|
return Promise.reject(
|
||||||
|
new Error(
|
||||||
|
"StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return this.StandardFontDataFactory.fetch(data);
|
return this.StandardFontDataFactory.fetch(data);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user