Skip to content

Commit

Permalink
Merge pull request #264 from JorjMcKie/master
Browse files Browse the repository at this point in the history
Upgrade to v1.14.10
  • Loading branch information
JorjMcKie authored Mar 10, 2019
2 parents 222b4d0 + 4c4eb76 commit 52a2d34
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ matrix:
prefix=/usr/local install && cd .."
- export CIBW_ENVIRONMENT='CFLAGS=-fPIC'
install:
- "$PIP install cibuildwheel==0.10.1"
- "$PIP install cibuildwheel"
- mkdir mupdf && wget -q $MUPDF -O - | tar zx -C mupdf --strip-components=1
- cp fitz/_mupdf_config.h mupdf/include/mupdf/fitz/config.h
- cp fitz/_pdf-device.c mupdf/source/pdf/pdf-device.c
Expand Down
6 changes: 3 additions & 3 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.14.9
Version: 1.14.10
Author: Ruikai Liu
Author-email: [email protected]
Maintainer: Jorj X. McKie
Expand All @@ -10,7 +10,7 @@ Download-url: https://github.com/pymupdf/PyMuPDF
Summary: PyMuPDF is a Python binding for the PDF rendering library MuPDF
Description:

Release date: March 6, 2019
Release date: March 10, 2019

Authors
=======
Expand All @@ -21,7 +21,7 @@ Description:
Introduction
============

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

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.

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.14.9
# PyMuPDF 1.14.10

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

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

