1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #15951 from Snuffleupagus/polyfill-Path2D

Polyfill `Path2D` in Node.js environments
This commit is contained in:
Tim van der Meij 2023-01-28 19:06:54 +01:00 committed by GitHub
commit ee3be2f979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 237 additions and 2462 deletions

View file

@ -38,7 +38,6 @@ import {
TilingPattern,
} from "./pattern_helper.js";
import { applyMaskImageData } from "../shared/image_utils.js";
import { isNodeJS } from "../shared/is_node.js";
// <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here.
@ -55,13 +54,7 @@ const EXECUTION_TIME = 15; // ms
const EXECUTION_STEPS = 10;
// To disable Type3 compilation, set the value to `-1`.
const MAX_SIZE_TO_COMPILE =
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC") &&
isNodeJS &&
typeof Path2D === "undefined"
? -1
: 1000;
const MAX_SIZE_TO_COMPILE = 1000;
const FULL_CHUNK_HEIGHT = 16;

View file

@ -21,7 +21,6 @@ import {
Util,
} from "../shared/util.js";
import { getCurrentTransform } from "./display_utils.js";
import { isNodeJS } from "../shared/is_node.js";
const PathType = {
FILL: "Fill",
@ -30,7 +29,7 @@ const PathType = {
};
function applyBoundingBox(ctx, bbox) {
if (!bbox || isNodeJS) {
if (!bbox) {
return;
}
const width = bbox[2] - bbox[0];

View file

@ -46,6 +46,18 @@ import { isNodeJS } from "./is_node.js";
globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix;
})();
// Support: Node.js
(function checkPath2D() {
if (globalThis.Path2D || !isNodeJS) {
return;
}
const { CanvasRenderingContext2D } = __non_webpack_require__("canvas");
const { polyfillPath2D } = __non_webpack_require__("path2d-polyfill");
globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
polyfillPath2D(globalThis);
})();
// Support: Node.js
(function checkReadableStream() {
if (globalThis.ReadableStream || !isNodeJS) {