Skip to content

Commit 672a44c

Browse files
authored
Merge pull request #271 from JorjMcKie/master
upload v1.14.12
2 parents 5cae163 + b7c3dae commit 672a44c

File tree

14 files changed

+315
-312
lines changed

14 files changed

+315
-312
lines changed

PKG-INFO

Lines changed: 2 additions & 2 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.11
3+
Version: 1.14.12
44
Author: Ruikai Liu
55
Author-email: [email protected]
66
Maintainer: Jorj X. McKie
@@ -21,7 +21,7 @@ Description:
2121
Introduction
2222
============
2323

24-
This is **version 1.14.11 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
24+
This is **version 1.14.12 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.11
1+
# PyMuPDF 1.14.12
22

33
![logo](https://github.com/pymupdf/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.11 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.12 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

doc/PyMuPDF.pdf

9.54 KB
Binary file not shown.

doc/html.zip

-10.9 KB
Binary file not shown.

fitz/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
fitz.Document.setToC = fitz.utils.setToC
3636
fitz.Document.searchPageFor = fitz.utils.searchPageFor
3737
fitz.Document.newPage = fitz.utils.newPage
38+
fitz.Document.insertPage = fitz.utils.insertPage
3839
fitz.Document.getCharWidths = fitz.utils.getCharWidths
3940

4041
# ------------------------------------------------------------------------------

fitz/fitz.i

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,29 +1059,10 @@ if links:
10591059
//---------------------------------------------------------------------
10601060
// Create and insert a new page (PDF)
10611061
//---------------------------------------------------------------------
1062-
FITZEXCEPTION(insertPage, result<0)
1063-
%feature("autodoc","Insert a new page in front of 'pno'. Use arguments 'width', 'height' to specify a non-default page size, and optionally text insertion arguments.") insertPage;
1064-
%pythonprepend insertPage %{
1065-
if self.isClosed or self.isEncrypted:
1066-
raise ValueError("operation illegal for closed / encrypted doc")
1067-
if bool(text):
1068-
CheckColor(color)
1069-
if fontname and fontname[0] == "/":
1070-
raise ValueError("invalid font reference")
1071-
%}
1072-
%pythonappend insertPage %{
1073-
if val < 0: return val
1074-
self._reset_page_refs()
1075-
if not bool(text): return val
1076-
page = self.loadPage(pno)
1077-
val = page.insertText(Point(50, 72), text, fontsize = fontsize,
1078-
fontname = fontname, fontfile = fontfile,
1079-
color = color, set_simple = set_simple)
1080-
%}
1081-
int insertPage(int pno = -1, PyObject *text = NULL, float fontsize = 11,
1082-
float width = 595, float height = 842,
1083-
char *fontname = NULL, char *fontfile = NULL,
1084-
int set_simple = 0, PyObject *color = NULL)
1062+
FITZEXCEPTION(_newPage, !result)
1063+
CLOSECHECK(_newPage)
1064+
%pythonappend _newPage %{self._reset_page_refs()%}
1065+
PyObject *_newPage(int pno=-1, float width=595, float height=842)
10851066
{
10861067
pdf_document *pdf = pdf_specifics(gctx, $self);
10871068
fz_rect mediabox = { 0, 0, 595, 842 }; // ISO-A4 portrait values
@@ -1095,25 +1076,22 @@ if links:
10951076
if (pno < -1) THROWMSG("invalid page number(s)");
10961077
// create /Resources and /Contents objects
10971078
resources = pdf_add_object_drop(gctx, pdf, pdf_new_dict(gctx, pdf, 1));
1098-
contents = fz_new_buffer(gctx, 10);
1099-
fz_append_string(gctx, contents, "");
1100-
fz_terminate_buffer(gctx, contents);
11011079
page_obj = pdf_add_page(gctx, pdf, mediabox, 0, resources, contents);
1102-
pdf_insert_page(gctx, pdf, pno , page_obj);
1080+
pdf_insert_page(gctx, pdf, pno, page_obj);
11031081
}
11041082
fz_always(gctx)
11051083
{
11061084
fz_drop_buffer(gctx, contents);
11071085
pdf_drop_obj(gctx, page_obj);
11081086
}
1109-
fz_catch(gctx) return -1;
1087+
fz_catch(gctx) return NULL;
11101088
pdf->dirty = 1;
1111-
return 0;
1089+
return NONE;
11121090
}
11131091
11141092
//---------------------------------------------------------------------
11151093
// Create sub-document to keep only selected pages.
1116-
// Parameter is a Python list of the wanted page numbers.
1094+
// Parameter is a Python sequence of the wanted page numbers.
11171095
//---------------------------------------------------------------------
11181096
FITZEXCEPTION(select, !result)
11191097
%feature("autodoc","Build sub-pdf with page numbers in 'list'.") select;

