Skip to content
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
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Change Log
Fixed issues:

* **Fixed** `4755 <https://github.com/pymupdf/PyMuPDF/issues/4755>`_: Unexpected behavior of annot.set_rect() with carets and strikeouts
* **Fixed** `5270 <https://github.com/pymupdf/PyMuPDF/issues/5270>`_: delete_page() raises a SWIG TypeError when another page has an invalid UTF-16 GoTo destination

Other:

Expand Down
22 changes: 20 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
PYMUPDF_SETUP_MUPDF_VS_UPGRADE
If '1' we run mupdf `scripts/mupdfwrap.py` with `--vs-upgrade 1` to
help Windows builds work with Visual Studio versions newer than 2019.

If undefined and we are running on windows-arm, we also specify
`--vs-upgrade 1`, because otherwise the mupdf build fails.

PYMUPDF_SETUP_MUPDF_TGZ
If set, overrides location of MuPDF .tar.gz file:
Expand Down Expand Up @@ -308,13 +311,28 @@
g_package_name = 'pymupdf-lite'


def _vs_upgrade():
'''
Returns true if we should upgrade mupdf's Visual Studio build files before
build.
'''
if PYMUPDF_SETUP_MUPDF_VS_UPGRADE == '1':
return True
if (PYMUPDF_SETUP_MUPDF_VS_UPGRADE is None
and platform.system() == 'Windows'
and platform.machine() == 'ARM64'
):
# Windows-arm builds require vs upgrade.
return True
return False

def mupdf_win32_infix():
'''
Returns subdirectory in mupdf:platform/ that contains windows
libraries. Usually 'win32', but if we have told mupdf to upgrade the VS
project files it will be 'win32-vs-upgrade'.
'''
if PYMUPDF_SETUP_MUPDF_VS_UPGRADE == '1':
if _vs_upgrade():
return 'win32-vs-upgrade'
else:
return 'win32'
Expand Down Expand Up @@ -1041,7 +1059,7 @@ def build_mupdf_windows(
devenv = 'devenv.com'
log( f'Cannot find devenv.com in default locations, using: {devenv!r}')
command = f'cd "{mupdf_local}" && "{sys.executable}" ./scripts/mupdfwrap.py'
if PYMUPDF_SETUP_MUPDF_VS_UPGRADE == '1':
if _vs_upgrade():
command += ' --vs-upgrade 1'

# Would like to simply do f'... --devenv {shutil.quote(devenv)}', but
Expand Down
11 changes: 9 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19305,8 +19305,15 @@ def _remove_dest_range(pdf, numbers):
target = mupdf.pdf_array_get( dest, 0)
pno = mupdf.pdf_lookup_page_number( pdf, target)
elif mupdf.pdf_is_string( dest):
location, _, _ = mupdf.fz_resolve_link( pdf.super(), mupdf.pdf_to_text_string( dest))
pno = location.page
try:
location, _, _ = mupdf.fz_resolve_link( pdf.super(), mupdf.pdf_to_text_string( dest))
except Exception:
# We're only looking for links that are definitely to
# one of the deleted pages, so we don't care if we can't
# resolve the link.
pass
else:
pno = location.page
if pno < 0: # page number lookup did not work
continue
n1 = pno
Expand Down
4 changes: 3 additions & 1 deletion tests/test_annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,9 @@ def show_chars(chars, prefix):
num_errors += 1

print(f'{num_errors=}')
if pymupdf.mupdf_version_tuple >= (1, 28, 5):
if pymupdf.mupdf_version_tuple >= (1, 29):
assert num_errors == 0
elif pymupdf.mupdf_version_tuple >= (1, 28, 5):
# Bug introduced in mupdf-1.28.5.
assert num_errors
else:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_pagedelete.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,25 @@ def make_document():
document.delete_pages(from_page=-2, to_page=-1)
document = make_document()
document.delete_pages(-2, -1)


def test_5270():
state = dict()
for destination in 'FEFF0041', 'FEFFD800':
print(f'{destination=}', flush=1)
with pymupdf.open() as document:
for number in range(3):
document.new_page().insert_text((40, 40), f'synthetic page {number}')
xref = document.get_new_xref()
document.update_object(xref, f'<</Type /Annot /Subtype /Link /Rect [0 0 20 20] /A <</S /GoTo /D <{destination}>>>>>')
document.xref_set_key(document.page_xref(0), 'Annots', f'[{xref} 0 R]')
document.save(os.path.normpath(f'{__file__}/../../tests/test_5270_out.pdf'))
try:
document.delete_page(1)
except Exception as e:
state[destination] = e
raise
print(f'{len(document)=}')
assert len(document) == 2

print(f'{state=}')
2 changes: 1 addition & 1 deletion tests/test_textextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ def test_5218():
if ch.m_internal.c != 0xfde2:
num_errors += 1
print(f'{num_errors=}')
if pymupdf.mupdf_version_tuple >= (1, 29):
if pymupdf.mupdf_version_tuple >= (1, 28, 8):
assert not num_errors
else:
assert num_errors
Loading