Merge pull request #19708 from calixteman/fix_save_smask_mode

Fix save/restore while in smask mode
This commit is contained in:
calixteman 2025-03-23 14:45:09 +01:00 committed by GitHub
commit 7c5695f5c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1545,30 +1545,27 @@ class CanvasGraphics {
// Copy the temporary canvas state to the main(suspended) canvas to keep // Copy the temporary canvas state to the main(suspended) canvas to keep
// it in sync. // it in sync.
copyCtxState(this.ctx, this.suspendedCtx); copyCtxState(this.ctx, this.suspendedCtx);
// Don't bother calling save on the temporary canvas since state is not
// saved there.
this.suspendedCtx.save();
} else {
this.ctx.save();
} }
this.ctx.save();
const old = this.current; const old = this.current;
this.stateStack.push(old); this.stateStack.push(old);
this.current = old.clone(); this.current = old.clone();
} }
restore() { restore() {
if (this.stateStack.length === 0 && this.inSMaskMode) { if (this.stateStack.length === 0) {
if (this.inSMaskMode) {
this.endSMaskMode(); this.endSMaskMode();
} }
if (this.stateStack.length !== 0) { return;
}
this.current = this.stateStack.pop(); this.current = this.stateStack.pop();
this.ctx.restore();
if (this.inSMaskMode) { if (this.inSMaskMode) {
// Graphics state is stored on the main(suspended) canvas. Restore its // Graphics state is stored on the main(suspended) canvas. Restore its
// state then copy it over to the temporary canvas. // state then copy it over to the temporary canvas.
this.suspendedCtx.restore();
copyCtxState(this.suspendedCtx, this.ctx); copyCtxState(this.suspendedCtx, this.ctx);
} else {
this.ctx.restore();
} }
this.checkSMaskState(); this.checkSMaskState();
@ -1578,7 +1575,6 @@ class CanvasGraphics {
this._cachedScaleForStroking[0] = -1; this._cachedScaleForStroking[0] = -1;
this._cachedGetSinglePixelWidth = null; this._cachedGetSinglePixelWidth = null;
} }
}
transform(a, b, c, d, e, f) { transform(a, b, c, d, e, f) {
this.ctx.transform(a, b, c, d, e, f); this.ctx.transform(a, b, c, d, e, f);