Skip to content

Commit 61f7116

Browse files
committed
upgrade to v1.16.4
1 parent 993cf64 commit 61f7116

File tree

9 files changed

+118
-42
lines changed

9 files changed

+118
-42
lines changed

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.16.3
3+
Version: 1.16.4
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: September 30, 2019
12+
Release date: October 10, 2019
1313

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# PyMuPDF 1.16.3
1+
# PyMuPDF 1.16.4
22

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

5-
Release date: September 30, 2019
5+
Release date: October 10, 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.3 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.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".
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

43.3 KB
Binary file not shown.

doc/html.zip

7.5 KB
Binary file not shown.

fitz/fitz.i

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
15381538
char *ext = NULL;
15391539
char *fontname = NULL;
15401540
PyObject *nulltuple = Py_BuildValue("sssO", "", "", "", bytes);
1541-
PyObject *tuple;
1541+
PyObject *tuple, *val;
15421542
Py_ssize_t len = 0;
15431543
fz_try(gctx)
15441544
{
@@ -1560,12 +1560,13 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
15601560
bytes = JM_BinFromBuffer(gctx, buffer);
15611561
fz_drop_buffer(gctx, buffer);
15621562
}
1563-
fontname = (char *) JM_ASCIIFromChar((char *) pdf_to_name(gctx, bname));
1564-
tuple = Py_BuildValue("sssO",
1565-
fontname,
1566-
ext,
1567-
pdf_to_name(gctx, subtype),
1568-
bytes);
1563+
tuple = PyTuple_New(4);
1564+
PyTuple_SET_ITEM(tuple, 0, JM_EscapeStrFromStr(gctx,
1565+
pdf_to_name(gctx, bname)));
1566+
PyTuple_SET_ITEM(tuple, 1, Py_BuildValue("s", ext));
1567+
PyTuple_SET_ITEM(tuple, 2, Py_BuildValue("s",
1568+
pdf_to_name(gctx, subtype)));
1569+
PyTuple_SET_ITEM(tuple, 3, bytes);
15691570
}
15701571
else
15711572
{
@@ -1776,11 +1777,11 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
17761777
// Return the /SigFlags value
17771778
//---------------------------------------------------------------------
17781779
CLOSECHECK0(getSigFlags)
1779-
int getSigFlags()
1780+
PyObject *getSigFlags()
17801781
{
17811782
pdf_document *pdf = pdf_specifics(gctx, $self);
1782-
if (!pdf) return -1; // not a PDF
1783-
int sigflag;
1783+
if (!pdf) return Py_BuildValue("i", -1); // not a PDF
1784+
size_t sigflag = 0;
17841785
fz_try(gctx)
17851786
{
17861787
pdf_obj *sigflags = pdf_dict_getl(gctx,
@@ -1789,11 +1790,13 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
17891790
PDF_NAME(AcroForm),
17901791
PDF_NAME(SigFlags),
17911792
NULL);
1792-
if (sigflags) sigflag = pdf_to_int(gctx, sigflags);
1793-
else sigflag = -1;
1793+
if (sigflags)
1794+
{
1795+
sigflag = (size_t) pdf_to_int(gctx, sigflags);
1796+
}
17941797
}
1795-
fz_catch(gctx) return -1; // any problem yields -1
1796-
return sigflag;
1798+
fz_catch(gctx) return Py_BuildValue("i", -1); // any problem
1799+
return Py_BuildValue("I", sigflag);
17971800
}
17981801
17991802
//---------------------------------------------------------------------
@@ -1804,8 +1807,8 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
18041807
PyObject *isFormPDF()
18051808
{
18061809
pdf_document *pdf = pdf_specifics(gctx, $self);
1807-
if (!pdf) Py_RETURN_FALSE; // not a PDF
1808-
int have_form = 0; // preset indicator
1810+
if (!pdf) Py_RETURN_FALSE; // not a PDF
1811+
int count = 0; // init count
18091812
fz_try(gctx)
18101813
{
18111814
pdf_obj *fields = pdf_dict_getl(gctx,
@@ -1814,10 +1817,20 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
18141817
PDF_NAME(AcroForm),
18151818
PDF_NAME(Fields),
18161819
NULL);
1817-
if (fields && pdf_array_len(gctx, fields) > 0) have_form = 1;
1820+
if (pdf_is_array(gctx, fields))
1821+
{
1822+
count = pdf_array_len(gctx, fields);
1823+
};
18181824
}
18191825
fz_catch(gctx) Py_RETURN_FALSE; // any problem yields false
1820-
return JM_BOOL(have_form);
1826+
if (count)
1827+
{
1828+
return Py_BuildValue("i", count);
1829+
}
1830+
else
1831+
{
1832+
Py_RETURN_FALSE;
1833+
}
18211834
}
18221835
18231836
//---------------------------------------------------------------------
@@ -2492,10 +2505,38 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
24922505
def __getitem__(self, i=0):
24932506
if type(i) is not int:
24942507
raise ValueError("bad page number(s)")
2495-
if i >= len(self):
2508+
if i >= self.pageCount:
24962509
raise IndexError("bad page number(s)")
24972510
return self.loadPage(i)
24982511
2512+
def pages(self, start=None, stop=None, step=None):
2513+
"""Return a generator iterator over a page range.
2514+
2515+
Arguments have the same meaning as for the range() built-in.
2516+
"""
2517+
# set the start value
2518+
start = start or 0
2519+
while start < 0:
2520+
start += self.pageCount
2521+
if start not in range(self.pageCount):
2522+
raise ValueError("bad start page number")
2523+
2524+
# set the stop value
2525+
stop = stop if stop is not None and stop <= self.pageCount else self.pageCount
2526+
2527+
# set the step value
2528+
if step == 0:
2529+
raise ValueError("arg 3 must not be zero")
2530+
if step is None:
2531+
if start > stop:
2532+
step = -1
2533+
else:
2534+
step = 1
2535+
2536+
for pno in range(start, stop, step):
2537+
yield (self.loadPage(pno))
2538+
2539+
24992540
def __len__(self):
25002541
return self.pageCount
25012542
@@ -3924,6 +3965,33 @@ def insertFont(self, fontname="helv", fontfile=None, fontbuffer=None,
39243965
TOOLS._insert_contents(self, b"q\n", False)
39253966
TOOLS._insert_contents(self, b"\nQ", True)
39263967
3968+
3969+
def links(self, kinds=None):
3970+
""" Generator over the links of a page."""
3971+
all_links = self.getLinks()
3972+
for link in all_links:
3973+
if kinds is None or link["kind"] in kinds:
3974+
yield (link)
3975+
3976+
3977+
def annots(self, types=None):
3978+
""" Generator over the annotations of a page."""
3979+
annot = self.firstAnnot
3980+
while annot:
3981+
if types is None or annot.type[0] in types:
3982+
yield (annot)
3983+
annot = annot.next
3984+
3985+
3986+
def widgets(self, types=None):
3987+
""" Generator over the widgets of a page."""
3988+
widget = self.firstWidget
3989+
while widget:
3990+
if types is None or widget.field_type in types:
3991+
yield (widget)
3992+
widget = widget.next
3993+
3994+
39273995
def __str__(self):
39283996
CheckParent(self)
39293997
x = self.parent.name

fitz/helper-pdfinfo.i

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
%{
2+
/* ************ CURRENTLY NOT USED ***************
23
//----------------------------------------------------------------------------
34
// convert (char *) to ASCII-only (char*) (which must be freed!)
45
//----------------------------------------------------------------------------
@@ -32,6 +33,7 @@ PyObject *JM_UnicodeFromASCII(const char *in)
3233
JM_Free(c);
3334
return p;
3435
}
36+
*/
3537

3638
//-----------------------------------------------------------------------------
3739
// Store info of a font in Python list
@@ -73,10 +75,10 @@ void JM_gather_fonts(fz_context *ctx, pdf_document *pdf, pdf_obj *dict,
7375
PyObject *entry = PyList_New(6);
7476
PyList_SET_ITEM(entry, 0, Py_BuildValue("i", xref));
7577
PyList_SET_ITEM(entry, 1, Py_BuildValue("s", ext));
76-
PyList_SET_ITEM(entry, 2, JM_UnicodeFromASCII(pdf_to_name(ctx, subtype)));
77-
PyList_SET_ITEM(entry, 3, JM_UnicodeFromASCII(pdf_to_name(ctx, name)));
78-
PyList_SET_ITEM(entry, 4, JM_UnicodeFromASCII(pdf_to_name(ctx, refname)));
79-
PyList_SET_ITEM(entry, 5, JM_UnicodeFromASCII(pdf_to_name(ctx, encoding)));
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)));
8082
PyList_Append(fontlist, entry);
8183
Py_DECREF(entry);
8284
}
@@ -147,10 +149,10 @@ void JM_gather_images(fz_context *ctx, pdf_document *doc, pdf_obj *dict,
147149
PyList_SET_ITEM(entry, 2, Py_BuildValue("i", pdf_to_int(ctx, width)));
148150
PyList_SET_ITEM(entry, 3, Py_BuildValue("i", pdf_to_int(ctx, height)));
149151
PyList_SET_ITEM(entry, 4, Py_BuildValue("i", pdf_to_int(ctx, bpc)));
150-
PyList_SET_ITEM(entry, 5, JM_UnicodeFromASCII(pdf_to_name(ctx, cs)));
151-
PyList_SET_ITEM(entry, 6, JM_UnicodeFromASCII(pdf_to_name(ctx, altcs)));
152-
PyList_SET_ITEM(entry, 7, JM_UnicodeFromASCII(pdf_to_name(ctx, refname)));
153-
PyList_SET_ITEM(entry, 8, JM_UnicodeFromASCII(pdf_to_name(ctx, filter)));
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)));
154156
PyList_Append(imagelist, entry);
155157
Py_DECREF(entry);
156158
}
@@ -187,7 +189,7 @@ void JM_gather_forms(fz_context *ctx, pdf_document *doc, pdf_obj *dict,
187189

188190
PyObject *entry = PyList_New(2);
189191
PyList_SET_ITEM(entry, 0, Py_BuildValue("i", xref));
190-
PyList_SET_ITEM(entry, 1, JM_UnicodeFromASCII(pdf_to_name(ctx, refname)));
192+
PyList_SET_ITEM(entry, 1, JM_EscapeStrFromStr(ctx, pdf_to_name(ctx, refname)));
191193
PyList_Append(imagelist, entry);
192194
Py_DECREF(entry);
193195
}

