Skip to content

Commit 52a2d34

Browse files
authored
Merge pull request #264 from JorjMcKie/master
Upgrade to v1.14.10
2 parents 222b4d0 + 4c4eb76 commit 52a2d34

File tree

13 files changed

+248
-193
lines changed

13 files changed

+248
-193
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ matrix:
3636
prefix=/usr/local install && cd .."
3737
- export CIBW_ENVIRONMENT='CFLAGS=-fPIC'
3838
install:
39-
- "$PIP install cibuildwheel==0.10.1"
39+
- "$PIP install cibuildwheel"
4040
- mkdir mupdf && wget -q $MUPDF -O - | tar zx -C mupdf --strip-components=1
4141
- cp fitz/_mupdf_config.h mupdf/include/mupdf/fitz/config.h
4242
- cp fitz/_pdf-device.c mupdf/source/pdf/pdf-device.c

PKG-INFO

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.1
22
Name: PyMuPDF
3-
Version: 1.14.9
3+
Version: 1.14.10
44
Author: Ruikai Liu
55
Author-email: [email protected]
66
Maintainer: Jorj X. McKie
@@ -10,7 +10,7 @@ Download-url: https://github.com/pymupdf/PyMuPDF
1010
Summary: PyMuPDF is a Python binding for the PDF rendering library MuPDF
1111
Description:
1212

13-
Release date: March 6, 2019
13+
Release date: March 10, 2019
1414

1515
Authors
1616
=======
@@ -21,7 +21,7 @@ Description:
2121
Introduction
2222
============
2323

24-
This is **version 1.14.9 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
24+
This is **version 1.14.10 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
2525

2626
MuPDF can access files in PDF, XPS, OpenXPS, epub, comic and fiction book formats, and it is known for both, its top performance and high rendering quality.
2727

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PyMuPDF 1.14.9
1+
# PyMuPDF 1.14.10
22

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

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

1515
# Introduction
1616

