Skip to content

Commit c55d70e

Browse files
tests/: reproducer for #5108, Page.clip_to_rect() drops 'sh' (shading) operators
1 parent 6a8775b commit c55d70e

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎tests/resources/test_5108.pdf‎

639 Bytes
Binary file not shown.

‎tests/test_clip_page.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,33 @@ def test_clip():
3636
assert bbox.intersects(
3737
rect
3838
), f"Character '{char['c']}' at {bbox} is outside of {rect}."
39+
40+
41+
def test_5108():
42+
print()
43+
path = os.path.normpath(f'{__file__}/../../tests/resources/test_5108.pdf')
44+
def clipped_content(i, clip):
45+
with pymupdf.open(path) as document:
46+
page = document[0]
47+
page.clip_to_rect(clip)
48+
with pymupdf.open(stream=document.tobytes(garbage=3, clean=True)) as document2:
49+
page = document2[0]
50+
ret = b''.join(document2.xref_stream(x) for x in page.get_contents())
51+
page.draw_rect(clip, (1, 0, 0))
52+
document2.save(f'{path}.out.{i}.pdf')
53+
return ret
54+
for i, (label, clip) in enumerate([
55+
('whole page ', pymupdf.Rect(0, 0, 400, 400)),
56+
('right half (holds shading) ', pymupdf.Rect(200, 0, 400, 400)),
57+
('page inset by 1pt ', pymupdf.Rect(1, 1, 399, 399)),
58+
('1x1 at PDF origin, no shading in it ', pymupdf.Rect(0, 399, 1, 400)),
59+
(' ', pymupdf.Rect(0, 0, 10, 10)),
60+
(' ', pymupdf.Rect(0, 2, 10, 7)),
61+
]):
62+
content = clipped_content(i, clip)
63+
sh_kept = str(b'sh' in content)
64+
print(f' {label} -> {sh_kept=:5s} {content!r}')
65+
66+
67+
68+

0 commit comments

Comments
 (0)