mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Merge pull request #19015 from Snuffleupagus/@napi-rs/canvas
[api-minor] Replace the `canvas` package with `@napi-rs/canvas`
This commit is contained in:
commit
5524216c23
8 changed files with 196 additions and 105 deletions
|
@ -586,7 +586,7 @@ class CanvasExtraState {
|
|||
}
|
||||
|
||||
function putBinaryImageData(ctx, imgData) {
|
||||
if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
|
||||
if (imgData instanceof ImageData) {
|
||||
ctx.putImageData(imgData, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -31,50 +31,36 @@ if (
|
|||
!PDFJSDev.test("SKIP_BABEL") &&
|
||||
isNodeJS
|
||||
) {
|
||||
let canvas, path2d;
|
||||
let canvas;
|
||||
try {
|
||||
const require = process
|
||||
.getBuiltinModule("module")
|
||||
.createRequire(import.meta.url);
|
||||
|
||||
try {
|
||||
canvas = require("canvas");
|
||||
canvas = require("@napi-rs/canvas");
|
||||
} catch (ex) {
|
||||
warn(`Cannot load "canvas" package: "${ex}".`);
|
||||
}
|
||||
try {
|
||||
path2d = require("path2d");
|
||||
} catch (ex) {
|
||||
warn(`Cannot load "path2d" package: "${ex}".`);
|
||||
warn(`Cannot load "@napi-rs/canvas" package: "${ex}".`);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
if (!globalThis.DOMMatrix) {
|
||||
const DOMMatrix = canvas?.DOMMatrix;
|
||||
|
||||
if (DOMMatrix) {
|
||||
globalThis.DOMMatrix = DOMMatrix;
|
||||
if (canvas?.DOMMatrix) {
|
||||
globalThis.DOMMatrix = canvas.DOMMatrix;
|
||||
} else {
|
||||
warn("Cannot polyfill `DOMMatrix`, rendering may be broken.");
|
||||
}
|
||||
}
|
||||
if (!globalThis.ImageData) {
|
||||
if (canvas?.ImageData) {
|
||||
globalThis.ImageData = canvas.ImageData;
|
||||
} else {
|
||||
warn("Cannot polyfill `ImageData`, rendering may be broken.");
|
||||
}
|
||||
}
|
||||
if (!globalThis.Path2D) {
|
||||
const CanvasRenderingContext2D = canvas?.CanvasRenderingContext2D;
|
||||
const applyPath2DToCanvasRenderingContext =
|
||||
path2d?.applyPath2DToCanvasRenderingContext;
|
||||
const Path2D = path2d?.Path2D;
|
||||
|
||||
if (
|
||||
CanvasRenderingContext2D &&
|
||||
applyPath2DToCanvasRenderingContext &&
|
||||
Path2D
|
||||
) {
|
||||
try {
|
||||
applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D);
|
||||
} catch (ex) {
|
||||
warn(`applyPath2DToCanvasRenderingContext: "${ex}".`);
|
||||
}
|
||||
globalThis.Path2D = Path2D;
|
||||
if (canvas?.Path2D) {
|
||||
globalThis.Path2D = canvas.Path2D;
|
||||
} else {
|
||||
warn("Cannot polyfill `Path2D`, rendering may be broken.");
|
||||
}
|
||||
|
@ -97,7 +83,7 @@ class NodeCanvasFactory extends BaseCanvasFactory {
|
|||
const require = process
|
||||
.getBuiltinModule("module")
|
||||
.createRequire(import.meta.url);
|
||||
const canvas = require("canvas");
|
||||
const canvas = require("@napi-rs/canvas");
|
||||
return canvas.createCanvas(width, height);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue