Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
21 changes: 21 additions & 0 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down