diff --git a/src/__init__.py b/src/__init__.py index 4628d73e9..bd66a643e 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -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", @@ -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))) @@ -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) diff --git a/src/extra.i b/src/extra.i index 0b5b8c6f9..5c1d7910f 100644 --- a/src/extra.i +++ b/src/extra.i @@ -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; }; @@ -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); diff --git a/tests/resources/test_4047.pdf b/tests/resources/test_4047.pdf new file mode 100644 index 000000000..b36b753c9 Binary files /dev/null and b/tests/resources/test_4047.pdf differ diff --git a/tests/test_annots.py b/tests/test_annots.py index 6c579cc33..ff4f92e12 100644 --- a/tests/test_annots.py +++ b/tests/test_annots.py @@ -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() diff --git a/tests/test_general.py b/tests/test_general.py index 2d87f22c4..c3417601c 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -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()) @@ -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')