Skip to content

Commit

Permalink
Address #3134 - incorrect conversion of IRect to Rect.
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Feb 14, 2024
1 parent 6302ecd commit fdd0de3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17088,8 +17088,12 @@ def JM_read_contents(pageref):
def JM_rect_from_py(r):
if isinstance(r, mupdf.FzRect):
return r
if isinstance(r, mupdf.FzIrect):
return mupdf.FzRect(r)
if isinstance(r, Rect):
return mupdf.fz_make_rect(r.x0, r.y0, r.x1, r.y1)
if isinstance(r, IRect):
return mupdf.fz_make_rect(r.x0, r.y0, r.x1, r.y1)
if not r or not PySequence_Check(r) or PySequence_Size(r) != 4:
return mupdf.FzRect(mupdf.FzRect.Fixed_INFINITE)
f = [0, 0, 0, 0]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_pixmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,15 @@ def test_3072():
pix = page_49.get_pixmap(clip=rect, matrix=zoom)
image_save_path = f'{out}/2.jpg'
pix.save(image_save_path, jpg_quality=95)

def test_3134():
doc = fitz.Document()
page = doc.new_page()
page.get_pixmap(clip=fitz.Rect(0, 0, 100, 100)).save("test_3134_rect.jpg")
page.get_pixmap(clip=fitz.IRect(0, 0, 100, 100)).save("test_3134_irect.jpg")
stat_rect = os.stat('test_3134_rect.jpg')
stat_irect = os.stat('test_3134_irect.jpg')
print(f' {stat_rect=}')
print(f'{stat_irect=}')
assert stat_rect.st_size == stat_irect.st_size

0 comments on commit fdd0de3

Please sign in to comment.