Skip to content

Commit 1f08405

Browse files
committed
Merge pull request mozilla#2313 from yurydelendik/issue-1905
Fixes incomplete restore in paintFormXObject
2 parents 5caef86 + 4c533d0 commit 1f08405

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/canvas.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
187187
this.fillAlpha = 1;
188188
this.strokeAlpha = 1;
189189
this.lineWidth = 1;
190+
this.paintFormXObjectDepth = 0;
190191

191192
this.old = old;
192193
}
@@ -1109,6 +1110,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
11091110
paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
11101111
bbox) {
11111112
this.save();
1113+
this.current.paintFormXObjectDepth++;
11121114

11131115
if (matrix && isArray(matrix) && 6 == matrix.length)
11141116
this.transform.apply(this, matrix);
@@ -1123,7 +1125,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
11231125
},
11241126

11251127
paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
1126-
this.restore();
1128+
var depth = this.current.paintFormXObjectDepth;
1129+
do {
1130+
this.restore();
1131+
// some pdf don't close all restores inside object
1132+
// closing those for them
1133+
} while (this.current.paintFormXObjectDepth >= depth);
11271134
},
11281135

11291136
paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
!pdfkit_compressed.pdf
2525
!TAMReview.pdf
2626
!issue918.pdf
27+
!issue1905.pdf
2728
!issue1249.pdf
2829
!smaskdim.pdf
2930
!type4psfunc.pdf

test/pdfs/issue1905.pdf

897 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@
367367
"pageLimit": 3,
368368
"type": "eq"
369369
},
370+
{ "id": "issue1905",
371+
"file": "pdfs/issue1905.pdf",
372+
"md5": "b1bbd72ca6522ae1502aa26320f81994",
373+
"rounds": 1,
374+
"type": "eq"
375+
},
370376
{ "id": "issue918",
371377
"file": "pdfs/issue918.pdf",
372378
"md5": "d582cc0f2592ae82936589ced2a47e55",

0 commit comments

Comments
 (0)