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

Jules - fixes for mupdf master. #4053

Merged
merged 3 commits into from
Nov 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7750,6 +7750,7 @@ def _add_redact_annot(self, quad, text=None, da_str=None, align=0, fill=None, te
mupdf.pdf_array_push_real(arr, fcol[i])
mupdf.pdf_dict_put(mupdf.pdf_annot_obj(annot), PDF_NAME('IC'), arr)
if text:
assert da_str
mupdf.pdf_dict_puts(
mupdf.pdf_annot_obj(annot),
"OverlayText",
Expand Down Expand Up @@ -16547,7 +16548,10 @@ def __str__(self):
style.size = ch.m_internal.size
style.flags = flags
style.font = JM_font_name(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
style.color = ch.m_internal.color
if mupdf_version_tuple >= (1, 26):
style.color = ch.m_internal.argb
else:
style.color = ch.m_internal.color
style.asc = JM_font_ascender(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
style.desc = JM_font_descender(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))

Expand Down Expand Up @@ -21057,10 +21061,12 @@ def sRGB_to_rgb(srgb: int) -> tuple:
There is **no error checking** for performance reasons!

Args:
srgb: (int) RRGGBB (red, green, blue), each color in range(255).
srgb: (int) SSRRGGBB (red, green, blue), each color in range(255).
With MuPDF < 1.26, `s` is always 0.
Returns:
Tuple (red, green, blue) each item in interval 0 <= item <= 255.
"""
srgb &= 0xffffff
r = srgb >> 16
g = (srgb - (r << 16)) >> 8
b = srgb - (r << 16) - (g << 8)
Expand Down
8 changes: 6 additions & 2 deletions src/extra.i
Original file line number Diff line number Diff line change
Expand Up @@ -3045,7 +3045,7 @@ mupdf::FzRect JM_make_spanlist(
float size = -1;
int flags = -1;
const char *font = "";
int color = -1;
unsigned int color = -1;
float asc = 0;
float desc = 0;
};
Expand All @@ -3064,7 +3064,11 @@ mupdf::FzRect JM_make_spanlist(
style.size = ch.m_internal->size;
style.flags = flags;
style.font = JM_font_name(ch.m_internal->font);
style.color = ch.m_internal->color;
#if (FZ_VERSION_MAJOR > 1 || (FZ_VERSION_MAJOR == 1 && FZ_VERSION_MINOR >= 26))
style.color = ch.m_internal->argb;
#else
style.color = ch.m_internal->color;
#endif
style.asc = JM_font_ascender(ch.m_internal->font);
style.desc = JM_font_descender(ch.m_internal->font);

Expand Down
Binary file added tests/resources/test_4047.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/test_annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,17 @@ def test_parent():
assert str(e) == 'weakly-referenced object no longer exists'
else:
assert 0, f'Failed to get expected exception.'

def test_4047():
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4047.pdf')
with pymupdf.open(path) as document:
page = document[0]
fontname = page.get_fonts()[0][3]
if fontname not in pymupdf.Base14_fontnames:
fontname = "Courier"
hits = page.search_for("|")
for rect in hits:
page.add_redact_annot(
rect, " ", fontname=fontname, align=pymupdf.TEXT_ALIGN_CENTER, fontsize=10
) # Segmentation Fault...
page.apply_redactions()
19 changes: 13 additions & 6 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,15 @@ def test_2238():
rebased = hasattr(pymupdf, 'mupdf')
if rebased:
wt = pymupdf.TOOLS.mupdf_warnings()
assert wt == (
'format error: cannot recognize version marker\n'
'trying to repair broken xref\n'
'repairing PDF document'
), f'{wt=}'
wt_expected = ''
if pymupdf.mupdf_version_tuple >= (1, 26):
wt_expected += 'garbage bytes before version marker\n'
wt_expected += 'syntax error: expected \'obj\' keyword (6 0 ?)\n'
else:
wt_expected += 'format error: cannot recognize version marker\n'
wt_expected += 'trying to repair broken xref\n'
wt_expected += 'repairing PDF document'
assert wt == wt_expected, f'{wt=}'
first_page = doc.load_page(0).get_text('text', pymupdf.INFINITE_RECT())
last_page = doc.load_page(-1).get_text('text', pymupdf.INFINITE_RECT())

Expand Down Expand Up @@ -1555,7 +1559,10 @@ def test_3905():
else:
assert 0
wt = pymupdf.TOOLS.mupdf_warnings()
assert wt == 'format error: cannot recognize version marker\ntrying to repair broken xref\nrepairing PDF document'
if pymupdf.mupdf_version_tuple >= (1, 26):
assert wt == 'format error: cannot find version marker\ntrying to repair broken xref\nrepairing PDF document'
else:
assert wt == 'format error: cannot recognize version marker\ntrying to repair broken xref\nrepairing PDF document'

def test_3624():
path = os.path.normpath(f'{__file__}/../../tests/resources/test_3624.pdf')
Expand Down