Skip to content

Commit 6f11085

Browse files
src/__init__.py tests/: added test for pymupdf#4047.
Also added assert that will catch the problem in future.
1 parent 69891d3 commit 6f11085

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7750,6 +7750,7 @@ def _add_redact_annot(self, quad, text=None, da_str=None, align=0, fill=None, te
77507750
mupdf.pdf_array_push_real(arr, fcol[i])
77517751
mupdf.pdf_dict_put(mupdf.pdf_annot_obj(annot), PDF_NAME('IC'), arr)
77527752
if text:
7753+
assert da_str
77537754
mupdf.pdf_dict_puts(
77547755
mupdf.pdf_annot_obj(annot),
77557756
"OverlayText",

tests/resources/test_4047.pdf

92.8 KB
Binary file not shown.

tests/test_annots.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,17 @@ def test_parent():
458458
assert str(e) == 'weakly-referenced object no longer exists'
459459
else:
460460
assert 0, f'Failed to get expected exception.'
461+
462+
def test_4047():
463+
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4047.pdf')
464+
with pymupdf.open(path) as document:
465+
page = document[0]
466+
fontname = page.get_fonts()[0][3]
467+
if fontname not in pymupdf.Base14_fontnames:
468+
fontname = "Courier"
469+
hits = page.search_for("|")
470+
for rect in hits:
471+
page.add_redact_annot(
472+
rect, " ", fontname=fontname, align=pymupdf.TEXT_ALIGN_CENTER, fontsize=10
473+
) # Segmentation Fault...
474+
page.apply_redactions()

0 commit comments

Comments
 (0)