Skip to content

Commit 5c7c36e

Browse files
committed
upgrade to v1.16.5
1 parent 61f7116 commit 5c7c36e

15 files changed

+139
-580
lines changed

PKG-INFO

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.1
22
Name: PyMuPDF
3-
Version: 1.16.4
3+
Version: 1.16.5
44
Author: Ruikai Liu
55
Author-email: [email protected]
66
Maintainer: Jorj X. McKie
@@ -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: October 10, 2019
12+
Release date: October 15, 2019
1313

1414
Authors
1515
=======
@@ -20,7 +20,7 @@ Description:
2020
Introduction
2121
============
2222

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

2525
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.
2626

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# PyMuPDF 1.16.4
1+
# PyMuPDF 1.16.5
22

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

5-
Release date: October 10, 2019
5+
Release date: October 15, 2019
66

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

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

1515
# Introduction
1616

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

doc/PyMuPDF.pdf

1.65 KB
Binary file not shown.

doc/html.zip

3.19 KB
Binary file not shown.

fitz/fitz.i

+43-18
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ dictkey_type = PyUnicode_FromString("type");
214214
dictkey_ufilename = PyUnicode_FromString("ufilename");
215215
dictkey_width = PyUnicode_FromString("width");
216216
dictkey_wmode = PyUnicode_FromString("wmode");
217+
dictkey_xref = PyUnicode_FromString("xref");
217218
%}
218219

