Skip to content

Commit

Permalink
upgrade to v1.16.5
Browse files Browse the repository at this point in the history
  • Loading branch information
JorjMcKie committed Oct 14, 2019
1 parent 61f7116 commit 5c7c36e
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 580 deletions.
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.16.4
Version: 1.16.5
Author: Ruikai Liu
Author-email: [email protected]
Maintainer: Jorj X. McKie
Expand All @@ -9,7 +9,7 @@ Home-page: https://github.com/pymupdf/PyMuPDF
Download-url: https://github.com/pymupdf/PyMuPDF
Summary: PyMuPDF is a Python binding for the PDF rendering library MuPDF
Description:
Release date: October 10, 2019
Release date: October 15, 2019

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

This is **version 1.16.4 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
This is **version 1.16.5 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# PyMuPDF 1.16.4
# PyMuPDF 1.16.5

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

Release date: October 10, 2019
Release date: October 15, 2019

**Travis-CI:** [![Build Status](https://travis-ci.org/JorjMcKie/py-mupdf.svg?branch=master)](https://travis-ci.org/JorjMcKie/py-mupdf)

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

# Introduction

This is **version 1.16.4 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.16.*](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
This is **version 1.16.5 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.16.*](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
Binary file modified doc/PyMuPDF.pdf
Binary file not shown.
Binary file modified doc/html.zip
Binary file not shown.
61 changes: 43 additions & 18 deletions fitz/fitz.i
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ dictkey_type = PyUnicode_FromString("type");
dictkey_ufilename = PyUnicode_FromString("ufilename");
dictkey_width = PyUnicode_FromString("width");
dictkey_wmode = PyUnicode_FromString("wmode");
dictkey_xref = PyUnicode_FromString("xref");
%}

%header %{
Expand Down Expand Up @@ -1561,8 +1562,7 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
fz_drop_buffer(gctx, buffer);
}
tuple = PyTuple_New(4);
PyTuple_SET_ITEM(tuple, 0, JM_EscapeStrFromStr(gctx,
pdf_to_name(gctx, bname)));
PyTuple_SET_ITEM(tuple, 0, JM_EscapeStrFromStr(pdf_to_name(gctx, bname)));
PyTuple_SET_ITEM(tuple, 1, Py_BuildValue("s", ext));
PyTuple_SET_ITEM(tuple, 2, Py_BuildValue("s",
pdf_to_name(gctx, subtype)));
Expand Down Expand Up @@ -2621,20 +2621,44 @@ struct fz_page_s {
return_none;
}
//---------------------------------------------------------------------
// Page.getTextPage
//---------------------------------------------------------------------
FITZEXCEPTION(getTextPage, !result)
%feature("autodoc","Create a TextPage directly from the page.") getTextPage;
%pythonprepend getTextPage %{
CheckParent(self)
%}
struct fz_stext_page_s *getTextPage(int flags=0)
{
fz_stext_page *textpage=NULL;
fz_try(gctx)
{
textpage = JM_new_stext_page_from_page(gctx, $self, flags);
}
fz_catch(gctx)
{
return NULL;
}
return textpage;
}
//---------------------------------------------------------------------
// Page.getSVGimage
//---------------------------------------------------------------------
FITZEXCEPTION(getSVGimage, !result)
%feature("autodoc","Create an SVG image from the page.") getSVGimage;
PARENTCHECK(getSVGimage)
%pythonprepend getSVGimage %{
CheckParent(self)
%}
PyObject *getSVGimage(PyObject *matrix = NULL)
{
fz_rect mediabox = fz_bound_page(gctx, $self);
fz_device *dev = NULL;
fz_buffer *res = NULL;
PyObject *text = NULL;
fz_matrix ctm = JM_matrix_from_py(matrix);
fz_cookie *cookie = NULL;
fz_output *out = NULL;
fz_separations *seps = NULL;
fz_var(out);
Expand All @@ -2648,7 +2672,7 @@ struct fz_page_s {
res = fz_new_buffer(gctx, 1024);
out = fz_new_output_with_buffer(gctx, res);
dev = fz_new_svg_device(gctx, out, tbounds.x1-tbounds.x0, tbounds.y1-tbounds.y0, FZ_SVG_TEXT_AS_PATH, 1);
fz_run_page(gctx, $self, dev, ctm, cookie);
fz_run_page(gctx, $self, dev, ctm, NULL);
fz_close_device(gctx, dev);
text = JM_StrFromBuffer(gctx, res);
}
Expand Down Expand Up @@ -3104,10 +3128,12 @@ struct fz_page_s {
}
//---------------------------------------------------------------------
// getDisplayList()
// Page.getDisplayList()
//---------------------------------------------------------------------
FITZEXCEPTION(getDisplayList, !result)
PARENTCHECK(getDisplayList)
%pythonprepend getDisplayList %{
CheckParent(self)
%}
struct fz_display_list_s *getDisplayList(int annots=1)
{
fz_display_list *dl = NULL;
Expand Down Expand Up @@ -3251,7 +3277,7 @@ except:
if (!PyDict_Check(linkdict)) return; // have no dictionary
pdf_page *page = pdf_page_from_fz_page(gctx, $self);
if (!page) return; // have no PDF
int xref = (int) PyInt_AsLong(PyDict_GetItemString(linkdict, "xref"));
int xref = (int) PyInt_AsLong(PyDict_GetItem(linkdict, dictkey_xref));
if (xref < 1) return; // invalid xref
pdf_obj *annots = pdf_dict_get(gctx, page->obj, PDF_NAME(Annots));
if (!annots) return; // have no annotations
Expand Down Expand Up @@ -5383,8 +5409,8 @@ struct pdf_annot_s
{
if (!PyDict_Check(colors)) return;
PyObject *ccol, *icol;
ccol = PyDict_GetItemString(colors, "stroke");
icol = PyDict_GetItemString(colors, "fill");
ccol = PyDict_GetItem(colors, dictkey_stroke);
icol = PyDict_GetItem(colors, dictkey_fill);
int i, n;
float col[4];
n = 0;
Expand Down Expand Up @@ -5734,7 +5760,7 @@ CheckParent(self)
THROWMSG("info not a dict");
// contents
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "content"));
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_content));
if (uc)
{
pdf_set_annot_contents(gctx, $self, uc);
Expand All @@ -5744,16 +5770,15 @@ CheckParent(self)
if (is_markup)
{
// title (= author)
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "title"));
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_title));
if (uc)
{
pdf_set_annot_author(gctx, $self, uc);
JM_Python_str_DelForPy3(uc);
}
// creation date
uc = JM_Python_str_AsChar(PyDict_GetItemString(info,
"creationDate"));
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_creationDate));
if (uc)
{
pdf_dict_put_text_string(gctx, $self->obj,
Expand All @@ -5762,7 +5787,7 @@ CheckParent(self)
}
// mod date
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "modDate"));
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_modDate));
if (uc)
{
pdf_dict_put_text_string(gctx, $self->obj,
Expand All @@ -5771,7 +5796,7 @@ CheckParent(self)
}
// subject
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "subject"));
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_subject));
if (uc)
{
pdf_dict_puts_drop(gctx, $self->obj, "Subj",
Expand Down Expand Up @@ -5978,8 +6003,8 @@ struct fz_link_s
int nscol = 0;
float fcol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
int nfcol = 0;
PyObject *stroke = PyDict_GetItemString(colors, "stroke");
PyObject *fill = PyDict_GetItemString(colors, "fill");
PyObject *stroke = PyDict_GetItem(colors, dictkey_stroke);
PyObject *fill = PyDict_GetItem(colors, dictkey_fill);
JM_color_FromSequence(stroke, &nscol, scol);
JM_color_FromSequence(fill, &nfcol, fcol);
if (!nscol && !nfcol) return_none;
Expand Down
12 changes: 6 additions & 6 deletions fitz/helper-annot.i
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ PyObject *JM_annot_set_border(fz_context *ctx, PyObject *border, pdf_document *d
PyObject *nstyle = NULL; // new style
PyObject *ostyle = NULL; // old style

nwidth = PyFloat_AsDouble(PyDict_GetItemString(border, "width"));
ndashes = PyDict_GetItemString(border, "dashes");
nstyle = PyDict_GetItemString(border, "style");
nwidth = PyFloat_AsDouble(PyDict_GetItem(border, dictkey_width));
ndashes = PyDict_GetItem(border, dictkey_dashes);
nstyle = PyDict_GetItem(border, dictkey_style);

// first get old border properties
PyObject *oborder = JM_annot_border(ctx, annot_obj);
owidth = PyFloat_AsDouble(PyDict_GetItemString(oborder, "width"));
odashes = PyDict_GetItemString(oborder, "dashes");
ostyle = PyDict_GetItemString(oborder, "style");
owidth = PyFloat_AsDouble(PyDict_GetItem(oborder, dictkey_width));
odashes = PyDict_GetItem(oborder, dictkey_dashes);
ostyle = PyDict_GetItem(oborder, dictkey_style);

// then delete any relevant entries
pdf_dict_del(ctx, annot_obj, PDF_NAME(BS));
Expand Down
1 change: 1 addition & 0 deletions fitz/helper-defines.i
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,6 @@ PyObject *dictkey_type;
PyObject *dictkey_ufilename;
PyObject *dictkey_width;
PyObject *dictkey_wmode;
PyObject *dictkey_xref;

%}
45 changes: 43 additions & 2 deletions fitz/helper-other.i
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
%{

PyObject *JM_StrFromBuffer(fz_context *ctx, fz_buffer *buff)
{
if (!buff) return PyUnicode_FromString("");
unsigned char *s = NULL;
size_t len = fz_buffer_storage(ctx, buff, &s);
PyObject *val = PyUnicode_DecodeUTF8(s, (Py_ssize_t) len, "replace");
if (!val)
{
val = PyUnicode_FromString("");
PyErr_Clear();
}
return val;
}


PyObject *JM_EscapeStrFromBuffer(fz_context *ctx, fz_buffer *buff)
{
if (!buff) return PyUnicode_FromString("");
unsigned char *s = NULL;
size_t len = fz_buffer_storage(ctx, buff, &s);
PyObject *val = PyUnicode_DecodeUnicodeEscape(s, (Py_ssize_t) len, "replace");
if (!val)
{
val = PyUnicode_FromString("");
PyErr_Clear();
}
return val;
}

PyObject *JM_EscapeStrFromStr(const char *c)
{
if (!c) return PyUnicode_FromString("");
PyObject *val = PyUnicode_DecodeUnicodeEscape(c, (Py_ssize_t) strlen(c), "replace");
if (!val)
{
val = PyUnicode_FromString("");
PyErr_Clear();
}
return val;
}

// redirect MuPDF warnings
void JM_mupdf_warning(void *user, const char *message)
{

PyObject *val = Py_BuildValue("s", message);
PyObject *val = JM_EscapeStrFromStr(message);
PyList_Append(JM_mupdf_warnings_store, val);
Py_DECREF(val);
}
Expand Down
18 changes: 9 additions & 9 deletions fitz/helper-pdfinfo.i
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ void JM_gather_fonts(fz_context *ctx, pdf_document *pdf, pdf_obj *dict,
PyObject *entry = PyList_New(6);
PyList_SET_ITEM(entry, 0, Py_BuildValue("i", xref));
PyList_SET_ITEM(entry, 1, Py_BuildValue("s", ext));
PyList_SET_ITEM(entry, 2, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, subtype)));
PyList_SET_ITEM(entry, 3, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, name)));
PyList_SET_ITEM(entry, 4, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, refname)));
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, encoding)));
PyList_SET_ITEM(entry, 2, JM_EscapeStrFromStr(pdf_to_name(ctx, subtype)));
PyList_SET_ITEM(entry, 3, JM_EscapeStrFromStr(pdf_to_name(ctx, name)));
PyList_SET_ITEM(entry, 4, JM_EscapeStrFromStr(pdf_to_name(ctx, refname)));
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(pdf_to_name(ctx, encoding)));
PyList_Append(fontlist, entry);
Py_DECREF(entry);
}
Expand Down Expand Up @@ -149,10 +149,10 @@ void JM_gather_images(fz_context *ctx, pdf_document *doc, pdf_obj *dict,
PyList_SET_ITEM(entry, 2, Py_BuildValue("i", pdf_to_int(ctx, width)));
PyList_SET_ITEM(entry, 3, Py_BuildValue("i", pdf_to_int(ctx, height)));
PyList_SET_ITEM(entry, 4, Py_BuildValue("i", pdf_to_int(ctx, bpc)));
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, cs)));
PyList_SET_ITEM(entry, 6, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, altcs)));
PyList_SET_ITEM(entry, 7, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, refname)));
PyList_SET_ITEM(entry, 8, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, filter)));
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(pdf_to_name(ctx, cs)));
PyList_SET_ITEM(entry, 6, JM_EscapeStrFromStr(pdf_to_name(ctx, altcs)));
PyList_SET_ITEM(entry, 7, JM_EscapeStrFromStr(pdf_to_name(ctx, refname)));
PyList_SET_ITEM(entry, 8, JM_EscapeStrFromStr(pdf_to_name(ctx, filter)));
PyList_Append(imagelist, entry);
Py_DECREF(entry);
}
Expand Down Expand Up @@ -189,7 +189,7 @@ void JM_gather_forms(fz_context *ctx, pdf_document *doc, pdf_obj *dict,

PyObject *entry = PyList_New(2);
PyList_SET_ITEM(entry, 0, Py_BuildValue("i", xref));
PyList_SET_ITEM(entry, 1, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, refname)));
PyList_SET_ITEM(entry, 1, JM_EscapeStrFromStr(pdf_to_name(ctx, refname)));
PyList_Append(imagelist, entry);
Py_DECREF(entry);
}
Expand Down
1 change: 1 addition & 0 deletions fitz/helper-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ def CheckFont(page, fontname):
if f[3].lower() == fontname.lower():
return f


def CheckFontInfo(doc, xref):
"""Return a font info if present in the document.
"""
Expand Down
Loading

0 comments on commit 5c7c36e

Please sign in to comment.