Apply group blend mode when compositing group to main canvas

This commit is contained in:
ritwic 2025-06-19 07:51:44 +08:00
parent 04511c607b
commit f0964c7dfd

View File

@ -2464,7 +2464,12 @@ class CanvasGraphics {
currentMtx, currentMtx,
dirtyBox 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.ctx.drawImage(groupCtx.canvas, 0, 0);
this.popGroupBlendMode(this.ctx, prevBlendMode);
this.ctx.restore(); this.ctx.restore();
this.compose(dirtyBox); 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() { isContentVisible() {
for (let i = this.markedContentStack.length - 1; i >= 0; i--) { for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
if (!this.markedContentStack[i].visible) { if (!this.markedContentStack[i].visible) {