Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address #3182: Pixmap.invert_irect argument type error. #3187

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16259,23 +16259,27 @@ def JM_invert_pixmap_rect( dest, b):

def JM_irect_from_py(r):
'''
PySequence to fz_irect. Default: infinite irect
PySequence to mupdf.FzIrect. Default: infinite irect
'''
if isinstance(r, mupdf.FzIrect):
return r
if isinstance(r, IRect):
r = mupdf.FzIrect( r.x0, r.y0, r.x1, r.y1)
return r
if isinstance(r, Rect):
ret = mupdf.fz_make_irect(r.x0, r.y0, r.x1, r.y1)
ret = mupdf.FzRect(r.x0, r.y0, r.x1, r.y1)
ret = mupdf.FzIrect(ret) # Uses fz_irect_from_rect().
return ret
if isinstance(r, mupdf.FzRect):
ret = mupdf.FzIrect(r) # Uses fz_irect_from_rect().
return ret
if not r or not PySequence_Check(r) or PySequence_Size(r) != 4:
return mupdf.FzIrect(mupdf.fz_infinite_irect)
f = [0, 0, 0, 0]
for i in range(4):
f[i] = r[i]
if f[i] is None:
return mupdf.FzRect(mupdf.fz_infinite_irect)
return mupdf.FzIrect(mupdf.fz_infinite_irect)
if f[i] < FZ_MIN_INF_RECT:
f[i] = FZ_MIN_INF_RECT
if f[i] > FZ_MAX_INF_RECT:
Expand Down Expand Up @@ -17814,9 +17818,6 @@ def PyUnicode_DecodeRawUnicodeEscape(s, errors='strict'):
elif isinstance(s, bytes):
rc = s[:]
ret = rc.decode('raw_unicode_escape', errors=errors)
z = ret.find(chr(0))
if z >= 0:
ret = ret[:z]
return ret


Expand Down
Binary file added tests/resources/test_3186.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Check matrix inversions in variations
* Check algebra constructs
"""
import os

import fitz


Expand Down Expand Up @@ -339,3 +341,8 @@ def test_pageboxes():
def test_3163():
b = {'number': 0, 'type': 0, 'bbox': (403.3577880859375, 330.8871765136719, 541.2731323242188, 349.5766296386719), 'lines': [{'spans': [{'size': 14.0, 'flags': 4, 'font': 'SFHello-Medium', 'color': 1907995, 'ascender': 1.07373046875, 'descender': -0.26123046875, 'text': 'Inclusion and diversity', 'origin': (403.3577880859375, 345.9194030761719), 'bbox': (403.3577880859375, 330.8871765136719, 541.2731323242188, 349.5766296386719)}], 'wmode': 0, 'dir': (1.0, 0.0), 'bbox': (403.3577880859375, 330.8871765136719, 541.2731323242188, 349.5766296386719)}]}
bbox = fitz.IRect(b["bbox"])

def test_3182():
pix = fitz.Pixmap(os.path.abspath(f'{__file__}/../../tests/resources/img-transparent.png'))
rect = fitz.Rect(0, 0, 100, 100)
pix.invert_irect(rect)