Skip to content

Commit fdf2ae2

Browse files
committed
first changes for v1.18.7
1 parent b0babae commit fdf2ae2

File tree

8 files changed

+81
-21
lines changed

8 files changed

+81
-21
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.18.6
3+
Version: 1.18.7
44
Author: Jorj McKie
55
Author-email: [email protected]
66
Maintainer: Jorj 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: January 7, 2021
12+
Release date: January 15, 2021
1313

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

23-
This is **version 1.18.6 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
23+
This is **version 1.18.7 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PyMuPDF 1.18.6
1+
# PyMuPDF 1.18.7
22

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

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

1616
# Introduction
1717

18-
This is **version 1.18.6 of PyMuPDF**, a Python binding with support for [MuPDF 1.18.*](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
18+
This is **version 1.18.7 of PyMuPDF**, a Python binding with support for [MuPDF 1.18.*](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
1919

2020
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.
2121

fitz/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
fitz.Document.tobytes = fitz.Document.write
5757
fitz.Document.set_page_labels = fitz.utils.set_page_labels
5858
fitz.Document.get_page_numbers = fitz.utils.get_page_numbers
59+
fitz.Document.has_links = fitz.utils.has_links
60+
fitz.Document.has_annots = fitz.utils.has_annots
5961

6062
# ------------------------------------------------------------------------------
6163
# Page

fitz/fitz.i

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,28 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
20522052
}
20532053
20542054
2055+
FITZEXCEPTION(page_annot_xrefs, !result)
2056+
CLOSECHECK0(page_annot_xrefs, """Get list annotations of page number.""")
2057+
PyObject *page_annot_xrefs(int pno)
2058+
{
2059+
fz_document *this_doc = (fz_document *) $self;
2060+
int pageCount = fz_count_pages(gctx, this_doc);
2061+
int n = pno;
2062+
while (n < 0) n += pageCount;
2063+
pdf_document *pdf = pdf_specifics(gctx, this_doc);
2064+
PyObject *annots = NULL;
2065+
fz_try(gctx) {
2066+
if (n >= pageCount) THROWMSG(gctx, "bad page number(s)");
2067+
ASSERT_PDF(pdf);
2068+
annots = JM_get_annot_xref_list(gctx, pdf_lookup_page_obj(gctx, pdf, n));
2069+
}
2070+
fz_catch(gctx) {
2071+
return NULL;
2072+
}
2073+
return annots;
2074+
}
2075+
2076+
20552077
FITZEXCEPTION(pageCropBox, !result)
20562078
CLOSECHECK0(pageCropBox, """Get CropBox of page number (without loading page).""")
20572079
%pythonappend pageCropBox %{val = Rect(val)%}
@@ -3801,8 +3823,7 @@ if basestate:
38013823
old_toc = self.getToC()
38023824
for i, item in enumerate(old_toc):
38033825
if item[2] == pno + 1:
3804-
xref = self.outline_xref(i)
3805-
self._remove_toc_item(xref)
3826+
self.del_toc_item(i)
38063827
38073828
self._remove_links_to(pno, pno)
38083829
self._deletePage(pno)
@@ -3831,8 +3852,7 @@ if basestate:
38313852
old_toc = self.getToC()
38323853
for i, item in enumerate(old_toc):
38333854
if f + 1 <= item[2] <= t + 1:
3834-
xref = self.outline_xref(i)
3835-
self._remove_toc_item(xref)
3855+
self.del_toc_item(i)
38363856
38373857
self._remove_links_to(f, t)
38383858
@@ -5078,7 +5098,7 @@ def get_oc_items(self) -> list:
50785098
{
50795099
pdf_page *page = pdf_page_from_fz_page(gctx, (fz_page *) $self);
50805100
if (!page) Py_RETURN_NONE;
5081-
return JM_get_annot_xref_list(gctx, page);
5101+
return JM_get_annot_xref_list(gctx, page->obj);
50825102
}
50835103

50845104

fitz/helper-annot.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,11 @@ PyObject *JM_get_annot_id_list(fz_context *ctx, pdf_page *page)
321321
//------------------------------------------------------------------------
322322
// return the xrefs and /NM ids of a page's annots, links and fields
323323
//------------------------------------------------------------------------
324-
PyObject *JM_get_annot_xref_list(fz_context *ctx, pdf_page *page)
324+
PyObject *JM_get_annot_xref_list(fz_context *ctx, pdf_obj *page_obj)
325325
{
326326
PyObject *names = PyList_New(0);
327327
pdf_obj *id, *annot_obj = NULL;
328-
pdf_obj *annots = pdf_dict_get(ctx, page->obj, PDF_NAME(Annots));
328+
pdf_obj *annots = pdf_dict_get(ctx, page_obj, PDF_NAME(Annots));
329329
if (!annots) return names;
330330
fz_try(ctx) {
331331
int i, n = pdf_array_len(ctx, annots);

fitz/utils.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def calc_matrix(sr, tr, keep=True, rotate=0):
170170
matrix = calc_matrix(src_rect, tar_rect, keep=keep_proportion, rotate=rotate)
171171

172172
# list of existing /Form /XObjects
173-
ilst = [i[1] for i in doc._getPageInfo(page.number, 3)]
173+
ilst = [i[1] for i in doc.get_page_xobjects(page.number)]
174+
ilst += [i[7] for i in doc.get_page_images(page.number)]
175+
ilst += [i[4] for i in doc.get_page_fonts(page.number)]
174176

175177
# create a name not in that list
176178
n = "fzFrm"
@@ -369,8 +371,10 @@ def calc_matrix(fw, fh, tr, rotate=0):
369371
matrix = calc_matrix(fw, fh, clip, rotate=rotate) # calculate matrix
370372

371373
# Create a unique image reference name.
372-
ilst = [i[7] for i in doc.getPageImageList(page.number)]
373-
n = "Im" # 'fitz image'
374+
ilst = [i[7] for i in doc.get_page_images(page.number)]
375+
ilst += [i[1] for i in doc.get_page_xobjects(page.number)]
376+
ilst += [i[4] for i in doc.get_page_fonts(page.number)]
377+
n = "fzImg" # 'fitz image'
374378
i = 0
375379
_imgname = n + "0" # first name candidate
376380
while _imgname in ilst:
@@ -1068,10 +1072,10 @@ def setToC(
10681072
# make a list of xref numbers, which we can use for our TOC entries
10691073
# --------------------------------------------------------------------------
10701074
old_xrefs = doc._delToC() # del old outlines, get their xref numbers
1071-
old_xrefs = [] # TODO do not reuse them currently
1075+
10721076
# prepare table of xrefs for new bookmarks
10731077
xref = [0] + old_xrefs
1074-
xref[0] = doc._getOLRootNumber() # entry zero is outline root xref#
1078+
xref[0] = doc._getOLRootNumber() # entry zero is outline root xref number
10751079
if toclen > len(old_xrefs): # too few old xrefs?
10761080
for i in range((toclen - len(old_xrefs))):
10771081
xref.append(doc.get_new_xref()) # acquire new ones
@@ -4466,3 +4470,37 @@ def create_nums(labels):
44664470

44674471

44684472
# End of Page Label Code -------------------------------------------------
4473+
4474+
4475+
def has_links(doc: Document) -> bool:
4476+
"""Check whether there links on any page."""
4477+
if doc.isClosed:
4478+
raise ValueError("closed document")
4479+
if not doc.isPDF:
4480+
raise ValueError("not a PDF")
4481+
s = set()
4482+
for i in range(doc.pageCount):
4483+
s = s.union([True for j in doc.page_annot_xrefs(i) if j[1] == PDF_ANNOT_LINK])
4484+
if s == {True}:
4485+
return True
4486+
return False
4487+
4488+
4489+
def has_annots(doc: Document) -> bool:
4490+
"""Check whether there annotations on any page."""
4491+
if doc.isClosed:
4492+
raise ValueError("closed document")
4493+
if not doc.isPDF:
4494+
raise ValueError("not a PDF")
4495+
s = set()
4496+
for i in range(doc.pageCount):
4497+
s = s.union(
4498+
[
4499+
True
4500+
for j in doc.page_annot_xrefs(i)
4501+
if j[1] not in (PDF_ANNOT_LINK, PDF_ANNOT_WIDGET)
4502+
]
4503+
)
4504+
if s == {True}:
4505+
return True
4506+
return False

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.18.0"
3-
VersionBind = "1.18.6"
4-
VersionDate = "2021-01-07 07:10:59"
5-
version = (VersionBind, VersionFitz, "20210107071059")
3+
VersionBind = "1.18.7"
4+
VersionDate = "2021-01-09 08:53:43"
5+
version = (VersionBind, VersionFitz, "20210109085343")
66
%}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def load_libraries():
131131

132132
setup(
133133
name="PyMuPDF",
134-
version="1.18.6",
134+
version="1.18.7",
135135
description="Python bindings for the PDF rendering library MuPDF",
136136
long_description=long_desc,
137137
classifiers=classifier,

0 commit comments

Comments
 (0)