17-
This is **version 1.14.9 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.14.x](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
17+
This is **version 1.14.10 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.14.x](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
1818

1919
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.
2020

fitz/fitz.i

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ if links:
14181418
else
14191419
{
14201420
// handling JPX
1421-
buffer = pdf_load_stream(gctx, obj);
1421+
buffer = pdf_load_stream_number(gctx, pdf, xref);
14221422
freebuf = buffer; // so it will be dropped!
14231423
type = FZ_IMAGE_JPX;
14241424
o = pdf_dict_get(gctx, obj, PDF_NAME(ColorSpace));
@@ -1837,7 +1837,8 @@ if links:
18371837
new_obj = JM_pdf_obj_from_str(gctx, pdf, text);
18381838
pdf_update_object(gctx, pdf, xref, new_obj);
18391839
pdf_drop_obj(gctx, new_obj);
1840-
if (page) refresh_link_table(gctx, pdf_page_from_fz_page(gctx, page));
1840+
if (page)
1841+
refresh_link_table(gctx, pdf_page_from_fz_page(gctx, page));
18411842
}
18421843
fz_catch(gctx) return NULL;
18431844
pdf->dirty = 1;
@@ -2965,75 +2966,41 @@ fannot._erase()
29652966
// Show a PDF page
29662967
//---------------------------------------------------------------------
29672968
FITZEXCEPTION(_showPDFpage, !result)
2968-
PyObject *_showPDFpage(PyObject *rect, struct fz_document_s *docsrc, int pno=0, int overlay=1, int keep_proportion=1, int reuse_xref=0, PyObject *clip = NULL, struct pdf_graft_map_s *graftmap = NULL, char *_imgname = NULL)
2969+
PyObject *_showPDFpage(PyObject *rect, struct fz_document_s *docsrc, int pno=0, int overlay=1, int keep_proportion=1, PyObject *matrix=NULL, int reuse_xref=0, PyObject *clip = NULL, struct pdf_graft_map_s *graftmap = NULL, char *_imgname = NULL)
29692970
{
29702971
int xref = reuse_xref;
29712972
pdf_obj *xobj1, *xobj2, *resources, *o;
29722973
fz_buffer *res, *nres;
2973-
fz_rect mediabox;
2974-
fz_rect cropbox;
2974+
fz_matrix inv_ctm = fz_identity;
2975+
fz_rect cropbox = fz_empty_rect;
29752976
fz_rect rrect = JM_rect_from_py(rect);
2977+
fz_matrix mat = JM_matrix_from_py(matrix);
29762978
fz_try(gctx)
29772979
{
2978-
pdf_page *tpage = pdf_page_from_fz_page(gctx, $self);
2979-
assert_PDF(tpage);
29802980
if (fz_is_infinite_rect(rrect) || fz_is_empty_rect(rrect))
29812981
THROWMSG("rect must be finite and not empty");
2982+
2983+
pdf_page *tpage = pdf_page_from_fz_page(gctx, $self);
29822984
pdf_obj *tpageref = tpage->obj;
29832985
pdf_document *pdfout = tpage->doc; // target PDF
29842986
pdf_document *pdfsrc = pdf_specifics(gctx, docsrc);
2985-
assert_PDF(pdfsrc);
29862987
29872988
//-------------------------------------------------------------
2988-
// make XObject of source page and get its xref
2989+
// make XObject out of the source page pno, get its xref,
2990+
// mediabox and cropbox.
29892991
//-------------------------------------------------------------
29902992
xobj1 = JM_xobject_from_page(gctx, pdfout, pdfsrc, pno,
2991-
&mediabox, &cropbox, xref, graftmap);
2993+
&inv_ctm, &cropbox, xref, graftmap);
29922994
xref = pdf_to_num(gctx, xobj1);
29932995
29942996
//-------------------------------------------------------------
29952997
// Calculate /Matrix and /BBox of the referencing XObject
29962998
//-------------------------------------------------------------
29972999
fz_rect rclip = JM_rect_from_py(clip);
2998-
if (!fz_is_infinite_rect(rclip)) // set cropbox if clip given
2999-
{
3000-
cropbox.x0 = rclip.x0;
3001-
cropbox.y0 = mediabox.y1 - rclip.y1;
3002-
cropbox.x1 = rclip.x1;
3003-
cropbox.y1 = mediabox.y1 - rclip.y0;
3004-
}
3005-
fz_matrix mat = fz_identity;
3006-
fz_rect prect = fz_bound_page(gctx, $self);
3007-
fz_rect r = fz_empty_rect;
3008-
o = pdf_dict_get_inheritable(gctx, tpageref, PDF_NAME(CropBox));
3009-
3010-
if (o)
3011-
{
3012-
r = pdf_to_rect(gctx, o);
3013-
prect.x0 = r.x0;
3014-
prect.y0 = r.y0;
3015-
}
3016-
o = pdf_dict_get_inheritable(gctx, tpageref, PDF_NAME(MediaBox));
3017-
3018-
if (o)
3000+
if (!fz_is_infinite_rect(rclip)) // set cropbox = clip
30193001
{
3020-
r = pdf_to_rect(gctx, o);
3021-
prect.x1 = r.x1;
3022-
prect.y1 = r.y1;
3002+
cropbox = fz_transform_rect(rclip, inv_ctm);
30233003
}
3024-
3025-
float W = rrect.x1 - rrect.x0;
3026-
float H = rrect.y1 - rrect.y0;
3027-
float fw = W / (cropbox.x1 - cropbox.x0);
3028-
float fh = H / (cropbox.y1 - cropbox.y0);
3029-
if ((fw < fh) && keep_proportion) // zoom factors in matrix
3030-
fh = fw;
3031-
float X = rrect.x0 + prect.x0 - fw*cropbox.x0;
3032-
float Y = prect.y1 - (rrect.y1 + prect.y0 + fh*cropbox.y0);
3033-
mat.a = fw;
3034-
mat.d = fh;
3035-
mat.e = X;
3036-
mat.f = Y;
30373004
30383005
//-------------------------------------------------------------
30393006
// create referencing XObject (controls actual display)
@@ -3173,7 +3140,7 @@ fannot._erase()
31733140
image = fz_new_image_from_file(gctx, filename);
31743141
else
31753142
{
3176-
imgbuf = fz_new_buffer_from_shared_data(gctx,
3143+
imgbuf = fz_new_buffer_from_copied_data(gctx,
31773144
streamdata, streamlen);
31783145
image = fz_new_image_from_buffer(gctx, imgbuf);
31793146
}
@@ -3219,6 +3186,7 @@ fannot._erase()
32193186
fz_drop_image(gctx, mask);
32203187
fz_drop_pixmap(gctx, pix);
32213188
fz_drop_pixmap(gctx, pm);
3189+
fz_drop_buffer(gctx, imgbuf);
32223190
}
32233191
fz_catch(gctx) return NULL;
32243192
pdf->dirty = 1;

fitz/fitz.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ class _object:
105105

106106

107107
VersionFitz = "1.14.0"
108-
VersionBind = "1.14.9"
109-
VersionDate = "2019-03-06 14:13:45"
110-
version = (VersionBind, VersionFitz, "20190306141345")
108+
VersionBind = "1.14.10"
109+
VersionDate = "2019-03-10 11:59:51"
110+
version = (VersionBind, VersionFitz, "20190310115951")
111111

112112

113113
class Matrix():
@@ -128,9 +128,9 @@ def __init__(self, *args):
128128
return None
129129
if len(args) == 1: # either an angle or a sequ
130130
if hasattr(args[0], "__float__"):
131-
theta = args[0] * math.pi / 180.0
132-
c = math.cos(theta)
133-
s = math.sin(theta)
131+
theta = math.radians(args[0])
132+
c = round(math.cos(theta), 8)
133+
s = round(math.sin(theta), 8)
134134
self.a = self.d = c
135135
self.b = s
136136
self.c = -s
@@ -221,8 +221,9 @@ def preRotate(self, theta):
221221
self.d = b
222222

223223
else:
224-
s = math.sin(theta * math.pi / 180.0)
225-
c = math.cos(theta * math.pi / 180.0)
224+
rad = math.radians(theta)
225+
s = round(math.sin(rad), 8)
226+
c = round(math.cos(rad), 8)
226227
a = self.a
227228
b = self.b
228229
self.a = c * a + s * self.c
@@ -269,7 +270,8 @@ def __mul__(self, m):
269270
if hasattr(m, "__float__"):
270271
return Matrix(self.a * m, self.b * m, self.c * m,
271272
self.d * m, self.e * m, self.f * m)
272-
return self.concat(self, m)
273+
m1 = Matrix(1,1)
274+
return m1.concat(self, m)
273275

274276
def __truediv__(self, m):
275277
if hasattr(m, "__float__"):
@@ -1238,10 +1240,13 @@ def _check5(self):
12381240

12391241
def getTextlength(text, fontname="helv", fontsize=11, encoding=0):
12401242
"""Calculate length of a string for a given built-in font.
1241-
:arg str fontname: name of the font.
1242-
:arg float fontsize: size of font in points.
1243-
:arg int encoding: encoding to use (0=Latin, 1=Greek, 2=Cyrillic).
1244-
:returns: (float) length of text.
1243+
1244+
Args:
1245+
fontname: name of the font.
1246+
fontsize: size of font in points.
1247+
encoding: encoding to use (0=Latin, 1=Greek, 2=Cyrillic).
1248+
Returns:
1249+
(float) length of text.
12451250
"""
12461251
fontname = fontname.lower()
12471252
basename = Base14_fontdict.get(fontname, None)
@@ -2922,9 +2927,9 @@ def _cleanContents(self):
29222927
return _fitz.Page__cleanContents(self)
29232928

29242929

2925-
def _showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None):
2926-
"""_showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *"""
2927-
return _fitz.Page__showPDFpage(self, rect, docsrc, pno, overlay, keep_proportion, reuse_xref, clip, graftmap, _imgname)
2930+
def _showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, matrix=None, reuse_xref=0, clip=None, graftmap=None, _imgname=None):
2931+
"""_showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, matrix=None, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *"""
2932+
return _fitz.Page__showPDFpage(self, rect, docsrc, pno, overlay, keep_proportion, matrix, reuse_xref, clip, graftmap, _imgname)
29282933

29292934

29302935
def insertImage(self, rect, filename=None, pixmap=None, stream=None, overlay=1, _imgname=None):

0 commit comments

Comments
 (0)