Browse Source
In the PDF from issue 8527, the clip operator (W) shows up before a path is defined. The current SVG backend however expects a path to exist before generating a `<svg:clipPath>` element. In the example, the path was defined after the clip, followed by a endPath operator (n). So this commit fixes the bug by moving the path generation logic from clip to endPath. Our canvas backend appears to use similar logic: `CanvasGraphics_endPath` calls `consumePath`, which in turn draws the clip and resets the `pendingClip` state. The canvas backend calls `consumePath` from multiple other places, so we probably need to check whether doing so is also necessary for the SVG backend. I scanned our corpus of PDF files in test/pdfs, and found that in every instance (except for one), the "W" PDF operator (clip) is immediately followed by "n" (endPath). The new test from this commit (clippath.pdf) starts with "W", followed by a path definition and then "n". # Commands used to find some of the clipping commands: grep -ra '^W$' -C7 | less -S grep -ra '^W ' -C7 | less -S grep -ra ' W$' -C7 | less -S test/pdfs/issue6413.pdf is the only file where "W" (a tline 55) is not followed by "n". In fact, the "W" is the last operation of a series of XObject painting operations, and removing it does not have any effect on the rendered PDF (confirmed by looking at the output of PDF.js's canvas backend, and ImageMagick's convert command).
4 changed files with 59 additions and 5 deletions
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
%PDF-1.1 |
||||
1 0 obj |
||||
<</Type/Catalog/Pages 2 0 R>> |
||||
endobj |
||||
2 0 obj |
||||
<</Type/Pages/Count 1/Kids[3 0 R]/MediaBox [0 0 200 100]>> |
||||
endobj |
||||
3 0 obj |
||||
<</Type/Page/Parent 2 0 R/Contents 4 0 R>> |
||||
endobj |
||||
4 0 obj |
||||
<</Length 65>> |
||||
stream |
||||
W |
||||
40 20 m |
||||
160 20 l |
||||
160 80 l |
||||
40 80 l |
||||
h |
||||
n |
||||
0 0 0 sc |
||||
0 0 200 100 re |
||||
f |
||||
endstream |
||||
endobj |
||||
xref |
||||
0 5 |
||||
0000000000 65535 f |
||||
0000000009 00000 n |
||||
0000000054 00000 n |
||||
0000000128 00000 n |
||||
0000000186 00000 n |
||||
trailer |
||||
<</Root 1 0 R/Size 5>> |
||||
startxref |
||||
299 |
||||
%%EOF |
Loading…
Reference in new issue