@@ -147,8 +147,13 @@ function mirrorContextOperations(ctx, destCtx) {
147147 } ;
148148
149149 ctx . setTransform = function ( a , b , c , d , e , f ) {
150- destCtx . setTransform ( a , b , c , d , e , f ) ;
151- this . __originalSetTransform ( a , b , c , d , e , f ) ;
150+ if ( b === undefined ) {
151+ destCtx . setTransform ( a ) ;
152+ this . __originalSetTransform ( a ) ;
153+ } else {
154+ destCtx . setTransform ( a , b , c , d , e , f ) ;
155+ this . __originalSetTransform ( a , b , c , d , e , f ) ;
156+ }
152157 } ;
153158
154159 ctx . resetTransform = function ( ) {
@@ -1467,6 +1472,13 @@ class CanvasGraphics {
14671472 // Graphics state is stored on the main(suspended) canvas. Restore its
14681473 // state then copy it over to the temporary canvas.
14691474 copyCtxState ( this . suspendedCtx , this . ctx ) ;
1475+ // The scratch canvas may have been freshly created by beginSMaskMode
1476+ // (called from checkSMaskState during a previous endGroup), in which
1477+ // case its save/restore stack is empty and ctx.restore() above was a
1478+ // no-op. Explicitly sync the CTM from the main canvas so that any CTM
1479+ // change that the mirrored restore applied to the main canvas is also
1480+ // reflected on the scratch canvas.
1481+ this . ctx . setTransform ( this . suspendedCtx . getTransform ( ) ) ;
14701482 }
14711483 this . checkSMaskState ( opIdx ) ;
14721484
@@ -2805,6 +2817,13 @@ class CanvasGraphics {
28052817 this . restore ( opIdx ) ;
28062818 if ( this . dependencyTracker ) {
28072819 this . ctx . restore ( ) ;
2820+ // beginSMaskMode() may have been called inside restore(opIdx) above
2821+ // (via checkSMaskState), creating a fresh scratch canvas. If so,
2822+ // the mirrored ctx.restore() just synced main's CTM but left the
2823+ // scratch at the stale CTM set by beginSMaskMode(). Re-sync it.
2824+ if ( this . inSMaskMode ) {
2825+ this . ctx . setTransform ( this . suspendedCtx . getTransform ( ) ) ;
2826+ }
28082827 }
28092828 } else {
28102829 this . ctx . restore ( ) ;
0 commit comments