fitz/fitz.py

Lines changed: 54 additions & 42 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.11"
109-
VersionDate = "2019-03-18 08:26:46"
110-
version = (VersionBind, VersionFitz, "20190318082646")
108+
VersionBind = "1.14.12"
109+
VersionDate = "2019-03-21 06:59:25"
110+
version = (VersionBind, VersionFitz, "20190321065925")
111111

112112

113113
class Matrix():
@@ -129,8 +129,8 @@ def __init__(self, *args):
129129
if len(args) == 1: # either an angle or a sequ
130130
if hasattr(args[0], "__float__"):
131131
theta = math.radians(args[0])
132-
c = round(math.cos(theta), 8)
133-
s = round(math.sin(theta), 8)
132+
c = round(math.cos(theta), 12)
133+
s = round(math.sin(theta), 12)
134134
self.a = self.d = c
135135
self.b = s
136136
self.c = -s
@@ -222,8 +222,8 @@ def preRotate(self, theta):
222222

223223
else:
224224
rad = math.radians(theta)
225-
s = round(math.sin(rad), 8)
226-
c = round(math.cos(rad), 8)
225+
s = round(math.sin(rad), 12)
226+
c = round(math.cos(rad), 12)
227227
a = self.a
228228
b = self.b
229229
self.a = c * a + s * self.c
@@ -1460,15 +1460,15 @@ def getPDFnow():
14601460
pass
14611461
return tstamp
14621462

1463-
#-------------------------------------------------------------------------------
1464-
# Return a PDF string depending on its coding.
1465-
# If only ascii then "(original)" is returned,
1466-
# else if only 8 bit chars then "(original)" with interspersed octal strings
1467-
# \nnn is returned,
1468-
# else a string "<FEFF[hexstring]>" is returned, where [hexstring] is the
1469-
# UTF-16BE encoding of the original.
1470-
#-------------------------------------------------------------------------------
14711463
def getPDFstr(s):
1464+
""" Return a PDF string depending on its coding.
1465+
1466+
Notes:
1467+
If only ascii then "(original)" is returned, else if only 8 bit chars
1468+
then "(original)" with interspersed octal strings \nnn is returned,
1469+
else a string "<FEFF[hexstring]>" is returned, where [hexstring] is the
1470+
UTF-16BE encoding of the original.
1471+
"""
14721472
if not bool(s):
14731473
return "()"
14741474

@@ -1515,15 +1515,17 @@ def make_utf16be(s):
15151515
return "(" + r + ")"
15161516

