Skip to content

Commit

Permalink
Address #3182: Pixmap.invert_irect argument type error.
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Feb 20, 2024
1 parent a7f9269 commit 0766ae7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/__init__.py
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
7 changes: 7 additions & 0 deletions tests/test_geometry.py
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)

0 comments on commit 0766ae7

Please sign in to comment.