Skip to content

Commit

Permalink
Consume any pending path before drawing an annotation
Browse files Browse the repository at this point in the history
Fixes #18058.
  • Loading branch information
calixteman committed Sep 10, 2024
1 parent 5b4c2fe commit 218283d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2651,14 +2651,15 @@ class CanvasGraphics {
// The page content drawing can potentially have set a transform,
// a clipping path, whatever...
// So in order to have something clean, we restore the initial state.
const { ctx } = this;
this.#restoreInitialState();
resetCtxToDefault(this.ctx);
resetCtxToDefault(ctx);

this.ctx.save();
ctx.save();
this.save();

if (this.baseTransform) {
this.ctx.setTransform(...this.baseTransform);
ctx.setTransform(...this.baseTransform);
}

if (rect) {
Expand All @@ -2676,7 +2677,7 @@ class CanvasGraphics {
rect[3] = height;

const [scaleX, scaleY] = Util.singularValueDecompose2dScale(
getCurrentTransform(this.ctx)
getCurrentTransform(ctx)
);
const { viewportScale } = this;
const canvasWidth = Math.ceil(
Expand All @@ -2692,18 +2693,21 @@ class CanvasGraphics {
);
const { canvas, context } = this.annotationCanvas;
this.annotationCanvasMap.set(id, canvas);
this.annotationCanvas.savedCtx = this.ctx;
this.annotationCanvas.savedCtx = ctx;
this.ctx = context;
this.ctx.save();
this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
context.save();
context.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);

resetCtxToDefault(this.ctx);
resetCtxToDefault(context);
} else {
resetCtxToDefault(this.ctx);
resetCtxToDefault(ctx);

this.ctx.rect(rect[0], rect[1], width, height);
this.ctx.clip();
// Consume a potential path before clipping.
this.endPath();

ctx.rect(rect[0], rect[1], width, height);
ctx.clip();
ctx.beginPath();
}
}

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue18058.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/15269193/file.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10474,5 +10474,13 @@
"pageIndex": 0
}
}
},
{
"id": "issue18058",
"file": "pdfs/issue18058.pdf",
"md5": "da8fcdf25c83ecb2d4be315be5affc3c",
"rounds": 1,
"link": true,
"type": "eq"
}
]

0 comments on commit 218283d

Please sign in to comment.