# Introduction

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".
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".

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
64 changes: 16 additions & 48 deletions fitz/fitz.i
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ if links:
else
{
// handling JPX
buffer = pdf_load_stream(gctx, obj);
buffer = pdf_load_stream_number(gctx, pdf, xref);
freebuf = buffer; // so it will be dropped!
type = FZ_IMAGE_JPX;
o = pdf_dict_get(gctx, obj, PDF_NAME(ColorSpace));
Expand Down Expand Up @@ -1837,7 +1837,8 @@ if links:
new_obj = JM_pdf_obj_from_str(gctx, pdf, text);
pdf_update_object(gctx, pdf, xref, new_obj);
pdf_drop_obj(gctx, new_obj);
if (page) refresh_link_table(gctx, pdf_page_from_fz_page(gctx, page));
if (page)
refresh_link_table(gctx, pdf_page_from_fz_page(gctx, page));
}
fz_catch(gctx) return NULL;
pdf->dirty = 1;
Expand Down Expand Up @@ -2965,75 +2966,41 @@ fannot._erase()
// Show a PDF page
//---------------------------------------------------------------------
FITZEXCEPTION(_showPDFpage, !result)
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)
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)
{
int xref = reuse_xref;
pdf_obj *xobj1, *xobj2, *resources, *o;
fz_buffer *res, *nres;
fz_rect mediabox;
fz_rect cropbox;
fz_matrix inv_ctm = fz_identity;
fz_rect cropbox = fz_empty_rect;
fz_rect rrect = JM_rect_from_py(rect);
fz_matrix mat = JM_matrix_from_py(matrix);
fz_try(gctx)
{
pdf_page *tpage = pdf_page_from_fz_page(gctx, $self);
assert_PDF(tpage);
if (fz_is_infinite_rect(rrect) || fz_is_empty_rect(rrect))
THROWMSG("rect must be finite and not empty");
pdf_page *tpage = pdf_page_from_fz_page(gctx, $self);
pdf_obj *tpageref = tpage->obj;
pdf_document *pdfout = tpage->doc; // target PDF
pdf_document *pdfsrc = pdf_specifics(gctx, docsrc);
assert_PDF(pdfsrc);
//-------------------------------------------------------------
// make XObject of source page and get its xref
// make XObject out of the source page pno, get its xref,
// mediabox and cropbox.
//-------------------------------------------------------------
xobj1 = JM_xobject_from_page(gctx, pdfout, pdfsrc, pno,
&mediabox, &cropbox, xref, graftmap);
&inv_ctm, &cropbox, xref, graftmap);
xref = pdf_to_num(gctx, xobj1);
//-------------------------------------------------------------
// Calculate /Matrix and /BBox of the referencing XObject
//-------------------------------------------------------------
fz_rect rclip = JM_rect_from_py(clip);
if (!fz_is_infinite_rect(rclip)) // set cropbox if clip given
{
cropbox.x0 = rclip.x0;
cropbox.y0 = mediabox.y1 - rclip.y1;
cropbox.x1 = rclip.x1;
cropbox.y1 = mediabox.y1 - rclip.y0;
}
fz_matrix mat = fz_identity;
fz_rect prect = fz_bound_page(gctx, $self);
fz_rect r = fz_empty_rect;
o = pdf_dict_get_inheritable(gctx, tpageref, PDF_NAME(CropBox));
if (o)
{
r = pdf_to_rect(gctx, o);
prect.x0 = r.x0;
prect.y0 = r.y0;
}
o = pdf_dict_get_inheritable(gctx, tpageref, PDF_NAME(MediaBox));
if (o)
if (!fz_is_infinite_rect(rclip)) // set cropbox = clip
{
r = pdf_to_rect(gctx, o);
prect.x1 = r.x1;
prect.y1 = r.y1;
cropbox = fz_transform_rect(rclip, inv_ctm);
}
float W = rrect.x1 - rrect.x0;
float H = rrect.y1 - rrect.y0;
float fw = W / (cropbox.x1 - cropbox.x0);
float fh = H / (cropbox.y1 - cropbox.y0);
if ((fw < fh) && keep_proportion) // zoom factors in matrix
fh = fw;
float X = rrect.x0 + prect.x0 - fw*cropbox.x0;
float Y = prect.y1 - (rrect.y1 + prect.y0 + fh*cropbox.y0);
mat.a = fw;
mat.d = fh;
mat.e = X;
mat.f = Y;
//-------------------------------------------------------------
// create referencing XObject (controls actual display)
Expand Down Expand Up @@ -3173,7 +3140,7 @@ fannot._erase()
image = fz_new_image_from_file(gctx, filename);
else
{
imgbuf = fz_new_buffer_from_shared_data(gctx,
imgbuf = fz_new_buffer_from_copied_data(gctx,
streamdata, streamlen);
image = fz_new_image_from_buffer(gctx, imgbuf);
}
Expand Down Expand Up @@ -3219,6 +3186,7 @@ fannot._erase()
fz_drop_image(gctx, mask);
fz_drop_pixmap(gctx, pix);
fz_drop_pixmap(gctx, pm);
fz_drop_buffer(gctx, imgbuf);
}
fz_catch(gctx) return NULL;
pdf->dirty = 1;
Expand Down
37 changes: 21 additions & 16 deletions fitz/fitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class _object:


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


class Matrix():
Expand All @@ -128,9 +128,9 @@ def __init__(self, *args):
return None
if len(args) == 1: # either an angle or a sequ
if hasattr(args[0], "__float__"):
theta = args[0] * math.pi / 180.0
c = math.cos(theta)
s = math.sin(theta)
theta = math.radians(args[0])
c = round(math.cos(theta), 8)
s = round(math.sin(theta), 8)
self.a = self.d = c
self.b = s
self.c = -s
Expand Down Expand Up @@ -221,8 +221,9 @@ def preRotate(self, theta):
self.d = b

else:
s = math.sin(theta * math.pi / 180.0)
c = math.cos(theta * math.pi / 180.0)
rad = math.radians(theta)
s = round(math.sin(rad), 8)
c = round(math.cos(rad), 8)
a = self.a
b = self.b
self.a = c * a + s * self.c
Expand Down Expand Up @@ -269,7 +270,8 @@ def __mul__(self, m):
if hasattr(m, "__float__"):
return Matrix(self.a * m, self.b * m, self.c * m,
self.d * m, self.e * m, self.f * m)
return self.concat(self, m)
m1 = Matrix(1,1)
return m1.concat(self, m)

def __truediv__(self, m):
if hasattr(m, "__float__"):
Expand Down Expand Up @@ -1238,10 +1240,13 @@ def _check5(self):

def getTextlength(text, fontname="helv", fontsize=11, encoding=0):
"""Calculate length of a string for a given built-in font.
:arg str fontname: name of the font.
:arg float fontsize: size of font in points.
:arg int encoding: encoding to use (0=Latin, 1=Greek, 2=Cyrillic).
:returns: (float) length of text.
Args:
fontname: name of the font.
fontsize: size of font in points.
encoding: encoding to use (0=Latin, 1=Greek, 2=Cyrillic).
Returns:
(float) length of text.
"""
fontname = fontname.lower()
basename = Base14_fontdict.get(fontname, None)
Expand Down Expand Up @@ -2922,9 +2927,9 @@ def _cleanContents(self):
return _fitz.Page__cleanContents(self)


def _showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None):
"""_showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *"""
return _fitz.Page__showPDFpage(self, rect, docsrc, pno, overlay, keep_proportion, reuse_xref, clip, graftmap, _imgname)
def _showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, matrix=None, reuse_xref=0, clip=None, graftmap=None, _imgname=None):
"""_showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, matrix=None, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *"""
return _fitz.Page__showPDFpage(self, rect, docsrc, pno, overlay, keep_proportion, matrix, reuse_xref, clip, graftmap, _imgname)


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

0 comments on commit 52a2d34

Please sign in to comment.