Skip to content

Commit c876582

Browse files
committed
Fixing issue #463
1 parent 5eaeddc commit c876582

File tree

7 files changed

+98
-55
lines changed

7 files changed

+98
-55
lines changed

PKG-INFO

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Home-page: https://github.com/pymupdf/PyMuPDF
99
Download-url: https://github.com/pymupdf/PyMuPDF
1010
Summary: PyMuPDF is a Python binding for the PDF rendering library MuPDF
1111
Description:
12-
Release date: March 05, 2020
12+
Release date: March 10, 2020
1313

1414
Authors
1515
=======

docs/changes.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ Changes in Version 1.16.12
66
* **Fixed** issue `#447 <https://github.com/pymupdf/PyMuPDF/issues/447>`_
77
* **Fixed** issue `#461 <https://github.com/pymupdf/PyMuPDF/issues/461>`_.
88
* **Fixed** issue `#397 <https://github.com/pymupdf/PyMuPDF/issues/397>`_.
9-
* **Added** JavaScript support to PDF form fields, thereby addressing `#454 <https://github.com/pymupdf/PyMuPDF/issues/454>`_.
10-
* **Added** a new annotation method :meth:`Annot.delete_responses`, which removes 'Popup' and response annotations referring to the current one.
9+
* **Fixed** issue `#463 <https://github.com/pymupdf/PyMuPDF/issues/463>`_.
10+
* **Added** JavaScript support to PDF form fields, thereby fixing `#454 <https://github.com/pymupdf/PyMuPDF/issues/454>`_.
11+
* **Added** a new annotation method :meth:`Annot.delete_responses`, which removes 'Popup' and response annotations referring to the current one. Mainly serves data protection purposes.
1112
* **Added** a new form field method :meth:`Widget.reset`, which resets the field value to its default.
12-
* **Changed** and extended handling of redactions: images and XObjects are removed if *contained* in a redaction rectangle. Any partial overlaps will just be covered by the redaction background color. Now a text can be specified to be inserted in the rectangle area to **replace the deleted original** text. This resolves `#434 <https://github.com/pymupdf/PyMuPDF/issues/434>`_.
13+
* **Changed** and extended handling of redactions: images and XObjects are removed if *contained* in a redaction rectangle. Any partial only overlaps will just be covered by the redaction background color. Now an *overlay* text can be specified to be inserted in the rectangle area to **take the place the deleted original** text. This resolves `#434 <https://github.com/pymupdf/PyMuPDF/issues/434>`_.
1314

1415
Changes in Version 1.16.11
1516
---------------------------

docs/installation.rst

+1-21
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,7 @@ Windows binaries are provided for Python **32-bit and 64-bit** versions.
5555

5656
**Overview of wheel names (PyMuPDF version is x.xx.xx):**
5757

58-
* ``PyMuPDF-x.xx.xx-cp27-cp27m-macosx_10_6_intel.whl``
59-
* ``PyMuPDF-x.xx.xx-cp27-cp27m-manylinux2010_x86_64.whl``
60-
* ``PyMuPDF-x.xx.xx-cp27-cp27m-win32.whl``
61-
* ``PyMuPDF-x.xx.xx-cp27-cp27m-win_amd64.whl``
62-
* ``PyMuPDF-x.xx.xx-cp27-cp27mu-manylinux2010_x86_64.whl``
63-
* ``PyMuPDF-x.xx.xx-cp35-cp35m-macosx_10_6_intel.whl``
64-
* ``PyMuPDF-x.xx.xx-cp35-cp35m-manylinux2010_x86_64.whl``
65-
* ``PyMuPDF-x.xx.xx-cp35-cp35m-win32.whl``
66-
* ``PyMuPDF-x.xx.xx-cp35-cp35m-win_amd64.whl``
67-
* ``PyMuPDF-x.xx.xx-cp36-cp36m-macosx_10_6_intel.whl``
68-
* ``PyMuPDF-x.xx.xx-cp36-cp36m-manylinux2010_x86_64.whl``
69-
* ``PyMuPDF-x.xx.xx-cp36-cp36m-win32.whl``
70-
* ``PyMuPDF-x.xx.xx-cp36-cp36m-win_amd64.whl``
71-
* ``PyMuPDF-x.xx.xx-cp37-cp37m-macosx_10_6_intel.whl``
72-
* ``PyMuPDF-x.xx.xx-cp37-cp37m-manylinux2010_x86_64.whl``
73-
* ``PyMuPDF-x.xx.xx-cp37-cp37m-win32.whl``
74-
* ``PyMuPDF-x.xx.xx-cp37-cp37m-win_amd64.whl``
75-
* ``PyMuPDF-x.xx.xx-cp38-cp38-macosx_10_9_x86_64.whl``
76-
* ``PyMuPDF-x.xx.xx-cp38-cp38-manylinux2010_x86_64.whl``
77-
* ``PyMuPDF-x.xx.xx-cp38-cp38-win32.whl``
78-
* ``PyMuPDF-x.xx.xx-cp38-cp38-win_amd64.whl``
58+
.. literalinclude:: wheelnames.txt
7959

