From 0c78b46184372665d72ed73242a90598d29643d8 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 3 Apr 2025 12:20:24 +0200 Subject: [PATCH] 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. --- src/display/canvas.js | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 11f5c6cd3..34a905c1c 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -20,7 +20,6 @@ import { IDENTITY_MATRIX, ImageKind, info, - isNodeJS, OPS, shadow, TextRenderingMode, @@ -598,14 +597,9 @@ function resetCtxToDefault(ctx) { ctx.setLineDash([]); ctx.lineDashOffset = 0; } - if ( - (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || - !isNodeJS - ) { - const { filter } = ctx; - if (filter !== "none" && filter !== "") { - ctx.filter = "none"; - } + const { filter } = ctx; + if (filter !== "none" && filter !== "") { + ctx.filter = "none"; } } @@ -2732,18 +2726,13 @@ class CanvasGraphics { this.save(); - if ( - (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || - !isNodeJS - ) { - // The filter, if any, will be applied in applyTransferMapsToBitmap. - // It must be applied to the image before rescaling else some artifacts - // could appear. - // The final restore will reset it to its value. - const { filter } = ctx; - if (filter !== "none" && filter !== "") { - ctx.filter = "none"; - } + // The filter, if any, will be applied in applyTransferMapsToBitmap. + // It must be applied to the image before rescaling else some artifacts + // could appear. + // The final restore will reset it to its value. + const { filter } = ctx; + if (filter !== "none" && filter !== "") { + ctx.filter = "none"; } // scale the image to the unit square