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 1.23.20 #3108

Merged
merged 3 commits into from
Jan 29, 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
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ body:
label: PyMuPDF version
options:
-
- 1.23.20
- 1.23.19
- 1.23.18
- 1.23.17
Expand Down
11 changes: 11 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ Change Log
==========


**Changes in version 1.23.20 (2024-01-29)**

* Bug fixes:

* **Fixed** `3100 <https://github.com/pymupdf/PyMuPDF/issues/3100>`_: Wrong internal property accessed in get_xml_metadata

* Other:

* Significantly improved speed of `Document.get_toc()`.


**Changes in version 1.23.19 (2024-01-25)**

* Bug fixes:
Expand Down
2 changes: 1 addition & 1 deletion docs/version.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
----

This documentation covers **PyMuPDF v1.23.19** features as of **2024-01-25 00:00:01**.
This documentation covers **PyMuPDF v1.23.20** features as of **2024-01-29 00:00:01**.

The major and minor versions of **PyMuPDF** and **MuPDF** will always be the same. Only the third qualifier (patch level) may deviate from that of **MuPDF**.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def sdist():
# We generate different wheels depending on g_flavour.
#

version = '1.23.19'
version = '1.23.20'
version_b = '1.23.9'

tag_python = None
Expand Down
92 changes: 53 additions & 39 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4271,7 +4271,7 @@ def get_xml_metadata(self):
PDF_NAME('Root'),
PDF_NAME('Metadata'),
)
if xml and xml.internal:
if xml and xml.m_internal:
buff = mupdf.pdf_load_stream(xml)
rc = JM_UnicodeFromBuffer(buff)
else:
Expand Down Expand Up @@ -7808,36 +7808,50 @@ def _insert_image(self,
do_have_imask = 0

if do_have_imask:
#log( 'do_have_imask')
# mupdf.FzCompressedBuffer is not copyable, so
# mupdf.fz_compressed_image_buffer() does not work - it cannot
# return by value. And sharing a fz_compressed_buffer betwen two
# `fz_image`'s doesn't work, so we use a raw fz_compressed_buffer
# here, not a mupdf.FzCompressedBuffer.
#
cbuf1 = mupdf.ll_fz_compressed_image_buffer( image.m_internal)
if not cbuf1:
raise ValueError( "uncompressed image cannot have mask")
bpc = image.bpc()
colorspace = image.colorspace()
xres, yres = mupdf.fz_image_resolution(image)
mask = mupdf.fz_new_image_from_buffer(maskbuf)
if mupdf_version_tuple >= (1, 24):
zimg = mupdf.ll_fz_new_image_from_compressed_buffer2(
# `fz_compressed_buffer` is reference counted and
# `mupdf.fz_new_image_from_compressed_buffer2()`
# is povided as a Swig-friendly wrapper for
# `fz_new_image_from_compressed_buffer()`, so we can do things
# straightfowardly.
#
cbuf1 = mupdf.fz_compressed_image_buffer( image)
if not cbuf1.m_internal:
raise ValueError( "uncompressed image cannot have mask")
bpc = image.bpc()
colorspace = image.colorspace()
xres, yres = mupdf.fz_image_resolution(image)
mask = mupdf.fz_new_image_from_buffer(maskbuf)
image = mupdf.fz_new_image_from_compressed_buffer2(
w,
h,
bpc,
colorspace.m_internal,
colorspace,
xres,
yres,
1, # interpolate
0, # imagemask,
None, # decode
None, # colorkey
cbuf1,
mask.m_internal,
mask,
)
else:
#log( 'do_have_imask')
# mupdf.FzCompressedBuffer is not copyable, so
# mupdf.fz_compressed_image_buffer() does not work - it cannot
# return by value. And sharing a fz_compressed_buffer betwen two
# `fz_image`'s doesn't work, so we use a raw fz_compressed_buffer
# here, not a mupdf.FzCompressedBuffer.
#
cbuf1 = mupdf.ll_fz_compressed_image_buffer( image.m_internal)
if not cbuf1:
raise ValueError( "uncompressed image cannot have mask")
bpc = image.bpc()
colorspace = image.colorspace()
xres, yres = mupdf.fz_image_resolution(image)
mask = mupdf.fz_new_image_from_buffer(maskbuf)

# mupdf.ll_fz_new_image_from_compressed_buffer() is not usable.
zimg = extra.fz_new_image_from_compressed_buffer(
w,
Expand All @@ -7852,26 +7866,26 @@ def _insert_image(self,
mask.m_internal,
)

zimg = mupdf.FzImage(zimg)

# `image` and `zimage` both have pointers to the same
# `fz_compressed_buffer`, which is not reference counted, and they
# both think that they own it.
#
# So we do what the classic implementataion does, and simply ensure
# that `fz_drop_image(image)` is never called. This will leak
# some of `image`'s allocations (for example the main `fz_image`
# allocation), but it's not trivial to avoid this.
#
# Perhaps we could manually set `fz_image`'s
# `fz_compressed_buffer*` to null? Trouble is we'd have to
# cast the `fz_image*` to a `fz_compressed_image*` to see the
# `fz_compressed_buffer*`, which is probably not possible from
# Python?
#
image.m_internal = None
zimg = mupdf.FzImage(zimg)

# `image` and `zimage` both have pointers to the same
# `fz_compressed_buffer`, which is not reference counted, and they
# both think that they own it.
#
# So we do what the classic implementataion does, and simply ensure
# that `fz_drop_image(image)` is never called. This will leak
# some of `image`'s allocations (for example the main `fz_image`
# allocation), but it's not trivial to avoid this.
#
# Perhaps we could manually set `fz_image`'s
# `fz_compressed_buffer*` to null? Trouble is we'd have to
# cast the `fz_image*` to a `fz_compressed_image*` to see the
# `fz_compressed_buffer*`, which is probably not possible from
# Python?
#
image.m_internal = None

image = zimg
image = zimg

if do_have_image:
#log( 'do_have_image')
Expand Down Expand Up @@ -21801,8 +21815,8 @@ def int_rc(text):
return int(text)

VersionFitz = "1.23.9" # MuPDF version.
VersionBind = "1.23.19" # PyMuPDF version.
VersionDate = "2024-01-25 00:00:01"
VersionBind = "1.23.20" # PyMuPDF version.
VersionDate = "2024-01-29 00:00:01"
VersionDate2 = VersionDate.replace('-', '').replace(' ', '').replace(':', '')
version = (VersionBind, VersionFitz, VersionDate2)
pymupdf_version_tuple = tuple( [int_rc(i) for i in VersionBind.split('.')])
Expand Down
6 changes: 3 additions & 3 deletions src_classic/version.i
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%pythoncode %{
VersionFitz = "1.23.9" # MuPDF version.
VersionBind = "1.23.19" # PyMuPDF version.
VersionDate = "2024-01-25 00:00:01"
version = (VersionBind, VersionFitz, "20240125000001")
VersionBind = "1.23.20" # PyMuPDF version.
VersionDate = "2024-01-29 00:00:01"
version = (VersionBind, VersionFitz, "20240129000001")
pymupdf_version_tuple = tuple( [int(i) for i in VersionFitz.split('.')])
%}
5 changes: 5 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,8 @@ def next_fd():
assert fd2 == fd1 + 1
assert fd3 == fd1
assert fd4 == fd1

def test_xml():
path = os.path.abspath(f'{__file__}/../../tests/resources/2.pdf')
with fitz.open(path) as document:
document.get_xml_metadata()
Loading