Skip to content

Commit

Permalink
hotfixing #1266
Browse files Browse the repository at this point in the history
  • Loading branch information
JorjMcKie committed Sep 16, 2021
1 parent b32abc7 commit d206ef7
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 29 deletions.
4 changes: 2 additions & 2 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: PyMuPDF
Version: 1.18.18
Version: 1.18.19
Author: Jorj McKie
Author-email: jorj.x.mckie@outlook.de
License: GNU AFFERO GPL 3.0
Expand All @@ -20,7 +20,7 @@ Description:
Introduction
============

PyMuPDF (current version 1.18.18) is a Python binding with support for `MuPDF <http://mupdf.com/>`_ (current version 1.18.*), a lightweight PDF, XPS, and E-book viewer, renderer and toolkit, which is maintained and developed by Artifex Software, Inc.
PyMuPDF (current version 1.18.19) is a Python binding with support for `MuPDF <http://mupdf.com/>`_ (current version 1.18.*), a lightweight PDF, XPS, and E-book viewer, renderer and toolkit, which is maintained and developed by Artifex Software, Inc.

MuPDF can access files in PDF, XPS, OpenXPS, CBZ, EPUB and FB2 (e-books) formats, and it is known for its top performance and high rendering quality.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PyMuPDF 1.18.18
# PyMuPDF 1.18.19

