Skip to content

Commit ffbbdfb

Browse files
authored
Merge pull request #245 from JorjMcKie/master
Upgrade to v1.14.5
2 parents 2b170eb + a7e917d commit ffbbdfb

File tree

13 files changed

+269
-240
lines changed

13 files changed

+269
-240
lines changed

README.md

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

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

5-
Release date: December 18, 2018
5+
Release date: January 5, 2018
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.14.4 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.5 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

demo/piechart1.pdf

1.34 KB
Binary file not shown.

demo/piechart2.pdf

1.36 KB
Binary file not shown.

demo/sierpinski.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def punch(pm, x00, y00, x03, y03):
4949
d = 3 ** 6 # 729
5050
# create a quadratic pixmap with origin (0,0), where width = height = d should
5151
# be a power of 3
52-
t0 = time.clock()
52+
t0 = time.perf_counter()
5353
ir = fitz.IRect(0, 0, d, d)
5454
pm = fitz.Pixmap(fitz.csGRAY, ir, 0)
5555
# fill image area with "black" and then optionally tint and gamma it
@@ -58,8 +58,8 @@ def punch(pm, x00, y00, x03, y03):
5858
# pm.gammaWith(0.5) # lighten it up
5959
# now punch holes into it, down to 1 pixel granularity
6060
punch(pm, 0, 0, d, d)
61-
t1 = time.clock()
61+
t1 = time.perf_counter()
6262
pm.writePNG(png_name)
63-
t2 = time.clock()
63+
t2 = time.perf_counter()
6464
print("%f sec to create fitz img" % (t1 - t0))
6565
print("%f sec to save fitz img" % (t2 - t1))

fitz/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import absolute_import
22
from fitz.fitz import *
3-
from fitz import _fitz
3+
try:
4+
from fitz import _fitz
5+
except:
6+
pass
47

58
# define the supported colorspaces for convenience
69
fitz.csRGB = fitz.Colorspace(fitz.CS_RGB)
@@ -45,6 +48,7 @@
4548
fitz.Page.drawOval = fitz.utils.drawOval
4649
fitz.Page.drawPolyline = fitz.utils.drawPolyline
4750
fitz.Page.drawRect = fitz.utils.drawRect
51+
fitz.Page.drawQuad = fitz.utils.drawQuad
4852
fitz.Page.drawSector = fitz.utils.drawSector
4953
fitz.Page.drawSquiggle = fitz.utils.drawSquiggle
5054
fitz.Page.drawZigzag = fitz.utils.drawZigzag
@@ -61,11 +65,6 @@
6165
fitz.Page.updateLink = fitz.utils.updateLink
6266
fitz.Page.newShape = lambda x: fitz.utils.Shape(x)
6367

64-
#------------------------------------------------------------------------------
65-
# Pixmap
66-
#------------------------------------------------------------------------------
67-
fitz.Pixmap.writeImage = fitz.utils.writeImage
68-
6968
#------------------------------------------------------------------------------
7069
# Rect
7170
#------------------------------------------------------------------------------

