Skip to content

Commit 96ab4b8

Browse files
committed
Publish v1.13.20
1 parent ae92f4c commit 96ab4b8

File tree

8 files changed

+289
-56
lines changed

8 files changed

+289
-56
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PyMuPDF 1.13.19
1+
# PyMuPDF 1.13.20
22

33
![logo](https://github.com/rk700/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.13.19 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.13.0](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
17+
This is **version 1.13.20 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.13.0](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

16.8 KB
Binary file not shown.

doc/html.zip

12.5 KB
Binary file not shown.

fitz/fitz.i

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@
9191
// memory allocation macros
9292
#define JM_MEMORY 1
9393
#if PY_VERSION_HEX < 0x03000000
94+
#undef JM_MEMORY
9495
#define JM_MEMORY 0
9596
#endif
97+
9698
#if JM_MEMORY == 1
9799
#define JM_Alloc(type, len) PyMem_New(type, len)
98100
#define JM_Free(x) PyMem_Del(x)
@@ -119,8 +121,10 @@
119121
#define JM_BinFromChar(x) PyByteArray_FromStringAndSize(x, (Py_ssize_t) strlen(x))
120122
#define JM_BinFromCharSize(x, y) PyByteArray_FromStringAndSize(x, (Py_ssize_t) y)
121123
# endif
124+
122125
// define Python None object
123126
#define NONE Py_BuildValue("s", NULL)
127+
124128
#include <fitz.h>
125129
#include <pdf.h>
126130
#include <zlib.h>
@@ -235,22 +239,24 @@ struct fz_document_s
235239
236240
fz_document_s(const char *filename = NULL, PyObject *stream = NULL,
237241
const char *filetype = NULL, struct fz_rect_s *rect = NULL,
242+
float width = 0, float height = 0,
238243
float fontsize = 11)
239244
{
240245
gctx->error->errcode = 0; // reset any error code
241246
gctx->error->message[0] = 0; // reset any error message
242247
struct fz_document_s *doc = NULL;
243248
fz_stream *data = NULL;
244249
char *streamdata;
250+
float w = width, h = height;
245251
size_t streamlen = JM_CharFromBytesOrArray(stream, &streamdata);
246252
fz_try(gctx)
247253
{
248254
if (rect)
249255
{
250256
if (fz_is_empty_rect(rect) || fz_is_infinite_rect(rect))
251257
THROWMSG("rect must be finite and not empty");
252-
if (rect->x0 != 0.0f || rect->y0 != 0.0f)
253-
THROWMSG("rect must start at (0,0)");
258+
w = rect->x1 - rect->x0;
259+
h = rect->y1 - rect->y0;
254260
}
255261
if (streamlen > 0)
256262
{
@@ -282,8 +288,8 @@ struct fz_document_s
282288
}
283289
}
284290
fz_catch(gctx) return NULL;
285-
if (rect)
286-
fz_layout_document(gctx, doc, rect->x1, rect->y1, fontsize);
291+
if (w > 0 && h > 0)
292+
fz_layout_document(gctx, doc, w, h, fontsize);
287293
return doc;
288294
}
289295
@@ -677,21 +683,48 @@ struct fz_document_s
677683
678684
FITZEXCEPTION(layout, !result)
679685
CLOSECHECK(layout)
680-
PyObject *layout(struct fz_rect_s *rect, float fontsize = 11)
686+
%pythonappend layout %{
687+
self._reset_page_refs()
688+
self.initData()%}
689+
PyObject *layout(struct fz_rect_s *rect = NULL, float width = 0, float height = 0, float fontsize = 11)
681690
{
682691
if (!fz_is_document_reflowable(gctx, $self)) return NONE;
683692
fz_try(gctx)
684693
{
685-
if (fz_is_empty_rect(rect) || fz_is_infinite_rect(rect))
686-
THROWMSG("rect must be finite and not empty");
687-
if (rect->x0 != 0.0 || rect->y0 != 0)
688-
THROWMSG("rect must start at (0, 0)");
689-
fz_layout_document(gctx, $self, rect->x1, rect->y1, fontsize);
694+
float w = width, h = height;
695+
if (rect)
696+
{
697+
if (fz_is_empty_rect(rect) || fz_is_infinite_rect(rect))
698+
THROWMSG("rect must be finite and not empty");
699+
w = rect->x1 - rect->x0;
700+
h = rect->y1 - rect->y0;
701+
}
702+
if (w <= 0.0f || h <= 0.0f)
703+
THROWMSG("invalid page size");
704+
fz_layout_document(gctx, $self, w, h, fontsize);
690705
}
691706
fz_catch(gctx) return NULL;
692707
return NONE;
693708
}
694709
710+
CLOSECHECK(makeBookmark)
711+
PyObject *makeBookmark(int pno = 0)
712+
{
713+
if (!fz_is_document_reflowable(gctx, $self)) return NONE;
714+
int n = pno, cp = fz_count_pages(gctx, $self);
715+
while(n < 0) n += cp;
716+
long long mark = (long long) fz_make_bookmark(gctx, $self, n);
717+
return PyLong_FromLongLong(mark);
718+
}
719+
720+
CLOSECHECK(findBookmark)
721+
int findBookmark(long long bookmark)
722+
{
723+
if (!fz_is_document_reflowable(gctx, $self)) return -1;
724+
fz_bookmark m = (fz_bookmark) bookmark;
725+
return fz_lookup_bookmark(gctx, $self, m);
726+
}
727+
695728
CLOSECHECK0(isReflowable)
696729
%pythoncode%{@property%}
697730
PyObject *isReflowable()
@@ -2031,7 +2064,7 @@ struct fz_page_s {
20312064
pdf_page *page = pdf_page_from_fz_page(gctx, $self);
20322065
fz_annot *fzannot = NULL;
20332066
pdf_annot *annot = NULL;
2034-
char *data = NULL, *uf, *d;
2067+
char *data = NULL, *uf = ufilename, *d = desc;
20352068
if (!ufilename) uf = filename;
20362069
if (!desc) d = filename;
20372070
size_t len = 0;

fitz/fitz.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class _object:
102102

103103

104104
VersionFitz = "1.13.0"
105-
VersionBind = "1.13.19"
106-
VersionDate = "2018-08-31 12:11:48"
107-
version = (VersionBind, VersionFitz, "20180831121148")
105+
VersionBind = "1.13.20"
106+
VersionDate = "2018-09-09 09:54:14"
107+
version = (VersionBind, VersionFitz, "20180909095414")
108108

109109

110110
#------------------------------------------------------------------------------
@@ -1036,8 +1036,8 @@ class Document(_object):
10361036
__swig_destroy__ = _fitz.delete_Document
10371037
__del__ = lambda self: None
10381038

1039-
def __init__(self, filename=None, stream=None, filetype=None, rect=None, fontsize=11):
1040-
"""__init__(self, filename=None, stream=None, filetype=None, rect=None, fontsize=11) -> Document"""
1039+
def __init__(self, filename=None, stream=None, filetype=None, rect=None, width=0, height=0, fontsize=11):
1040+
"""__init__(self, filename=None, stream=None, filetype=None, rect=None, width=0, height=0, fontsize=11) -> Document"""
10411041

10421042
if not filename or type(filename) == str:
10431043
pass
@@ -1061,7 +1061,7 @@ def __init__(self, filename=None, stream=None, filetype=None, rect=None, fontsiz
10611061
self.Graftmaps = {}
10621062
self._page_refs = weakref.WeakValueDictionary()
10631063

1064-
this = _fitz.new_Document(filename, stream, filetype, rect, fontsize)
1064+
this = _fitz.new_Document(filename, stream, filetype, rect, width, height, fontsize)
10651065
try:
10661066
self.this.append(this)
10671067
except __builtin__.Exception:
@@ -1237,12 +1237,33 @@ def resolveLink(self, uri=None):
12371237
return _fitz.Document_resolveLink(self, uri)
12381238

12391239

1240-
def layout(self, rect, fontsize=11):
1241-
"""layout(self, rect, fontsize=11) -> PyObject *"""
1240+
def layout(self, rect=None, width=0, height=0, fontsize=11):
1241+
"""layout(self, rect=None, width=0, height=0, fontsize=11) -> PyObject *"""
12421242
if self.isClosed or self.isEncrypted:
12431243
raise ValueError("operation illegal for closed / encrypted doc")
12441244

1245-
return _fitz.Document_layout(self, rect, fontsize)
1245+
val = _fitz.Document_layout(self, rect, width, height, fontsize)
1246+
1247+
self._reset_page_refs()
1248+
self.initData()
1249+
1250+
return val
1251+
1252+
1253+
def makeBookmark(self, pno=0):
1254+
"""makeBookmark(self, pno=0) -> PyObject *"""
1255+
if self.isClosed or self.isEncrypted:
1256+
raise ValueError("operation illegal for closed / encrypted doc")
1257+
1258+
return _fitz.Document_makeBookmark(self, pno)
1259+
1260+
1261+
def findBookmark(self, bookmark):
1262+
"""findBookmark(self, bookmark) -> int"""
1263+
if self.isClosed or self.isEncrypted:
1264+
raise ValueError("operation illegal for closed / encrypted doc")
1265+
1266+
return _fitz.Document_findBookmark(self, bookmark)
12461267

12471268
@property
12481269

0 commit comments

Comments
 (0)