![logo](https://github.com/pymupdf/PyMuPDF/blob/master/demo/pymupdf.jpg)

Expand All @@ -11,7 +11,7 @@ On **[PyPI](https://pypi.org/project/PyMuPDF)** since August 2016: [![Downloads]

# Introduction

PyMuPDF (current version 1.18.18) is a Python binding with support for [MuPDF](https://mupdf.com/) (current version 1.18.*), a lightweight PDF, XPS, and E-book viewer, renderer, and toolkit, which is maintained and developed by Artifex Software, Inc.
PyMuPDF (current version 1.18.19) is a Python binding with support for [MuPDF](https://mupdf.com/) (current version 1.18.*), a lightweight PDF, XPS, and E-book viewer, renderer, and toolkit, which is maintained and developed by Artifex Software, Inc.

MuPDF can access files in PDF, XPS, OpenXPS, CBZ, EPUB and FB2 (e-books) formats, and it is known for its top performance and high rendering quality.

Expand Down
16 changes: 16 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ Change Logs

------

**Changes in Version 1.18.18**

* **Fixed** issue `#1257 <https://github.com/pymupdf/PyMuPDF/issues/1257>`_. Removing the read-only flag from PDF fields is now possible.

* **Fixed** issue `#1252 <https://github.com/pymupdf/PyMuPDF/issues/1252>`_. Now correctly specifying the ``zoom`` value for PDF link annotations.

* **Fixed** issue `#1244 <https://github.com/pymupdf/PyMuPDF/issues/1244>`_. Now correctly computing the transform matrix in :meth:`Page.get_image__bbox`.

* **Fixed** issue `#1241 <https://github.com/pymupdf/PyMuPDF/issues/1241>`_. Prevent returning artifact characters in :meth:`Page.get_textbox`, which happened in certain constellations.

* **Fixed** issue `#1234 <https://github.com/pymupdf/PyMuPDF/issues/1234>`_. Avoid creating infinite rectangles in corner cases -- :meth:`Page.get_drawings`, :meth:`Page.get_cdrawings`.

* **Added** test data and test scripts to the source PyPI source distribution.

------

**Changes in Version 1.18.17**

Focus of this version are major performance improvements of selected functions.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = "1.18.17"
release = "1.18.19"

# The short X.Y version
version = release
Expand Down
27 changes: 13 additions & 14 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ and `extract-imgb.py <https://github.com/JorjMcKie/PyMuPDF-Utilities/blob/master

----------

How to Handle Stencil Masks
How to Handle Image Masks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some images in PDFs are accompanied by **stencil masks**. In their simplest form stencil masks represent alpha (transparency) bytes stored as separate images. In order to reconstruct the original of an image, which has a stencil mask, it must be "enriched" with transparency bytes taken from its stencil mask.
Some images in PDFs are accompanied by **image masks**. In their simplest form, masks represent alpha (transparency) bytes stored as separate images. In order to reconstruct the original of an image, which has a mask, it must be "enriched" with transparency bytes taken from its mask.

Whether an image does have such a stencil mask can be recognized in one of two ways in PyMuPDF:
Whether an image does have such a mask can be recognized in one of two ways in PyMuPDF:

1. An item of :meth:`Document.get_page_images` has the general format *[xref, smask, ...]*, where *xref* is the image's :data:`xref` and *smask*, if positive, is the :data:`xref` of a stencil mask.
2. The (dictionary) results of :meth:`Document.extract_image` have a key *"smask"*, which also contains any stencil mask's :data:`xref` if positive.
1. An item of :meth:`Document.get_page_images` has the general format ``(xref, smask, ...)``, where *xref* is the image's :data:`xref` and *smask*, if positive, is the :data:`xref` of a mask.
2. The (dictionary) results of :meth:`Document.extract_image` have a key *"smask"*, which also contains any mask's :data:`xref` if positive.

If *smask == 0* then the image encountered via :data:`xref` can be processed as it is.

Expand All @@ -207,12 +207,11 @@ To recover the original image using PyMuPDF, the procedure depicted as follows m
.. image:: images/img-stencil.*
:scale: 60

>>> pix1 = fitz.Pixmap(doc, xref) # (1) pixmap of image w/o alpha
>>> pix2 = fitz.Pixmap(doc, smask) # (2) stencil pixmap
>>> pix = fitz.Pixmap(pix1) # (3) copy of pix1, empty alpha channel added
>>> pix.set_alpha(pix2.samples) # (4) fill alpha channel
>>> pix1 = fitz.Pixmap(doc.extract_image(xref)["image"]) # (1) pixmap of image w/o alpha
>>> mask = fitz.Pixmap(doc.extract_image(smask)["image"]) # (2) mask pixmap
>>> pix = fitz.Pixmap(pix1, mask) # (3) copy of pix1, image mask added

Step (1) creates a pixmap of the "netto" image. Step (2) does the same with the stencil mask. Please note that the :attr:`Pixmap.samples` attribute of *pix2* contains the alpha bytes that must be stored in the final pixmap. This is what happens in step (3) and (4).
Step (1) creates a pixmap of the basic image. Step (2) does the same with the image mask. Step (3) adds an alpha channel and fills it with transparency information.

The scripts `extract-imga.py <https://github.com/JorjMcKie/PyMuPDF-Utilities/blob/master/extract-imga.py>`_, and `extract-imgb.py <https://github.com/JorjMcKie/PyMuPDF-Utilities/blob/master/extract-imgb.py>`_ above also contain this logic.

Expand Down Expand Up @@ -2108,10 +2107,10 @@ If it is *False* or if you want to be on the safe side, pick one of the followin

Missing or Unreadable Extracted Text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This can be a number of different problems.
Fairly often, text extraction does not work text as you would expect: text may be missing at all, or may not appear in the reading sequence visible on your screen, or contain garbled characters (like a ? or a "TOFU" symbol), etc. This can be caused by a number of different problems.

Problem: no text
^^^^^^^^^^^^^^^^
Problem: no text is extracted
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Your PDF viewer does display text, but you cannot select it with your cursor, and text extraction delivers nothing.

Cause
Expand All @@ -2130,7 +2129,7 @@ Text extraction does not deliver the text in readable order, duplicates some tex
Cause
^^^^^^
1. The single characters are redable as such (no "<?>" symbols), but the sequence in which the text is **coded in the file** deviates from the reading order. The motivation behind may be technical or protection of data against unwanted copies.
2. Many "<?>" symbols occur indicating MuPDF could not interpret these characters. The PDF creator may haved used a font that displays readable text, but obfuscates the unicode character that leads to the readable symbol (glyph).
2. Many "<?>" symbols occur, indicating MuPDF could not interpret these characters. The font may indeed be unsupported by MuPDF, or the PDF creator may haved used a font that displays readable text, but on purpose obfuscates the originating corresponding unicode character.

Solution
^^^^^^^^
Expand Down
16 changes: 14 additions & 2 deletions docs/pixmap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ Have a look at the :ref:`FAQ` section to see some pixmap usage "at work".
:arg source: the source pixmap.
:type source: *Pixmap*

.. method:: __init__(self, source, mask)

* New in v1.18.18

**Copy and add image mask:** Copy *source* pixmap, add an alpha channel with transparency data from a mask pixmap.

:arg source: pixmap without alpha channel.
:type source: :ref:`Pixmap`

:arg mask: a mask pixmap. Must be a graysale pixmap.
:type mask: :ref:`Pixmap`

.. method:: __init__(self, source, width, height, [clip])

**Copy and scale:** Copy *source* pixmap, scaling new width and height values -- the image will appear stretched or shrunk accordingly. Supports partial copying. The source colorspace may be *None*.
Expand All @@ -96,7 +108,7 @@ Have a look at the :ref:`FAQ` section to see some pixmap usage "at work".

:arg irect_like clip: restrict the resulting pixmap to this region of the **scaled** pixmap.

.. note:: If width or height are not *de facto* integers (i.e. ``value.is_integer() != True``), then the resulting pixmap **will have an alpha channel**.
.. note:: If width or height do not *represent* integers (i.e. ``value.is_integer() != True``), then the resulting pixmap **will have an alpha channel**.

.. method:: __init__(self, source, alpha=1)

Expand Down Expand Up @@ -255,7 +267,7 @@ Have a look at the :ref:`FAQ` section to see some pixmap usage "at work".

:arg bytes,bytearray,BytesIO alphavalues: the new alpha values. If provided, its length must be at least *width * height*. If omitted (``None``), all alpha values are set to 255 (no transparency). *Changed in version 1.14.13:* *io.BytesIO* is now also accepted.
:arg bool premultiply: *New in v1.18.13:* whether to premultiply color components with the alpha value.
:arg list,tuple opaque: specify a color that should be fully transparent -- ignoring the alpha value of the parameter. A sequence of integers in ``range(256)`` with a length of :attr:`Pixmap.n`. Default is *None*. E.g. in the RGB case a typical choice would be ``opaque=(255, 255, 255)`` for white.
:arg list,tuple opaque: ignore the alpha value and set this color to fully transparent. A sequence of integers in ``range(256)`` with a length of :attr:`Pixmap.n`. Default is *None*. For example, a typical choice for RGB would be ``opaque=(255, 255, 255)`` (white).


.. method:: invert_irect([irect])
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 @@
Covered Version
--------------------

This documentation covers PyMuPDF v1.18.17 features as of **2021-08-23 00:00:01**.
This documentation covers PyMuPDF v1.18.19 features as of **2021-09-16 16:45:29**.

.. note:: 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.
12 changes: 11 additions & 1 deletion fitz/fitz.i
Original file line number Diff line number Diff line change
Expand Up @@ -9565,6 +9565,11 @@ CheckParent(self)
cspaces = {"gray": csGRAY, "rgb": csRGB, "cmyk": csCMYK}
if type(colorspace) is str:
colorspace = cspaces.get(colorspace.lower(), None)
%}
%pythonappend get_pixmap
%{
val.samples_mv = val._samples_mv()
val.samples_ptr = val._samples_ptr()
%}
struct Pixmap *
get_pixmap(PyObject *matrix = NULL, struct Colorspace *colorspace = NULL, int alpha = 0)
Expand Down Expand Up @@ -9883,7 +9888,12 @@ struct DisplayList {
// DisplayList.get_pixmap
//----------------------------------------------------------------
FITZEXCEPTION(get_pixmap, !result)
%pythonappend get_pixmap %{val.thisown = True%}
%pythonappend get_pixmap
%{
val.thisown = True
val.samples_mv = val._samples_mv()
val.samples_ptr = val._samples_ptr()
%}
struct Pixmap *get_pixmap(PyObject *matrix=NULL,
struct Colorspace *colorspace=NULL,
int alpha=0,
Expand Down
2 changes: 0 additions & 2 deletions fitz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,6 @@ def get_pixmap(page: Page, **kw) -> Pixmap:
pix = dl.get_pixmap(matrix=matrix, colorspace=colorspace, alpha=alpha, clip=clip)
dl = None
return pix
# doc = page.parent
# return page._makePixmap(doc, matrix, colorspace, alpha, annots, clip)


def get_page_pixmap(
Expand Down
6 changes: 3 additions & 3 deletions fitz/version.i
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%pythoncode %{
VersionFitz = "1.18.0"
VersionBind = "1.18.18"
VersionDate = "2021-09-16 00:00:01"
version = (VersionBind, VersionFitz, "20210916000001")
VersionBind = "1.18.19"
VersionDate = "2021-09-16 16:45:29"
version = (VersionBind, VersionFitz, "20210916164529")
%}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def load_libraries():

setup(
name="PyMuPDF",
version="1.18.18",
version="1.18.19",
description="Python bindings for the PDF toolkit and renderer MuPDF",
long_description=long_desc,
classifiers=classifier,
Expand Down

0 comments on commit d206ef7

Please sign in to comment.