From f0964c7dfde6c0c8c006b55c5ed0cdd2bc131554 Mon Sep 17 00:00:00 2001 From: ritwic Date: Thu, 19 Jun 2025 07:51:44 +0800 Subject: [PATCH] Apply group blend mode when compositing group to main canvas --- src/display/canvas.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/display/canvas.js b/src/display/canvas.js index df0556ad0..4c7d5afdf 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -2464,7 +2464,12 @@ class CanvasGraphics { currentMtx, dirtyBox ); + + // Apply the group blend mode and alpha when compositing the group + const prevBlendMode = this.pushGroupBlendMode(this.ctx, group.blendMode); this.ctx.drawImage(groupCtx.canvas, 0, 0); + this.popGroupBlendMode(this.ctx, prevBlendMode); + this.ctx.restore(); this.compose(dirtyBox); } @@ -3044,6 +3049,22 @@ class CanvasGraphics { } } + pushGroupBlendMode(ctx, blendMode) { + if (!ctx || !blendMode) { + return null; + } + + const prev = ctx.globalCompositeOperation; + ctx.globalCompositeOperation = blendMode; + return prev; + } + + popGroupBlendMode(ctx, prev) { + if (ctx && prev !== null) { + ctx.globalCompositeOperation = prev; + } + } + isContentVisible() { for (let i = this.markedContentStack.length - 1; i >= 0; i--) { if (!this.markedContentStack[i].visible) {