8060

8161
Older versions can be found in the releases directory of our home page https://github.com/pymupdf/PyMuPDF/releases.

docs/page.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -984,13 +984,13 @@ This is available for PDF documents only. There are basically two groups of meth
984984

985985
.. attribute:: CropBoxPosition
986986

987-
Contains the displacement of the page's */CropBox* for a PDF, otherwise the top-left coordinates of :attr:`Page.rect`.
987+
Contains the top-left point of the page's */CropBox* for a PDF, otherwise *Point(0, 0)*.
988988

989989
:type: :ref:`Point`
990990

991991
.. attribute:: CropBox
992992

993-
The page's */CropBox* for a PDF, else :attr:`Page.rect`.
993+
The page's */CropBox* for a PDF. Always the **unrotated** page rectangle is returned. For a non-PDF this will always equal the page rectangle.
994994

995995
:type: :ref:`Rect`
996996

@@ -1006,7 +1006,7 @@ This is available for PDF documents only. There are basically two groups of meth
10061006

10071007
:type: :ref:`Rect`
10081008

1009-
.. note:: For most PDF documents and for all other types, *page.rect == page.CropBox == page.MediaBox* is true. However, for some PDFs the visible page is a true subset of */MediaBox*. In this case the above attributes help to correctly locate page elements.
1009+
.. note:: For most PDF documents and for all other types, *page.rect == page.CropBox == page.MediaBox* is true. However, for some PDFs the visible page is a true subset of */MediaBox*. Also, if the page is rotated, its ``Page.rect`` may not equal ``Page.CropBox``. In these cases the above attributes help to correctly locate page elements.
10101010

10111011
.. attribute:: firstLink
10121012

docs/wheelnames.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
PyMuPDF-x.xx.xx-cp27-cp27m-macosx_10_9_x86_64.whl
2+
PyMuPDF-x.xx.xx-cp27-cp27m-manylinux2010_x86_64.whl
3+
PyMuPDF-x.xx.xx-cp27-cp27m-win32.whl
4+
PyMuPDF-x.xx.xx-cp27-cp27m-win_amd64.whl
5+
PyMuPDF-x.xx.xx-cp27-cp27mu-manylinux2010_x86_64.whl
6+
PyMuPDF-x.xx.xx-cp35-cp35m-macosx_10_9_x86_64.whl
7+
PyMuPDF-x.xx.xx-cp35-cp35m-manylinux2010_x86_64.whl
8+
PyMuPDF-x.xx.xx-cp35-cp35m-win32.whl
9+
PyMuPDF-x.xx.xx-cp35-cp35m-win_amd64.whl
10+
PyMuPDF-x.xx.xx-cp36-cp36m-macosx_10_9_x86_64.whl
11+
PyMuPDF-x.xx.xx-cp36-cp36m-manylinux2010_x86_64.whl
12+
PyMuPDF-x.xx.xx-cp36-cp36m-win32.whl
13+
PyMuPDF-x.xx.xx-cp36-cp36m-win_amd64.whl
14+
PyMuPDF-x.xx.xx-cp37-cp37m-macosx_10_9_x86_64.whl
15+
PyMuPDF-x.xx.xx-cp37-cp37m-manylinux2010_x86_64.whl
16+
PyMuPDF-x.xx.xx-cp37-cp37m-win32.whl
17+
PyMuPDF-x.xx.xx-cp37-cp37m-win_amd64.whl
18+
PyMuPDF-x.xx.xx-cp38-cp38-macosx_10_9_x86_64.whl
19+
PyMuPDF-x.xx.xx-cp38-cp38-manylinux2010_x86_64.whl
20+
PyMuPDF-x.xx.xx-cp38-cp38-win32.whl
21+
PyMuPDF-x.xx.xx-cp38-cp38-win_amd64.whl

