Skip to content

Commit 30d8615

Browse files
committed
test v1.18.1
1 parent e88eaa1 commit 30d8615

File tree

7 files changed

+206
-26
lines changed

7 files changed

+206
-26
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.18.0
3+
Version: 1.18.1
44
Author: Jorj McKie
55
Author-email: [email protected]
66
Maintainer: Jorj McKie
@@ -20,7 +20,7 @@ Description:
2020
Introduction
2121
============
2222

23-
This is **version 1.18.0 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
23+
This is **version 1.18.1 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

fitz/fitz.i

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ CheckParent(self)%}
9292
#include <fitz.h>
9393
#include <pdf.h>
9494
#include <time.h>
95+
// freetype includes >> --------------------------------------------------
96+
#include <ft2build.h>
97+
#include FT_FREETYPE_H
98+
#ifdef FT_FONT_FORMATS_H
99+
#include FT_FONT_FORMATS_H
100+
#else
101+
#include FT_XFREE86_H
102+
#endif
103+
#include FT_TRUETYPE_TABLES_H
104+
105+
#ifndef FT_SFNT_HEAD
106+
#define FT_SFNT_HEAD ft_sfnt_head
107+
#endif
108+
// << freetype includes --------------------------------------------------
109+
110+
95111
char *JM_Python_str_AsChar(PyObject *str);
96112

97113
// additional headers from MuPDF ----------------------------------------------
@@ -100,7 +116,7 @@ fz_pixmap *fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, fl
100116
int fz_pixmap_size(fz_context *ctx, fz_pixmap *src);
101117
void fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile, int factor);
102118
void fz_copy_pixmap_rect(fz_context *ctx, fz_pixmap *dest, fz_pixmap *src, fz_irect b, const fz_default_colorspaces *default_cs);
103-
void jm_valid_chars(fz_context *ctx, fz_font *font, void *ptr);
119+
104120
// end of additional MuPDF headers --------------------------------------------
105121

