Skip to content

Commit 5bbed40

Browse files
Merge pull request mozilla#14797 from calixteman/12306
Don't clip when the clip path is empty (issue mozilla#12306)
2 parents f828792 + 3d74d2c commit 5bbed40

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/display/canvas.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,10 @@ class CanvasExtraState {
649649
this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
650650
}
651651

652+
isEmptyClip() {
653+
return this.minX === Infinity;
654+
}
655+
652656
startNewPathAndClipBox(box) {
653657
this.clipBox = box;
654658
this.minX = Infinity;
@@ -2476,7 +2480,7 @@ class CanvasGraphics {
24762480
// TODO According to the spec we're also suppose to ignore any operators
24772481
// that set color or include images while processing this type3 font.
24782482
this.ctx.rect(llx, lly, urx - llx, ury - lly);
2479-
this.clip();
2483+
this.ctx.clip();
24802484
this.endPath();
24812485
}
24822486

@@ -2862,7 +2866,7 @@ class CanvasGraphics {
28622866
resetCtxToDefault(this.ctx);
28632867

28642868
this.ctx.rect(rect[0], rect[1], width, height);
2865-
this.clip();
2869+
this.ctx.clip();
28662870
this.endPath();
28672871
}
28682872
}
@@ -3212,6 +3216,7 @@ class CanvasGraphics {
32123216
// Helper functions
32133217

32143218
consumePath(clipBox) {
3219+
const isEmpty = this.current.isEmptyClip();
32153220
if (this.pendingClip) {
32163221
this.current.updateClipFromPath();
32173222
}
@@ -3220,10 +3225,12 @@ class CanvasGraphics {
32203225
}
32213226
const ctx = this.ctx;
32223227
if (this.pendingClip) {
3223-
if (this.pendingClip === EO_CLIP) {
3224-
ctx.clip("evenodd");
3225-
} else {
3226-
ctx.clip();
3228+
if (!isEmpty) {
3229+
if (this.pendingClip === EO_CLIP) {
3230+
ctx.clip("evenodd");
3231+
} else {
3232+
ctx.clip();
3233+
}
32273234
}
32283235
this.pendingClip = null;
32293236
}

test/pdfs/issue12306.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/mozilla/pdf.js/files/5150027/document13-08-2020-122237.pdf

test/test_manifest.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6362,5 +6362,13 @@
63626362
"link": true,
63636363
"lastPage": 1,
63646364
"type": "eq"
6365+
},
6366+
{ "id": "issue12306",
6367+
"file": "pdfs/issue12306.pdf",
6368+
"md5": "7fd05ba56791238b5a60adc6cc0e7a22",
6369+
"rounds": 1,
6370+
"link": true,
6371+
"lastPage": 1,
6372+
"type": "eq"
63656373
}
63666374
]

0 commit comments

Comments
 (0)