Skip to content

Commit 419c265

Browse files
authored
Merge pull request #21094 from calixteman/issue17784
Correctly sync the transform on the scratch canvas
2 parents 1025af0 + 865b488 commit 419c265

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/display/canvas.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

test/pdfs/issue17784.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://web.archive.org/web/20240320131329/https://lp.entro.security/hubfs/Gated%20Assets/Onboarding-offboarding-checklist.pdf

test/test_manifest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14126,5 +14126,15 @@
1412614126
"md5": "5a690e2303604441308f808b5fc33e22",
1412714127
"rounds": 1,
1412814128
"type": "eq"
14129+
},
14130+
{
14131+
"id": "issue17784",
14132+
"file": "pdfs/issue17784.pdf",
14133+
"md5": "e92178bb5ca8d6cd6f79868470adbe1d",
14134+
"link": true,
14135+
"rounds": 1,
14136+
"firstPage": 3,
14137+
"lastPage": 3,
14138+
"type": "eq"
1412914139
}
1413014140
]

0 commit comments

Comments
 (0)