15171517
def getTJstr(text, glyphs, simple, ordering):
1518-
"""Return a PDF string enclosed in [] brackets, suitable for the PDF TJ
1518+
""" Return a PDF string enclosed in [] brackets, suitable for the PDF TJ
15191519
operator.
1520-
The input string is converted to either 2 or 4 hex digits per character.
1521-
* simple:
1522-
- no glyphs: 2-chars, use char codes as the glyph
1523-
- glyphs: 2-chars, use glyphs instead of char codes (Symbol, ZapfDingbats)
1524-
* not simple:
1525-
- ordering < 0: 4-chars, use glyphs not char codes
1526-
- ordering >=0: a CJK font! 4 chars, use char codes as glyphs
1520+
1521+
Notes:
1522+
The input string is converted to either 2 or 4 hex digits per character.
1523+
Args:
1524+
simple: no glyphs: 2-chars, use char codes as the glyph
1525+
glyphs: 2-chars, use glyphs instead of char codes (Symbol,
1526+
ZapfDingbats)
1527+
not simple: ordering < 0: 4-chars, use glyphs not char codes
1528+
ordering >=0: a CJK font! 4 chars, use char codes as glyphs
15271529
"""
15281530
if text.startswith("[<") and text.endswith(">]"): # already done
15291531
return text
@@ -1625,10 +1627,34 @@ def CheckParent(o):
16251627

16261628
def CheckColor(c):
16271629
if c is not None:
1628-
if type(c) not in (list, tuple) or len(c) not in (1, 3, 4) or \
1629-
min(c) < 0 or max(c) > 1:
1630+
if (
1631+
type(c) not in (list, tuple)
1632+
or len(c) not in (1, 3, 4)
1633+
or min(c) < 0
1634+
or max(c) > 1
1635+
):
16301636
raise ValueError("need 1, 3 or 4 color components in range 0 to 1")
16311637

1638+
def ColorCode(c, f):
1639+
if c is None:
1640+
return ""
1641+
if hasattr(c, "__float__"):
1642+
c = (c,)
1643+
CheckColor(c)
1644+
if len(c) == 1:
1645+
s = "%g " % c[0]
1646+
return s + "G " if f == "c" else s + "g "
1647+
1648+
if len(c) == 3:
1649+
s = "%g %g %g " % tuple(c)
1650+
return s + "RG " if f == "c" else s + "rg "
1651+
1652+
s = "%g %g %g %g " % tuple(c)
1653+
return s + "K " if f == "c" else s + "k "
1654+
1655+
def JM_TUPLE(o):
1656+
return tuple(map(lambda x: round(x, 8), o))
1657+
16321658
def CheckMorph(o):
16331659
if not bool(o): return False
16341660
if not (type(o) in (list, tuple) and len(o) == 2):
@@ -2138,27 +2164,13 @@ def insertPDF(self, docsrc, from_page=-1, to_page=-1, start_at=-1, rotate=-1, li
21382164
return val
21392165

21402166

2141-
def insertPage(self, pno=-1, text=None, fontsize=11, width=595, height=842, fontname=None, fontfile=None, set_simple=0, color=None):
2142-
"""Insert a new page in front of 'pno'. Use arguments 'width', 'height' to specify a non-default page size, and optionally text insertion arguments."""
2143-
2167+
def _newPage(self, pno=-1, width=595, height=842):
2168+
"""_newPage(self, pno=-1, width=595, height=842) -> PyObject *"""
21442169
if self.isClosed or self.isEncrypted:
21452170
raise ValueError("operation illegal for closed / encrypted doc")
2146-
if bool(text):
2147-
CheckColor(color)
2148-
if fontname and fontname[0] == "/":
2149-
raise ValueError("invalid font reference")
21502171

2151-
2152-
val = _fitz.Document_insertPage(self, pno, text, fontsize, width, height, fontname, fontfile, set_simple, color)
2153-
2154-
if val < 0: return val
2172+
val = _fitz.Document__newPage(self, pno, width, height)
21552173
self._reset_page_refs()
2156-
if not bool(text): return val
2157-
page = self.loadPage(pno)
2158-
val = page.insertText(Point(50, 72), text, fontsize = fontsize,
2159-
fontname = fontname, fontfile = fontfile,
2160-
color = color, set_simple = set_simple)
2161-
21622174

21632175
return val
21642176

0 commit comments

Comments
 (0)