fitz/fitz.i

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3867,10 +3867,10 @@ struct fz_pixmap_s
38673867
}
38683868
38693869
//----------------------------------------------------------------------
3870-
// getPNGData
3870+
// Pixmap._getImageData
38713871
//----------------------------------------------------------------------
3872-
FITZEXCEPTION(getPNGData, !result)
3873-
PyObject *getPNGData(int savealpha=-1)
3872+
FITZEXCEPTION(_getImageData, !result)
3873+
PyObject *_getImageData(int format, int savealpha=-1)
38743874
{
38753875
struct fz_buffer_s *res = NULL;
38763876
fz_output *out = NULL;
@@ -3879,7 +3879,27 @@ struct fz_pixmap_s
38793879
fz_try(gctx) {
38803880
res = fz_new_buffer(gctx, 1024);
38813881
out = fz_new_output_with_buffer(gctx, res);
3882-
fz_write_pixmap_as_png(gctx, out, $self);
3882+
switch(format)
3883+
{
3884+
case(1):
3885+
fz_write_pixmap_as_png(gctx, out, $self);
3886+
break;
3887+
case(2):
3888+
fz_write_pixmap_as_pnm(gctx, out, $self);
3889+
break;
3890+
case(3):
3891+
fz_write_pixmap_as_pam(gctx, out, $self);
3892+
break;
3893+
case(4):
3894+
fz_write_pixmap_as_tga(gctx, out, $self);
3895+
break;
3896+
case(5):
3897+
fz_write_pixmap_as_psd(gctx, out, $self);
3898+
break;
3899+
default:
3900+
fz_write_pixmap_as_png(gctx, out, $self);
3901+
break;
3902+
}
38833903
r = JM_BinFromBuffer(gctx, res);
38843904
}
38853905
fz_always(gctx)
@@ -3891,6 +3911,19 @@ struct fz_pixmap_s
38913911
return r;
38923912
}
38933913
3914+
%pythoncode %{
3915+
def getImageData(self, output="png"):
3916+
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
3917+
"pam": 3, "tga": 4, "psd": 5}
3918+
idx = valid_formats.get(output.lower(), 1)
3919+
return self._getImageData(idx)
3920+
3921+
def getPNGdata(self):
3922+
return self._getImageData(1)
3923+
def getPNGData(self, savealpha=-1):
3924+
return self._getImageData(1)
3925+
%}
3926+
38943927
//----------------------------------------------------------------------
38953928
// _writeIMG
38963929
//----------------------------------------------------------------------
@@ -3913,14 +3946,26 @@ struct fz_pixmap_s
39133946
case(4):
39143947
fz_save_pixmap_as_tga(gctx, $self, filename);
39153948
break;
3949+
case(5):
3950+
fz_save_pixmap_as_psd(gctx, $self, filename);
3951+
break;
3952+
default:
3953+
fz_save_pixmap_as_png(gctx, $self, filename);
3954+
break;
39163955
}
39173956
}
39183957
fz_catch(gctx) return NULL;
39193958
return NONE;
39203959
}
39213960
%pythoncode %{
3922-
def writePNG(self, filename, savealpha = -1):
3923-
return self._writeIMG(filename, 1, savealpha)
3961+
def writeImage(self, filename, output="png"):
3962+
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
3963+
"pam": 3, "tga": 4, "psd": 5}
3964+
idx = valid_formats.get(output.lower(), 1)
3965+
return self._writeIMG(filename, idx)
3966+
3967+
def writePNG(self, filename, savealpha = -1):
3968+
return self._writeIMG(filename, 1, savealpha)
39243969
%}
39253970
//----------------------------------------------------------------------
39263971
// invertIRect
@@ -3952,6 +3997,15 @@ struct fz_pixmap_s
39523997
width = w
39533998
height = h
39543999
4000+
def pixel(self, x, y):
4001+
"""Return a tuple representing one pixel. Item values are integers in range
4002+
0 to 255. Last item is the alpha value if Pixmap.alpha is true.
4003+
"""
4004+
if x not in range(self.width) or y not in range(self.height):
4005+
raise IndexError("coordinates outside image")
4006+
i = self.stride * y + self.n * x
4007+
return tuple(self.samples[i: i + self.n])
4008+
39554009
def __len__(self):
39564010
return self.size
39574011

fitz/fitz.py

Lines changed: 43 additions & 43 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.4"
109-
VersionDate = "2018-12-18 08:56:44"
110-
version = (VersionBind, VersionFitz, "20181218085644")
108+
VersionBind = "1.14.5"
109+
VersionDate = "2019-01-04 10:29:25"
110+
version = (VersionBind, VersionFitz, "20190104102925")
111111

112112

113113
class Matrix():
@@ -164,12 +164,7 @@ def invert(self, src=None):
164164
dst = TOOLS._invert_matrix(src)
165165
if dst[0] == 1:
166166
return 1
167-
self.a = dst[1][0]
168-
self.b = dst[1][1]
169-
self.c = dst[1][2]
170-
self.d = dst[1][3]
171-
self.e = dst[1][4]
172-
self.f = dst[1][5]
167+
self.a, self.b, self.c, self.d, self.e, self.f = dst[1]
173168
return 0
174169

175170
def preTranslate(self, tx, ty):
@@ -239,13 +234,7 @@ def preRotate(self, theta):
239234

240235
def concat(self, one, two):
241236
"""Multiply two matrices and replace current one."""
242-
dst = TOOLS._concat_matrix(one, two)
243-
self.a = dst[0]
244-
self.b = dst[1]
245-
self.c = dst[2]
246-
self.d = dst[3]
247-
self.e = dst[4]
248-
self.f = dst[5]
237+
self.a, self.b, self.c, self.d, self.e, self.f = TOOLS._concat_matrix(one, two)
249238
return self
250239

251240
def __getitem__(self, i):
@@ -386,7 +375,7 @@ def __init__(self, *args):
386375
raise ValueError("illegal Point constructor")
387376

388377
def transform(self, m):
389-
"""Replace point by its transformation with matrix m."""
378+
"""Replace point by its transformation with matrix-like m."""
390379
x = self.x
391380
self.x = x * m[0] + self.y * m[2] + m[4]
392381
self.y = x * m[1] + self.y * m[3] + m[5]
@@ -622,29 +611,22 @@ def round(self):
622611

