Skip to content

Commit 4c22889

Browse files
committed
Bug fixing PDF string escapes (#153)
1 parent 7902e0c commit 4c22889

10 files changed

+556
-550
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ script:
4646
- cibuildwheel --output-dir wheelhouse
4747

4848
before_deploy:
49-
- git tag "v1.12.4"
49+
- git tag "v1.12.5"
5050
deploy:
5151
provider: releases
5252
api_key:

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PyMuPDF 1.12.4 [![Build Status](https://travis-ci.org/rk700/PyMuPDF.svg?branch=master)](https://travis-ci.org/rk700/PyMuPDF)
1+
# PyMuPDF 1.12.5 [![Build Status](https://travis-ci.org/rk700/PyMuPDF.svg?branch=master)](https://travis-ci.org/rk700/PyMuPDF)
22

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

@@ -10,7 +10,7 @@ Release date: January 15, 2018
1010

1111
# Introduction
1212

13-
This is **version 1.12.4 of PyMuPDF (formerly python-fitz)**, a Python binding which supports [MuPDF 1.12](http://mupdf.com/) - "a lightweight PDF and XPS viewer".
13+
This is **version 1.12.5 of PyMuPDF (formerly python-fitz)**, a Python binding which supports [MuPDF 1.12](http://mupdf.com/) - "a lightweight PDF and XPS viewer".
1414

1515
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.
1616

fitz/fitz.i

+54-63
Original file line numberDiff line numberDiff line change
@@ -1021,65 +1021,21 @@ if links:
10211021
return Py_BuildValue("(l, l)", objnum, objgen);
10221022
}
10231023
1024-
//---------------------------------------------------------------------
1025-
// Returns the list of images used on a page.
1026-
// Each image entry contains
1027-
// [xref, smask, width, height, bpc, colorspace, altcs, name]
1028-
//---------------------------------------------------------------------
1029-
FITZEXCEPTION(getPageImageList, !result)
1030-
CLOSECHECK(getPageImageList)
1031-
%feature("autodoc","Show the images used on a page.") getPageImageList;
1032-
%pythonappend getPageImageList %{
1033-
x = []
1034-
for v in val:
1035-
if v not in x:
1036-
x.append(v)
1037-
val = x%}
1038-
PyObject *getPageImageList(int pno)
1039-
{
1040-
pdf_document *pdf = pdf_specifics(gctx, $self);
1041-
int pageCount = fz_count_pages(gctx, $self);
1042-
pdf_obj *pageref, *rsrc;
1043-
PyObject *imagelist; // returned object
1044-
int n = pno; // pno < 0 is allowed
1045-
while (n < 0) n += pageCount;
1046-
fz_try(gctx)
1047-
{
1048-
if (n >= pageCount) THROWMSG("invalid page number(s)");
1049-
assert_PDF(pdf);
1050-
pageref = pdf_lookup_page_obj(gctx, pdf, n);
1051-
rsrc = pdf_dict_get(gctx, pageref, PDF_NAME_Resources);
1052-
if (!pageref || !rsrc) THROWMSG("cannot retrieve page info");
1053-
imagelist = PyList_New(0);
1054-
JM_imagelist(gctx, pdf, rsrc, imagelist);
1055-
}
1056-
fz_catch(gctx)
1057-
{
1058-
Py_DECREF(imagelist);
1059-
return NULL;
1060-
}
1061-
return imagelist;
1062-
}
1063-
1064-
//---------------------------------------------------------------------
1065-
// Returns the list of fonts used on a page.
1066-
// Each font entry contains [xref, extension, type, basename, name]
1067-
//---------------------------------------------------------------------
1068-
FITZEXCEPTION(getPageFontList, !result)
1069-
CLOSECHECK(getPageFontList)
1070-
%feature("autodoc","Show the fonts used on a page.") getPageFontList;
1071-
%pythonappend getPageFontList %{
1024+
FITZEXCEPTION(_getPageInfo, !result)
1025+
CLOSECHECK(_getPageInfo)
1026+
%feature("autodoc","Show fonts or images used on a page.") _getPageInfo;
1027+
%pythonappend _getPageInfo %{
10721028
x = []
10731029
for v in val:
10741030
if v not in x:
10751031
x.append(v)
10761032
val = x%}
1077-
PyObject *getPageFontList(int pno)
1033+
PyObject *_getPageInfo(int pno, int what)
10781034
{
10791035
pdf_document *pdf = pdf_specifics(gctx, $self);
10801036
int pageCount = fz_count_pages(gctx, $self);
10811037
pdf_obj *pageref, *rsrc;
1082-
PyObject *fontlist; // returned object
1038+
PyObject *liste; // returned object
10831039
int n = pno; // pno < 0 is allowed
10841040
while (n < 0) n += pageCount;
10851041
fz_try(gctx)
@@ -1089,15 +1045,15 @@ if links:
10891045
pageref = pdf_lookup_page_obj(gctx, pdf, n);
10901046
rsrc = pdf_dict_get(gctx, pageref, PDF_NAME_Resources);
10911047
if (!pageref || !rsrc) THROWMSG("cannot retrieve page info");
1092-
fontlist = PyList_New(0);
1093-
JM_fontlist(gctx, pdf, rsrc, fontlist);
1048+
liste = PyList_New(0);
1049+
JM_ScanResources(gctx, pdf, rsrc, liste, what);
10941050
}
10951051
fz_catch(gctx)
10961052
{
1097-
Py_DECREF(fontlist);
1053+
Py_DECREF(liste);
10981054
return NULL;
10991055
}
1100-
return fontlist;
1056+
return liste;
11011057
}
11021058
11031059
FITZEXCEPTION(extractFont, !result)
@@ -1461,6 +1417,16 @@ if links:
14611417
outline = property(lambda self: self._outline)
14621418
_getPageXref = _getPageObjNumber
14631419
1420+
def getPageFontList(self, pno):
1421+
"""Retrieve a list of fonts used on a page.
1422+
"""
1423+
return self._getPageInfo(pno, 1)
1424+
1425+
def getPageImageList(self, pno):
1426+
"""Retrieve a list of images used on a page.
1427+
"""
1428+
return self._getPageInfo(pno, 2)
1429+
14641430
def saveIncr(self):
14651431
""" Save PDF incrementally"""
14661432
return self.save(self.name, incremental = True)
@@ -2933,6 +2899,8 @@ struct fz_pixmap_s
29332899
fz_pixmap *pm = NULL;
29342900
fz_try(gctx)
29352901
{
2902+
if (!fz_pixmap_colorspace(gctx, spix))
2903+
THROWMSG("cannot copy pixmap with NULL colorspace");
29362904
pm = fz_convert_pixmap(gctx, spix, cs, NULL, NULL, NULL, alpha);
29372905
}
29382906
fz_catch(gctx) return NULL;
@@ -2942,7 +2910,7 @@ struct fz_pixmap_s
29422910
//---------------------------------------------------------------------
29432911
// create pixmap as scaled copy of another one
29442912
//---------------------------------------------------------------------
2945-
fz_pixmap_s(fz_pixmap *spix, float w, float h, struct fz_irect_s *clip = NULL)
2913+
fz_pixmap_s(struct fz_pixmap_s *spix, float w, float h, struct fz_irect_s *clip = NULL)
29462914
{
29472915
fz_pixmap *pm = NULL;
29482916
fz_try(gctx)
@@ -3101,33 +3069,48 @@ struct fz_pixmap_s
31013069
//---------------------------------------------------------------------
31023070
void shrink(int factor)
31033071
{
3104-
if (factor < 0) return;
3105-
fz_try(gctx)
3072+
if (factor < 1)
31063073
{
3107-
fz_subsample_pixmap(gctx, $self, factor);
3074+
PySys_WriteStdout("warning: ignoring shrink factor < 1\n");
3075+
return;
31083076
}
3109-
fz_catch(gctx) return;
3077+
fz_subsample_pixmap(gctx, $self, factor);
31103078
}
31113079

31123080
/***************************/
31133081
/* apply gamma correction */
31143082
/***************************/
31153083
void gammaWith(float gamma)
31163084
{
3085+
if (!fz_pixmap_colorspace(gctx, $self))
3086+
{
3087+
PySys_WriteStdout("warning: colorspace invalid for function\n");
3088+
return;
3089+
}
31173090
fz_gamma_pixmap(gctx, $self, gamma);
31183091
}
31193092

31203093
/***************************/
31213094
/* tint pixmap with color */
31223095
/***************************/
31233096
%pythonprepend tintWith%{
3124-
if self.colorspace.n > 3:
3125-
raise TypeError("CMYK colorspace cannot be tinted")%}
3097+
if not self.colorspace or self.colorspace.n > 3:
3098+
print("warning: colorspace invalid for function")
3099+
return%}
31263100
void tintWith(int red, int green, int blue)
31273101
{
31283102
fz_tint_pixmap(gctx, $self, red, green, blue);
31293103
}
31303104

3105+
//----------------------------------------------------------------------
3106+
// Pixmap.setResolution
3107+
//----------------------------------------------------------------------
3108+
void setResolution(int xres, int yres)
3109+
{
3110+
$self->xres = xres;
3111+
$self->yres = yres;
3112+
}
3113+
31313114
//----------------------------------------------------------------------
31323115
// clear total pixmap with 0x00 */
31333116
//----------------------------------------------------------------------
@@ -3155,9 +3138,17 @@ struct fz_pixmap_s
31553138
//----------------------------------------------------------------------
31563139
// copy pixmaps
31573140
//----------------------------------------------------------------------
3158-
void copyPixmap(struct fz_pixmap_s *src, const struct fz_irect_s *bbox)
3141+
FITZEXCEPTION(copyPixmap, !result)
3142+
PyObject *copyPixmap(struct fz_pixmap_s *src, const struct fz_irect_s *bbox)
31593143
{
3160-
fz_copy_pixmap_rect(gctx, $self, src, bbox, NULL);
3144+
fz_try(gctx)
3145+
{
3146+
if (!fz_pixmap_colorspace(gctx, src))
3147+
THROWMSG("cannot copy pixmap with NULL colorspace");
3148+
fz_copy_pixmap_rect(gctx, $self, src, bbox, NULL);
3149+
}
3150+
fz_catch(gctx) return NULL;
3151+
return NONE;
31613152
}
31623153

31633154
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)