diff --git a/src/core/evaluator.js b/src/core/evaluator.js index edf02c2c052bf..0dfd1a5e8da98 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -510,6 +510,27 @@ class PartialEvaluator { smask.backdrop = colorSpace.getRgbHex(smask.backdrop, 0); } + // Parse group blend mode from ExtGState if it's in FormX Resources + const localResources = dict.get("Resources"); + if (localResources instanceof Dict) { + const extGState = localResources.get("ExtGState"); + if (extGState instanceof Dict) { + for (const val of extGState.getRawValues()) { + if (val instanceof Dict && val.has("BM")) { + const blendMode = val.get("BM"); + if (blendMode != null) { + try { + groupOptions.blendMode = normalizeBlendMode(blendMode); + break; + } catch (ex) { + console.error(`Invalid blend mode in ExtGState: ${blendMode}`, ex); + } + } + } + } + } + } + operatorList.addOp(OPS.beginGroup, [groupOptions]); } diff --git a/src/display/canvas.js b/src/display/canvas.js index df0556ad0c653..4c7d5afdf38f2 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) {