623612
def includePoint(self, p):
624613
"""Extend rectangle to include point p."""
625-
r0 = TOOLS._include_point_in_rect(self, p);
626-
self.x0 = r0[0]
627-
self.y0 = r0[1]
628-
self.x1 = r0[2]
629-
self.y1 = r0[3]
614+
self.x0, self.y0, self.x1, self.y1 = TOOLS._include_point_in_rect(self, p)
630615
return self
631616

632617
def includeRect(self, r):
633618
"""Extend rectangle to include rectangle r."""
634-
r0 = TOOLS._union_rect(self, r)
635-
self.x0 = r0[0]
636-
self.y0 = r0[1]
637-
self.x1 = r0[2]
638-
self.y1 = r0[3]
619+
self.x0, self.y0, self.x1, self.y1 = TOOLS._union_rect(self, r)
639620
return self
640621

641622
def intersect(self, r):
642623
"""Restrict self to common area with rectangle r."""
643-
r0 = TOOLS._intersect_rect(self, r);
644-
self.x0 = r0[0]
645-
self.y0 = r0[1]
646-
self.x1 = r0[2]
647-
self.y1 = r0[3]
624+
self.x0, self.y0, self.x1, self.y1 = TOOLS._intersect_rect(self, r)
625+
return self
626+
627+
def transform(self, m):
628+
"""Replace rectangle with its transformation by matrix m."""
629+
self.x0, self.y0, self.x1, self.y1 = TOOLS._transform_rect(self, m)
648630
return self
649631

650632
def __getitem__(self, i):
@@ -703,15 +685,6 @@ def __sub__(self, p):
703685
raise ValueError("require rect-like object")
704686
return Rect(self.x0 - p[0], self.y0 - p[1], self.x1 - p[2], self.y1 - p[3])
705687

706-
def transform(self, m):
707-
"""Replace rectangle with its transformation by matrix m."""
708-
r0 = TOOLS._transform_rect(self, m)
709-
self.x0 = r0[0]
710-
self.y0 = r0[1]
711-
self.x1 = r0[2]
712-
self.y1 = r0[3]
713-
return self
714-
715688
def __mul__(self, m):
716689
if hasattr(m, "__float__"):
717690
return Rect(self.x0 * m, self.y0 * m, self.x1 * m, self.y1 * m)
@@ -3189,16 +3162,34 @@ def setAlpha(self, alphavalues=None):
31893162
return _fitz.Pixmap_setAlpha(self, alphavalues)
31903163

31913164

3165+
def _getImageData(self, format, savealpha=-1):
3166+
"""_getImageData(self, format, savealpha=-1) -> PyObject *"""
3167+
return _fitz.Pixmap__getImageData(self, format, savealpha)
3168+
3169+
3170+
def getImageData(self, output="png"):
3171+
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
3172+
"pam": 3, "tga": 4, "psd": 5}
3173+
idx = valid_formats.get(output.lower(), 1)
3174+
return self._getImageData(idx)
3175+
3176+
def getPNGdata(self):
3177+
return self._getImageData(1)
31923178
def getPNGData(self, savealpha=-1):
3193-
"""getPNGData(self, savealpha=-1) -> PyObject *"""
3194-
return _fitz.Pixmap_getPNGData(self, savealpha)
3179+
return self._getImageData(1)
31953180

31963181

31973182
def _writeIMG(self, filename, format, savealpha=-1):
31983183
"""_writeIMG(self, filename, format, savealpha=-1) -> PyObject *"""
31993184
return _fitz.Pixmap__writeIMG(self, filename, format, savealpha)
32003185

32013186

3187+
def writeImage(self, filename, output="png"):
3188+
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
3189+
"pam": 3, "tga": 4, "psd": 5}
3190+
idx = valid_formats.get(output.lower(), 1)
3191+
return self._writeIMG(filename, idx)
3192+
32023193
def writePNG(self, filename, savealpha = -1):
32033194
return self._writeIMG(filename, 1, savealpha)
32043195

@@ -3217,6 +3208,15 @@ def samples(self):
32173208
width = w
32183209
height = h
32193210

3211+
def pixel(self, x, y):
3212+
"""Return a tuple representing one pixel. Item values are integers in range
3213+
0 to 255. Last item is the alpha value if Pixmap.alpha is true.
3214+
"""
3215+
if x not in range(self.width) or y not in range(self.height):
3216+
raise IndexError("coordinates outside image")
3217+
i = self.stride * y + self.n * x
3218+
return tuple(self.samples[i: i + self.n])
3219+
32203220
def __len__(self):
32213221
return self.size
32223222

0 commit comments

Comments
 (0)