Use ctx.filter unconditionally in the src/display/canvas.js file

It seems that the `@napi-rs/canvas` dependency has *basic* canvas-filter support, whereas the "old" `canvas` dependency didn't, hence we no longer need the Node.js-specific checks in the `src/display/canvas.js` file.

Note that I've successfully tested the [`pdf2png` example](https://github.com/mozilla/pdf.js/tree/master/examples/node/pdf2png) with this patch applied and things appear to work as before.
This commit is contained in:
Jonas Jenwald 2025-04-03 12:20:24 +02:00
parent a45f961a1c
commit 0c78b46184

View File

@ -20,7 +20,6 @@ import {
IDENTITY_MATRIX, IDENTITY_MATRIX,
ImageKind, ImageKind,
info, info,
isNodeJS,
OPS, OPS,
shadow, shadow,
TextRenderingMode, TextRenderingMode,
@ -598,16 +597,11 @@ function resetCtxToDefault(ctx) {
ctx.setLineDash([]); ctx.setLineDash([]);
ctx.lineDashOffset = 0; ctx.lineDashOffset = 0;
} }
if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
!isNodeJS
) {
const { filter } = ctx; const { filter } = ctx;
if (filter !== "none" && filter !== "") { if (filter !== "none" && filter !== "") {
ctx.filter = "none"; ctx.filter = "none";
} }
} }
}
function getImageSmoothingEnabled(transform, interpolate) { function getImageSmoothingEnabled(transform, interpolate) {
// In section 8.9.5.3 of the PDF spec, it's mentioned that the interpolate // In section 8.9.5.3 of the PDF spec, it's mentioned that the interpolate
@ -2732,10 +2726,6 @@ class CanvasGraphics {
this.save(); this.save();
if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
!isNodeJS
) {
// The filter, if any, will be applied in applyTransferMapsToBitmap. // The filter, if any, will be applied in applyTransferMapsToBitmap.
// It must be applied to the image before rescaling else some artifacts // It must be applied to the image before rescaling else some artifacts
// could appear. // could appear.
@ -2744,7 +2734,6 @@ class CanvasGraphics {
if (filter !== "none" && filter !== "") { if (filter !== "none" && filter !== "") {
ctx.filter = "none"; ctx.filter = "none";
} }
}
// scale the image to the unit square // scale the image to the unit square
ctx.scale(1 / width, -1 / height); ctx.scale(1 / width, -1 / height);