fitz/fitz.i

+66-27
Original file line numberDiff line numberDiff line change
@@ -2592,8 +2592,6 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
25922592
25932593
25942594
xrefObject = get_pdf_object
2595-
xref_object = get_pdf_object
2596-
xref_stream = xrefStream
25972595
25982596
25992597
def __repr__(self):
@@ -3673,28 +3671,56 @@ annot._erase()
36733671
}
36743672
36753673
//---------------------------------------------------------------------
3676-
// MediaBox size: width, height of /MediaBox (PDF only)
3674+
// MediaBox: get the /MediaBox (PDF only)
36773675
//---------------------------------------------------------------------
3678-
PARENTCHECK(MediaBoxSize)
3676+
PARENTCHECK(MediaBox)
36793677
%pythoncode %{@property%}
3680-
%feature("autodoc","Retrieve width, height of /MediaBox.") MediaBoxSize;
3681-
%pythonappend MediaBoxSize %{
3682-
val = Point(val)
3683-
if not bool(val):
3684-
r = self.rect
3685-
val = Point(r.width, r.height)
3678+
%feature("autodoc","Retrieve the /MediaBox.") MediaBox;
3679+
%pythonappend MediaBox %{
3680+
val = Rect(val)
36863681
%}
3687-
PyObject *MediaBoxSize()
3682+
PyObject *MediaBox()
36883683
{
3689-
PyObject *p = JM_py_from_point(fz_make_point(0, 0));
36903684
pdf_page *page = pdf_page_from_fz_page(gctx, $self);
3691-
if (!page) return p;
3692-
fz_rect r = fz_empty_rect;
3693-
pdf_obj *o = pdf_dict_get_inheritable(gctx, page->obj, PDF_NAME(MediaBox));
3694-
if (!o) return p;
3685+
if (!page) return JM_py_from_rect(fz_bound_page(gctx, $self));
3686+
3687+
fz_rect mediabox, cropbox, page_mediabox;
3688+
PyObject *rect = NULL;
3689+
pdf_obj *obj;
3690+
float userunit = 1;
3691+
3692+
obj = pdf_dict_get(gctx, page->obj, PDF_NAME(UserUnit));
3693+
if (pdf_is_real(gctx, obj))
3694+
{
3695+
userunit = pdf_to_real(gctx, obj);
3696+
}
3697+
3698+
mediabox = pdf_to_rect(gctx, pdf_dict_get_inheritable(gctx, page->obj, PDF_NAME(MediaBox)));
3699+
if (fz_is_empty_rect(mediabox))
3700+
{
3701+
mediabox.x0 = 0;
3702+
mediabox.y0 = 0;
3703+
mediabox.x1 = 612;
3704+
mediabox.y1 = 792;
3705+
}
3706+
3707+
cropbox = pdf_to_rect(gctx,
3708+
pdf_dict_get_inheritable(gctx, page->obj, PDF_NAME(CropBox)));
3709+
if (!fz_is_empty_rect(cropbox))
3710+
{
3711+
mediabox = fz_intersect_rect(mediabox, cropbox);
3712+
}
3713+
page_mediabox.x0 = fz_min(mediabox.x0, mediabox.x1);
3714+
page_mediabox.y0 = fz_min(mediabox.y0, mediabox.y1);
3715+
page_mediabox.x1 = fz_max(mediabox.x0, mediabox.x1);
3716+
page_mediabox.y1 = fz_max(mediabox.y0, mediabox.y1);
3717+
3718+
if (page_mediabox.x1 - page_mediabox.x0 < 1 ||
3719+
page_mediabox.y1 - page_mediabox.y0 < 1)
3720+
page_mediabox = fz_unit_rect;
3721+
3722+
return JM_py_from_rect(page_mediabox);
36953723
3696-
r = pdf_to_rect(gctx, o);
3697-
return JM_py_from_point(fz_make_point(r.x1 - r.x0, r.y1 - r.y0));
36983724
}
36993725
37003726
//---------------------------------------------------------------------
@@ -3712,6 +3738,7 @@ annot._erase()
37123738
pdf_obj *o = pdf_dict_get_inheritable(gctx, page->obj, PDF_NAME(CropBox));
37133739
if (!o) return p; // no CropBox specified
37143740
fz_rect cbox = pdf_to_rect(gctx, o);
3741+
Py_DECREF(p);
37153742
return JM_py_from_point(fz_make_point(cbox.x0, cbox.y0));;
37163743
}
37173744
@@ -4253,7 +4280,12 @@ def insertFont(self, fontname="helv", fontfile=None, fontbuffer=None,
42534280
//---------------------------------------------------------------------
42544281
PARENTCHECK(_getTransformation)
42554282
%feature("autodoc","Return page transformation matrix.") _getTransformation;
4256-
%pythonappend _getTransformation %{val = Matrix(val)%}
4283+
%pythonappend _getTransformation %{
4284+
if self.rotation % 360 == 0:
4285+
val = Matrix(val)
4286+
else:
4287+
val = Matrix(1, 0, 0, -1, 0, self.CropBox.height)
4288+
%}
42574289
PyObject *_getTransformation()
42584290
{
42594291
fz_matrix ctm = fz_identity;
@@ -4454,18 +4486,25 @@ def insertFont(self, fontname="helv", fontfile=None, fontbuffer=None,
44544486
44554487
@property
44564488
def CropBox(self):
4489+
"""Rectangle /CropBox IGNORING any page rotation."""
4490+
rotation = self.rotation # page rotation
4491+
width = self.rect.width # page width
4492+
height = self.rect.height # page height
4493+
if rotation % 180 != 0: # rotation by odd number of 90
4494+
width, height = height, width # so revert width and height
44574495
x0 = self.CropBoxPosition.x
4458-
y0 = self.MediaBoxSize.y - self.CropBoxPosition.y - self.rect.height
4459-
x1 = x0 + self.rect.width
4460-
y1 = y0 + self.rect.height
4496+
y0 = self.MediaBox.height - self.CropBoxPosition.y - height
4497+
x1 = x0 + width
4498+
y1 = y0 + height
44614499
return Rect(x0, y0, x1, y1)
44624500
44634501
@property
4464-
def MediaBox(self):
4465-
return Rect(0, 0, self.MediaBoxSize)
4466-
4467-
clean_contents = _cleanContents
4468-
get_contents = _getContents
4502+
def MediaBoxSize(self):
4503+
return Point(self.MediaBox.width, self.MediaBox.height)
4504+
4505+
cleanContents = _cleanContents
4506+
getContents = _getContents
4507+
getTransformation = _getTransformation
44694508
44704509
%}
44714510
}

fitz/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -2419,8 +2419,10 @@ def __init__(self, page):
24192419
self.width = page.MediaBoxSize.x
24202420
self.x = page.CropBoxPosition.x
24212421
self.y = page.CropBoxPosition.y
2422+
24222423
self.pctm = page._getTransformation() # page transf. matrix
24232424
self.ipctm = ~self.pctm # inverted transf. matrix
2425+
24242426
self.draw_cont = ""
24252427
self.text_cont = ""
24262428
self.totalcont = ""

0 commit comments

Comments
 (0)