mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Update the Path2D
polyfill for Node.js environments
The polyfill that we use was recently split into two packages, and it now consists of a "core" package and a browser-specific package that build upon the former. Hence we need to update to use the "core" package, and slightly tweak the code that loads/initializes the polyfill; see also https://www.npmjs.com/package/path2d This patch was tested successfully with the [pdf2png example](https://github.com/mozilla/pdf.js/tree/master/examples/node/pdf2png), after running `gulp dist-install` locally, using [this PDF document](https://bug810214.bmoattachments.org/attachment.cgi?id=9254990) which contains Type3-fonts that render using `Path2D`.
This commit is contained in:
parent
e7203f558f
commit
dc0df0a3c2
4 changed files with 24 additions and 24 deletions
|
@ -27,7 +27,7 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|||
);
|
||||
}
|
||||
|
||||
let fs, canvas, path2d_polyfill;
|
||||
let fs, canvas, path2d;
|
||||
if (isNodeJS) {
|
||||
// Native packages.
|
||||
fs = await __non_webpack_import__("fs");
|
||||
|
@ -36,7 +36,7 @@ if (isNodeJS) {
|
|||
canvas = await __non_webpack_import__("canvas");
|
||||
} catch {}
|
||||
try {
|
||||
path2d_polyfill = await __non_webpack_import__("path2d-polyfill");
|
||||
path2d = await __non_webpack_import__("path2d");
|
||||
} catch {}
|
||||
}
|
||||
|
||||
|
@ -59,11 +59,17 @@ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) {
|
|||
return;
|
||||
}
|
||||
const CanvasRenderingContext2D = canvas?.CanvasRenderingContext2D;
|
||||
const polyfillPath2D = path2d_polyfill?.polyfillPath2D;
|
||||
const applyPath2DToCanvasRenderingContext =
|
||||
path2d?.applyPath2DToCanvasRenderingContext;
|
||||
const Path2D = path2d?.Path2D;
|
||||
|
||||
if (CanvasRenderingContext2D && polyfillPath2D) {
|
||||
globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
|
||||
polyfillPath2D(globalThis);
|
||||
if (
|
||||
CanvasRenderingContext2D &&
|
||||
applyPath2DToCanvasRenderingContext &&
|
||||
Path2D
|
||||
) {
|
||||
applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D);
|
||||
globalThis.Path2D = Path2D;
|
||||
} else {
|
||||
warn("Cannot polyfill `Path2D`, rendering may be broken.");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue