Skip to content

Commit

Permalink
Fix incorrect call to JM_refresh_links() in Document.update_object().
Browse files Browse the repository at this point in the history
Addresses #3070.
  • Loading branch information
julian-smith-artifex-com committed Jan 22, 2024
1 parent a103a66 commit 5477123
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ def _as_fz_page(page):
return page
assert 0, f'Unrecognised {type(page)=}'

def _as_pdf_page(page):
'''
Returns page as a mupdf.PdfPage, downcasting as required. If we fail (i.e.
page is a mupdf.FzPage(), <ret>.m_internal will be None.
'''
if isinstance(page, Page):
page = page.this
if isinstance(page, mupdf.PdfPage):
return page
elif isinstance(page, mupdf.FzPage):
return mupdf.pdf_page_from_fz_page(page)
assert 0, f'Unrecognised {type(page)=}'


# Fixme: we don't support JM_MEMORY=1.
JM_MEMORY = 0
Expand Down Expand Up @@ -5638,7 +5651,7 @@ def update_object(self, xref, text, page=None):
new_obj = JM_pdf_obj_from_str(pdf, text)
mupdf.pdf_update_object(pdf, xref, new_obj)
if page:
JM_refresh_links( mupdf.pdf_page_from_fz_page(page.super()))
JM_refresh_links( _as_pdf_page(page))

def update_stream(self, xref=0, stream=None, new=1, compress=1):
"""Replace xref stream part."""
Expand Down
Binary file added tests/resources/test_3070.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,3 +794,10 @@ def test_2957_2():
w0 = words0[i] # word before redaction
bbox0 = fitz.Rect(w0[:4]).irect # its IRect coordinates
assert bbox0 == bbox1 # must be same coordinates

def test_3070():
with fitz.open(os.path.abspath(f'{__file__}/../../tests/resources/test_3070.pdf')) as pdf:
links = pdf[0].get_links()
links[0]['uri'] = "https://www.ddg.gg"
pdf[0].update_link(links[0])
pdf.save(os.path.abspath(f'{__file__}/../../tests/test_3070_out.pdf'))

0 comments on commit 5477123

Please sign in to comment.