219220
%header %{
@@ -1561,8 +1562,7 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
15611562
fz_drop_buffer(gctx, buffer);
15621563
}
15631564
tuple = PyTuple_New(4);
1564-
PyTuple_SET_ITEM(tuple, 0, JM_EscapeStrFromStr(gctx,
1565-
pdf_to_name(gctx, bname)));
1565+
PyTuple_SET_ITEM(tuple, 0, JM_EscapeStrFromStr(pdf_to_name(gctx, bname)));
15661566
PyTuple_SET_ITEM(tuple, 1, Py_BuildValue("s", ext));
15671567
PyTuple_SET_ITEM(tuple, 2, Py_BuildValue("s",
15681568
pdf_to_name(gctx, subtype)));
@@ -2621,20 +2621,44 @@ struct fz_page_s {
26212621
return_none;
26222622
}
26232623
2624+
//---------------------------------------------------------------------
2625+
// Page.getTextPage
2626+
//---------------------------------------------------------------------
2627+
FITZEXCEPTION(getTextPage, !result)
2628+
%feature("autodoc","Create a TextPage directly from the page.") getTextPage;
2629+
%pythonprepend getTextPage %{
2630+
CheckParent(self)
2631+
%}
2632+
struct fz_stext_page_s *getTextPage(int flags=0)
2633+
{
2634+
fz_stext_page *textpage=NULL;
2635+
fz_try(gctx)
2636+
{
2637+
textpage = JM_new_stext_page_from_page(gctx, $self, flags);
2638+
}
2639+
fz_catch(gctx)
2640+
{
2641+
return NULL;
2642+
}
2643+
return textpage;
2644+
}
2645+
2646+
26242647
//---------------------------------------------------------------------
26252648
// Page.getSVGimage
26262649
//---------------------------------------------------------------------
26272650
FITZEXCEPTION(getSVGimage, !result)
26282651
%feature("autodoc","Create an SVG image from the page.") getSVGimage;
2629-
PARENTCHECK(getSVGimage)
2652+
%pythonprepend getSVGimage %{
2653+
CheckParent(self)
2654+
%}
26302655
PyObject *getSVGimage(PyObject *matrix = NULL)
26312656
{
26322657
fz_rect mediabox = fz_bound_page(gctx, $self);
26332658
fz_device *dev = NULL;
26342659
fz_buffer *res = NULL;
26352660
PyObject *text = NULL;
26362661
fz_matrix ctm = JM_matrix_from_py(matrix);
2637-
fz_cookie *cookie = NULL;
26382662
fz_output *out = NULL;
26392663
fz_separations *seps = NULL;
26402664
fz_var(out);
@@ -2648,7 +2672,7 @@ struct fz_page_s {
26482672
res = fz_new_buffer(gctx, 1024);
26492673
out = fz_new_output_with_buffer(gctx, res);
26502674
dev = fz_new_svg_device(gctx, out, tbounds.x1-tbounds.x0, tbounds.y1-tbounds.y0, FZ_SVG_TEXT_AS_PATH, 1);
2651-
fz_run_page(gctx, $self, dev, ctm, cookie);
2675+
fz_run_page(gctx, $self, dev, ctm, NULL);
26522676
fz_close_device(gctx, dev);
26532677
text = JM_StrFromBuffer(gctx, res);
26542678
}
@@ -3104,10 +3128,12 @@ struct fz_page_s {
31043128
}
31053129
31063130
//---------------------------------------------------------------------
3107-
// getDisplayList()
3131+
// Page.getDisplayList()
31083132
//---------------------------------------------------------------------
31093133
FITZEXCEPTION(getDisplayList, !result)
3110-
PARENTCHECK(getDisplayList)
3134+
%pythonprepend getDisplayList %{
3135+
CheckParent(self)
3136+
%}
31113137
struct fz_display_list_s *getDisplayList(int annots=1)
31123138
{
31133139
fz_display_list *dl = NULL;
@@ -3251,7 +3277,7 @@ except:
32513277
if (!PyDict_Check(linkdict)) return; // have no dictionary
32523278
pdf_page *page = pdf_page_from_fz_page(gctx, $self);
32533279
if (!page) return; // have no PDF
3254-
int xref = (int) PyInt_AsLong(PyDict_GetItemString(linkdict, "xref"));
3280+
int xref = (int) PyInt_AsLong(PyDict_GetItem(linkdict, dictkey_xref));
32553281
if (xref < 1) return; // invalid xref
32563282
pdf_obj *annots = pdf_dict_get(gctx, page->obj, PDF_NAME(Annots));
32573283
if (!annots) return; // have no annotations
@@ -5383,8 +5409,8 @@ struct pdf_annot_s
53835409
{
53845410
if (!PyDict_Check(colors)) return;
53855411
PyObject *ccol, *icol;
5386-
ccol = PyDict_GetItemString(colors, "stroke");
5387-
icol = PyDict_GetItemString(colors, "fill");
5412+
ccol = PyDict_GetItem(colors, dictkey_stroke);
5413+
icol = PyDict_GetItem(colors, dictkey_fill);
53885414
int i, n;
53895415
float col[4];
53905416
n = 0;
@@ -5734,7 +5760,7 @@ CheckParent(self)
57345760
THROWMSG("info not a dict");
57355761
57365762
// contents
5737-
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "content"));
5763+
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_content));
57385764
if (uc)
57395765
{
57405766
pdf_set_annot_contents(gctx, $self, uc);
@@ -5744,16 +5770,15 @@ CheckParent(self)
57445770
if (is_markup)
57455771
{
57465772
// title (= author)
5747-
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "title"));
5773+
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_title));
57485774
if (uc)
57495775
{
57505776
pdf_set_annot_author(gctx, $self, uc);
57515777
JM_Python_str_DelForPy3(uc);
57525778
}
57535779
57545780
// creation date
5755-
uc = JM_Python_str_AsChar(PyDict_GetItemString(info,
5756-
"creationDate"));
5781+
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_creationDate));
57575782
if (uc)
57585783
{
57595784
pdf_dict_put_text_string(gctx, $self->obj,
@@ -5762,7 +5787,7 @@ CheckParent(self)
57625787
}
57635788
57645789
// mod date
5765-
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "modDate"));
5790+
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_modDate));
57665791
if (uc)
57675792
{
57685793
pdf_dict_put_text_string(gctx, $self->obj,
@@ -5771,7 +5796,7 @@ CheckParent(self)
57715796
}
57725797
57735798
// subject
5774-
uc = JM_Python_str_AsChar(PyDict_GetItemString(info, "subject"));
5799+
uc = JM_Python_str_AsChar(PyDict_GetItem(info, dictkey_subject));
57755800
if (uc)
57765801
{
57775802
pdf_dict_puts_drop(gctx, $self->obj, "Subj",
@@ -5978,8 +6003,8 @@ struct fz_link_s
59786003
int nscol = 0;
59796004
float fcol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
59806005
int nfcol = 0;
5981-
PyObject *stroke = PyDict_GetItemString(colors, "stroke");
5982-
PyObject *fill = PyDict_GetItemString(colors, "fill");
6006+
PyObject *stroke = PyDict_GetItem(colors, dictkey_stroke);
6007+
PyObject *fill = PyDict_GetItem(colors, dictkey_fill);
59836008
JM_color_FromSequence(stroke, &nscol, scol);
59846009
JM_color_FromSequence(fill, &nfcol, fcol);
59856010
if (!nscol && !nfcol) return_none;

fitz/helper-annot.i

+6-6
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ PyObject *JM_annot_set_border(fz_context *ctx, PyObject *border, pdf_document *d
173173
PyObject *nstyle = NULL; // new style
174174
PyObject *ostyle = NULL; // old style
175175

176-
nwidth = PyFloat_AsDouble(PyDict_GetItemString(border, "width"));
177-
ndashes = PyDict_GetItemString(border, "dashes");
178-
nstyle = PyDict_GetItemString(border, "style");
176+
nwidth = PyFloat_AsDouble(PyDict_GetItem(border, dictkey_width));
177+
ndashes = PyDict_GetItem(border, dictkey_dashes);
178+
nstyle = PyDict_GetItem(border, dictkey_style);
179179

180180
// first get old border properties
181181
PyObject *oborder = JM_annot_border(ctx, annot_obj);
182-
owidth = PyFloat_AsDouble(PyDict_GetItemString(oborder, "width"));
183-
odashes = PyDict_GetItemString(oborder, "dashes");
184-
ostyle = PyDict_GetItemString(oborder, "style");
182+
owidth = PyFloat_AsDouble(PyDict_GetItem(oborder, dictkey_width));
183+
odashes = PyDict_GetItem(oborder, dictkey_dashes);
184+
ostyle = PyDict_GetItem(oborder, dictkey_style);
185185

186186
// then delete any relevant entries
187187
pdf_dict_del(ctx, annot_obj, PDF_NAME(BS));

fitz/helper-defines.i

+1
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,6 @@ PyObject *dictkey_type;
277277
PyObject *dictkey_ufilename;
278278
PyObject *dictkey_width;
279279
PyObject *dictkey_wmode;
280+
PyObject *dictkey_xref;
280281

281282
%}

fitz/helper-other.i

+43-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
%{
2+
3+
PyObject *JM_StrFromBuffer(fz_context *ctx, fz_buffer *buff)
4+
{
5+
if (!buff) return PyUnicode_FromString("");
6+
unsigned char *s = NULL;
7+
size_t len = fz_buffer_storage(ctx, buff, &s);
8+
PyObject *val = PyUnicode_DecodeUTF8(s, (Py_ssize_t) len, "replace");
9+
if (!val)
10+
{
11+
val = PyUnicode_FromString("");
12+
PyErr_Clear();
13+
}
14+
return val;
15+
}
16+
17+
18+
PyObject *JM_EscapeStrFromBuffer(fz_context *ctx, fz_buffer *buff)
19+
{
20+
if (!buff) return PyUnicode_FromString("");
21+
unsigned char *s = NULL;
22+
size_t len = fz_buffer_storage(ctx, buff, &s);
23+
PyObject *val = PyUnicode_DecodeUnicodeEscape(s, (Py_ssize_t) len, "replace");
24+
if (!val)
25+
{
26+
val = PyUnicode_FromString("");
27+
PyErr_Clear();
28+
}
29+
return val;
30+
}
31+
32+
PyObject *JM_EscapeStrFromStr(const char *c)
33+
{
34+
if (!c) return PyUnicode_FromString("");
35+
PyObject *val = PyUnicode_DecodeUnicodeEscape(c, (Py_ssize_t) strlen(c), "replace");
36+
if (!val)
37+
{
38+
val = PyUnicode_FromString("");
39+
PyErr_Clear();
40+
}
41+
return val;
42+
}
43+
244
// redirect MuPDF warnings
345
void JM_mupdf_warning(void *user, const char *message)
446
{
5-
6-
PyObject *val = Py_BuildValue("s", message);
47+
PyObject *val = JM_EscapeStrFromStr(message);
748
PyList_Append(JM_mupdf_warnings_store, val);
849
Py_DECREF(val);
950
}

fitz/helper-pdfinfo.i

+9-9
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ void JM_gather_fonts(fz_context *ctx, pdf_document *pdf, pdf_obj *dict,
7575
PyObject *entry = PyList_New(6);
7676
PyList_SET_ITEM(entry, 0, Py_BuildValue("i", xref));
7777
PyList_SET_ITEM(entry, 1, Py_BuildValue("s", ext));
78-
PyList_SET_ITEM(entry, 2, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, subtype)));
79-
PyList_SET_ITEM(entry, 3, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, name)));
80-
PyList_SET_ITEM(entry, 4, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, refname)));
81-
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, encoding)));
78+
PyList_SET_ITEM(entry, 2, JM_EscapeStrFromStr(pdf_to_name(ctx, subtype)));
79+
PyList_SET_ITEM(entry, 3, JM_EscapeStrFromStr(pdf_to_name(ctx, name)));
80+
PyList_SET_ITEM(entry, 4, JM_EscapeStrFromStr(pdf_to_name(ctx, refname)));
81+
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(pdf_to_name(ctx, encoding)));
8282
PyList_Append(fontlist, entry);
8383
Py_DECREF(entry);
8484
}
@@ -149,10 +149,10 @@ void JM_gather_images(fz_context *ctx, pdf_document *doc, pdf_obj *dict,
149149
PyList_SET_ITEM(entry, 2, Py_BuildValue("i", pdf_to_int(ctx, width)));
150150
PyList_SET_ITEM(entry, 3, Py_BuildValue("i", pdf_to_int(ctx, height)));
151151
PyList_SET_ITEM(entry, 4, Py_BuildValue("i", pdf_to_int(ctx, bpc)));
152-
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, cs)));
153-
PyList_SET_ITEM(entry, 6, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, altcs)));
154-
PyList_SET_ITEM(entry, 7, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, refname)));
155-
PyList_SET_ITEM(entry, 8, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, filter)));
152+
PyList_SET_ITEM(entry, 5, JM_EscapeStrFromStr(pdf_to_name(ctx, cs)));
153+
PyList_SET_ITEM(entry, 6, JM_EscapeStrFromStr(pdf_to_name(ctx, altcs)));
154+
PyList_SET_ITEM(entry, 7, JM_EscapeStrFromStr(pdf_to_name(ctx, refname)));
155+
PyList_SET_ITEM(entry, 8, JM_EscapeStrFromStr(pdf_to_name(ctx, filter)));
156156
PyList_Append(imagelist, entry);
157157
Py_DECREF(entry);
158158
}
@@ -189,7 +189,7 @@ void JM_gather_forms(fz_context *ctx, pdf_document *doc, pdf_obj *dict,
189189

190190
PyObject *entry = PyList_New(2);
191191
PyList_SET_ITEM(entry, 0, Py_BuildValue("i", xref));
192-
PyList_SET_ITEM(entry, 1, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, refname)));
192+
PyList_SET_ITEM(entry, 1, JM_EscapeStrFromStr(pdf_to_name(ctx, refname)));
193193
PyList_Append(imagelist, entry);
194194
Py_DECREF(entry);
195195
}

fitz/helper-python.i

+1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ def CheckFont(page, fontname):
565565
if f[3].lower() == fontname.lower():
566566
return f
567567

568+
568569
def CheckFontInfo(doc, xref):
569570
"""Return a font info if present in the document.
570571
"""

0 commit comments

Comments
 (0)