diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 1b6439492..37320288b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -46,6 +46,7 @@ body: attributes: label: PyMuPDF version options: + - 1.27.1 - 1.27.0 - 1.26.7 - 1.26.6 diff --git a/changes.txt b/changes.txt index 5b7d4cde5..8927235bb 100644 --- a/changes.txt +++ b/changes.txt @@ -2,19 +2,27 @@ Change Log ========== -**Changes in version 1.27.0** () +**Changes in version 1.27.1** () -* Use MuPDF-1.27.0. +* Use MuPDF-1.27.1. * Fixed issues: * **Fixed** `2883 `_: Improve the Python type annotations for fitz_new + * **Fixed** `4599 `_: page.cluster_drawings extract a lot of small clusters once upgraded to 1.26 * **Fixed** `4751 `_: Memory leaking in page.widgets() + * **Fixed** `4762 `_: Importing pymupdf make pillow segmentation fault for converting jp2 file on ArchLinux * Other: * Added `pymupdf.TEXT_CLIP`. * Removed support for mupdf < 1.26. + * Partial fix of `4790 `_: Problem to delete pages on PDF + + * New arg `raise_on_repair` in `Document.save()`. + * New method `Document.repair()`. + + * Added py.typed file for type checkers. **Changes in version 1.26.7** (2025-12-11) diff --git a/setup.py b/setup.py index 49da50e50..fbab3ce9a 100755 --- a/setup.py +++ b/setup.py @@ -797,25 +797,35 @@ def build_mupdf_windows( ): assert mupdf_local - - if overwrite_config: - mupdf_config_h = f'{mupdf_local}/include/mupdf/fitz/config.h' - prefix = '#define TOFU_CJK_EXT 1 /* PyMuPDF override. */\n' - with open(mupdf_config_h) as f: - text = f.read() - if text.startswith(prefix): - print(f'Not modifying {mupdf_config_h} because already has prefix {prefix!r}.') - else: - print(f'Prefixing {mupdf_config_h} with {prefix!r}.') - text = prefix + text - st = os.stat(mupdf_config_h) - with open(mupdf_config_h, 'w') as f: - f.write(text) - os.utime(mupdf_config_h, (st.st_atime, st.st_mtime)) - + mupdf_version_tuple = get_mupdf_version(mupdf_local) + log(f'{overwrite_config=}') + log(f'{mupdf_version_tuple=}') wp = pipcl.wdev.WindowsPython() tesseract = '' if os.environ.get('PYMUPDF_SETUP_MUPDF_TESSERACT') == '0' else 'tesseract-' windows_build_tail = f'build\\shared-{tesseract}{build_type}' + + if overwrite_config: + if mupdf_version_tuple >= (1, 28): + # Tell mupdf build to use, for example, `/Build "ReleaseTofuCjkExt|x64"`. + # This avoids the need for us to modify mupdf's config.h. + windows_build_tail += '-TOFU_CJK_EXT' + log(f'Appending, {windows_build_tail=}') + else: + log(f'modifying mupdf:include/mupdf/fitz/config.h') + mupdf_config_h = f'{mupdf_local}/include/mupdf/fitz/config.h' + prefix = '#define TOFU_CJK_EXT 1 /* PyMuPDF override. */\n' + with open(mupdf_config_h) as f: + text = f.read() + if text.startswith(prefix): + log(f'Not modifying {mupdf_config_h} because already has prefix {prefix!r}.') + else: + log(f'Prefixing {mupdf_config_h} with {prefix!r}.') + text = prefix + text + st = os.stat(mupdf_config_h) + with open(mupdf_config_h, 'w') as f: + f.write(text) + os.utime(mupdf_config_h, (st.st_atime, st.st_mtime)) + if g_py_limited_api: windows_build_tail += f'-Py_LIMITED_API_{pipcl.current_py_limited_api()}' windows_build_tail += f'-x{wp.cpu.bits}-py{wp.version}' @@ -1273,9 +1283,9 @@ def sdist(): # # PyMuPDF version. -version_p = '1.27.0' +version_p = '1.27.1' -version_mupdf = '1.27.0' +version_mupdf = '1.27.1' # PyMuPDFb version. This is the PyMuPDF version whose PyMuPDFb wheels we will # (re)use if generating separate PyMuPDFb wheels. Though as of PyMuPDF-1.24.11 diff --git a/src/__init__.py b/src/__init__.py index 14953b10e..ab4ab9161 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -7865,6 +7865,7 @@ def write( preserve_metadata=1, use_objstms=0, compression_effort=0, + raise_on_repair=False, ): from io import BytesIO bio = BytesIO() @@ -7889,6 +7890,7 @@ def write( preserve_metadata=preserve_metadata, use_objstms=use_objstms, compression_effort=compression_effort, + raise_on_repair=raise_on_repair, ) return bio.getvalue() diff --git a/tests/resources/test_4599.pdf b/tests/resources/test_4599.pdf new file mode 100644 index 000000000..8f8ad9eb7 Binary files /dev/null and b/tests/resources/test_4599.pdf differ diff --git a/tests/test_cluster_drawings.py b/tests/test_cluster_drawings.py index 08fe23214..5dc739af1 100644 --- a/tests/test_cluster_drawings.py +++ b/tests/test_cluster_drawings.py @@ -45,3 +45,17 @@ def test_cluster3(): page.draw_rect(r1) page.draw_rect(r2) assert page.cluster_drawings() == [r1, r2] + + +def test_4599(): + print() + path = os.path.normpath(f'{__file__}/../../tests/resources/test_4599.pdf') + n = 0 + with pymupdf.open(path) as document: + for page in document: + for clip in page.cluster_drawings(): + print(clip) + n += 1 + assert n == 3 + +