106122
PyObject *JM_mupdf_warnings_store;
@@ -859,7 +875,7 @@ struct Document
859875
fz_try(gctx) {
860876
int fp = from_page, tp = to_page, srcCount = fz_count_pages(gctx, fz_doc);
861877
if (pdf_specifics(gctx, fz_doc))
862-
THROWMSG("use select+write or insertPDF for PDF docs instead");
878+
THROWMSG("bad document type");
863879
if (fp < 0) fp = 0;
864880
if (fp > srcCount - 1) fp = srcCount - 1;
865881
if (tp < 0) tp = srcCount - 1;
@@ -872,18 +888,34 @@ struct Document
872888
return doc;
873889
}
874890
891+
FITZEXCEPTION(pageCount, !result)
875892
CLOSECHECK0(pageCount, """Number of pages.""")
876893
%pythoncode%{@property%}
877894
PyObject *pageCount()
878895
{
879-
return Py_BuildValue("i", fz_count_pages(gctx, (fz_document *) $self));
896+
int pc = 0;
897+
fz_try(gctx) {
898+
pc = fz_count_pages(gctx, (fz_document *) $self);
899+
}
900+
fz_catch(gctx) {
901+
return NULL;
902+
}
903+
return Py_BuildValue("i", pc);
880904
}
881905
906+
FITZEXCEPTION(chapterCount, !result)
882907
CLOSECHECK0(chapterCount, """Number of chapters.""")
883908
%pythoncode%{@property%}
884909
PyObject *chapterCount()
885910
{
886-
return Py_BuildValue("i", fz_count_chapters(gctx, (fz_document *) $self));
911+
int pc=0;
912+
fz_try(gctx) {
913+
pc = fz_count_chapters(gctx, (fz_document *) $self);
914+
}
915+
fz_catch(gctx) {
916+
return NULL;
917+
}
918+
return Py_BuildValue("i", pc);
887919
}
888920
889921
FITZEXCEPTION(lastLocation, !result)
@@ -3375,6 +3407,58 @@ struct Page {
33753407
return text;
33763408
}
33773409
3410+
3411+
//---------------------------------------------------------------------
3412+
// page set opacity
3413+
//---------------------------------------------------------------------
3414+
FITZEXCEPTION(_set_opacity, !result)
3415+
%pythonprepend _set_opacity %{
3416+
if min(CA, ca) >= 1:
3417+
return
3418+
tCA = int(round(max(CA , 0) * 100))
3419+
if tCA >= 100:
3420+
tCA = 99
3421+
tca = int(round(max(ca, 0) * 100))
3422+
if tca >= 100:
3423+
tca = 99
3424+
gstate = "fitzca%02i%02i" % (tCA, tca)
3425+
%}
3426+
PyObject *
3427+
_set_opacity(char *gstate=NULL, float CA=1, float ca=1)
3428+
{
3429+
if (!gstate) Py_RETURN_NONE;
3430+
pdf_page *page = pdf_page_from_fz_page(gctx, (fz_page *) $self);
3431+
fz_try(gctx) {
3432+
ASSERT_PDF(page);
3433+
pdf_obj *resources = pdf_dict_get(gctx, page->obj, PDF_NAME(Resources));
3434+
if (!resources) {
3435+
resources = pdf_dict_put_dict(gctx, page->obj, PDF_NAME(Resources), 2);
3436+
}
3437+
pdf_obj *extg = pdf_dict_get(gctx, resources, PDF_NAME(ExtGState));
3438+
if (!extg) {
3439+
extg = pdf_dict_put_dict(gctx, resources, PDF_NAME(ExtGState), 2);
3440+
}
3441+
int i, n = pdf_dict_len(gctx, extg);
3442+
for (i = 0; i < n; i++) {
3443+
pdf_obj *o1 = pdf_dict_get_key(gctx, extg, i);
3444+
char *name = (char *) pdf_to_name(gctx, o1);
3445+
if (strcmp(name, gstate) == 0) goto finished;
3446+
}
3447+
pdf_obj *opa = pdf_new_dict(gctx, page->doc, 3);
3448+
pdf_dict_put_real(gctx, opa, PDF_NAME(CA), (double) CA);
3449+
pdf_dict_put_real(gctx, opa, PDF_NAME(ca), (double) ca);
3450+
pdf_dict_puts_drop(gctx, extg, gstate, opa);
3451+
finished:;
3452+
}
3453+
fz_always(gctx) {
3454+
}
3455+
fz_catch(gctx) {
3456+
return NULL;
3457+
}
3458+
return Py_BuildValue("s", gstate);
3459+
3460+
}
3461+
33783462
//---------------------------------------------------------------------
33793463
// page addCaretAnnot
33803464
//---------------------------------------------------------------------
@@ -4314,8 +4398,8 @@ struct Page {
43144398
path["even_odd"] = True
43154399
elif x[0] == "matrix":
43164400
ctm = Matrix(x[1])
4317-
if ctm.a == ctm.d:
4318-
factor = ctm.a
4401+
if abs(ctm.a) == abs(ctm.d):
4402+
factor = abs(ctm.a)
43194403
elif x[0] == "w":
43204404
path["width"] = x[1] * factor
43214405
elif x[0] == "lineCap":
@@ -5560,7 +5644,7 @@ Pixmap(PDFdoc, xref) - from an image at xref in a PDF document.
55605644
fz_separations *seps = NULL;
55615645
fz_try(gctx) {
55625646
if (!INRANGE(alpha, 0, 1))
5563-
THROWMSG("illegal alpha value");
5647+
THROWMSG("bad alpha value");
55645648
fz_colorspace *cs = fz_pixmap_colorspace(gctx, src_pix);
55655649
if (!cs && !alpha)
55665650
THROWMSG("cannot drop alpha for 'NULL' colorspace");
@@ -6915,8 +6999,11 @@ struct Annot
69156999
pdf_obj *obj = NULL;
69167000
const char *text = NULL;
69177001
fz_try(gctx) {
6918-
if (pdf_dict_gets(gctx, annot->obj, "RO")) {
7002+
obj = pdf_dict_gets(gctx, annot->obj, "RO");
7003+
if (obj) {
69197004
JM_Warning("Ignoring redaction key '/RO'.");
7005+
int xref = pdf_to_num(gctx, obj);
7006+
DICT_SETITEM_DROP(values, dictkey_xref, Py_BuildValue("i", xref));
69207007
}
69217008
obj = pdf_dict_gets(gctx, annot->obj, "OverlayText");
69227009
if (obj) {
@@ -9150,14 +9237,14 @@ struct Font
91509237
cp = array("l", (0,) * gc)
91519238
arr = cp.buffer_info()
91529239
self._valid_unicodes(arr)
9153-
return array("l", sorted(set(cp)[1:]))
9240+
return array("l", sorted(set(cp))[1:])
91549241
%}
91559242
void _valid_unicodes(PyObject *arr)
91569243
{
91579244
fz_font *font = (fz_font *) $self;
91589245
PyObject *temp = PySequence_ITEM(arr, 0);
91599246
void *ptr = PyLong_AsVoidPtr(temp);
9160-
jm_valid_chars(gctx, font, ptr);
9247+
JM_valid_chars(gctx, font, ptr);
91619248
Py_DECREF(temp);
91629249
}
91639250

fitz/helper-geo-py.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Matrix(object):
3737
self.a, self.b, self.c, self.d, self.e, self.f = 1.0, \
3838
float(args[1]), float(args[0]), 1.0, 0.0, 0.0
3939
return None
40-
raise ValueError("illegal Matrix constructor")
40+
raise ValueError("bad Matrix constructor")
4141

4242
def invert(self, src=None):
4343
"""Calculate the inverted matrix. Return 0 if successful and replace

fitz/helper-other.i

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ PyObject *JM_EscapeStrFromStr(const char *c)
7272
return val;
7373
}
7474

75+
76+
// list of valid unicodes of a fz_font
77+
void JM_valid_chars(fz_context *ctx, fz_font *font, void *arr)
78+
{
79+
FT_Face face = font->ft_face;
80+
FT_ULong ucs;
81+
FT_UInt gid;
82+
long *table = (long *)arr;
83+
fz_lock(ctx, FZ_LOCK_FREETYPE);
84+
ucs = FT_Get_First_Char(face, &gid);
85+
while (gid > 0)
86+
{
87+
if (gid < (FT_ULong)face->num_glyphs && face->num_glyphs > 0)
88+
table[gid] = (long)ucs;
89+
ucs = FT_Get_Next_Char(face, ucs, &gid);
90+
}
91+
fz_unlock(ctx, FZ_LOCK_FREETYPE);
92+
return;
93+
}
94+
95+
7596
// redirect MuPDF warnings
7697
void JM_mupdf_warning(void *user, const char *message)
7798
{

fitz/helper-xobject.i

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,16 @@ fz_buffer *JM_read_contents(fz_context * ctx, pdf_obj * pageref)
3232
//-----------------------------------------------------------------------------
3333
pdf_obj *JM_xobject_from_page(fz_context * ctx, pdf_document * pdfout, fz_page * fsrcpage, int xref, pdf_graft_map *gmap)
3434
{
35-
fz_buffer *res = NULL;
3635
pdf_obj *xobj1, *resources = NULL, *o, *spageref;
37-
fz_rect mediabox;
38-
3936
fz_try(ctx) {
40-
pdf_page *srcpage = pdf_page_from_fz_page(ctx, fsrcpage);
41-
spageref = srcpage->obj;
42-
mediabox = pdf_to_rect(ctx, pdf_dict_get_inheritable(ctx, spageref, PDF_NAME(MediaBox)));
43-
4437
if (xref > 0) {
4538
xobj1 = pdf_new_indirect(ctx, pdfout, xref, 0);
4639
} else {
40+
fz_buffer *res = NULL;
41+
fz_rect mediabox;
42+
pdf_page *srcpage = pdf_page_from_fz_page(ctx, fsrcpage);
43+
spageref = srcpage->obj;
44+
mediabox = pdf_to_rect(ctx, pdf_dict_get_inheritable(ctx, spageref, PDF_NAME(MediaBox)));
4745
// Deep-copy resources object of source page
4846
o = pdf_dict_get_inheritable(ctx, spageref, PDF_NAME(Resources));
4947
if (gmap) // use graftmap when possible

0 commit comments

Comments
 (0)