fitz/helper-stext.i

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
%{
2-
PyObject *JM_UnicodeFromASCII(const char *in);
3-
4-
52
PyObject *JM_StrFromBuffer(fz_context *ctx, fz_buffer *buff)
63
{
74
if (!buff) return PyUnicode_FromString("");
@@ -31,6 +28,15 @@ PyObject *JM_EscapeStrFromBuffer(fz_context *ctx, fz_buffer *buff)
3128
return val;
3229
}
3330

31+
PyObject *JM_EscapeStrFromStr(fz_context *ctx, const char *c)
32+
{
33+
if (!c) return PyUnicode_FromString("");
34+
fz_buffer *buff = fz_new_buffer_from_shared_data(ctx, c, strlen(c));
35+
PyObject *val = JM_EscapeStrFromBuffer(ctx, buff);
36+
// fz_drop_buffer(ctx, buff);
37+
return val;
38+
}
39+
3440

3541
// Replace MuPDF error rune with character 0xB7
3642
PyObject *JM_repl_char()
@@ -225,7 +231,7 @@ static PyObject *JM_make_spanlist(fz_context *ctx, fz_stext_line *line, int raw,
225231
PyDict_SetItem(span, dictkey_flags, val);
226232
Py_DECREF(val);
227233

228-
val = Py_BuildValue("s", style.font);
234+
val = JM_EscapeStrFromStr(ctx, style.font);
229235
PyDict_SetItem(span, dictkey_font, val);
230236
Py_DECREF(val);
231237

fitz/version.i

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%pythoncode %{
22
VersionFitz = "1.16.0"
3-
VersionBind = "1.16.3"
4-
VersionDate = "2019-10-01 09:01:06"
5-
version = (VersionBind, VersionFitz, "20191001090106")
3+
VersionBind = "1.16.4"
4+
VersionDate = "2019-10-10 10:00:00"
5+
version = (VersionBind, VersionFitz, "20191010100000")
66
%}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def run(self):
8181

8282
setup(
8383
name="PyMuPDF",
84-
version="1.16.3",
84+
version="1.16.4",
8585
description="Python bindings for the PDF rendering library MuPDF",
8686
long_description=long_desc,
8787
classifiers=classifier,

0 commit comments

Comments
 (0)