@@ -92,6 +92,22 @@ CheckParent(self)%}
92
92
#include < fitz.h>
93
93
#include < pdf.h>
94
94
#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
+
95
111
char *JM_Python_str_AsChar (PyObject *str);
96
112
97
113
// additional headers from MuPDF ----------------------------------------------
@@ -100,7 +116,7 @@ fz_pixmap *fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, fl
100
116
int fz_pixmap_size (fz_context *ctx, fz_pixmap *src);
101
117
void fz_subsample_pixmap (fz_context *ctx, fz_pixmap *tile, int factor);
102
118
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
+
104
120
// end of additional MuPDF headers --------------------------------------------
105
121
106
122
PyObject *JM_mupdf_warnings_store;
@@ -859,7 +875,7 @@ struct Document
859
875
fz_try(gctx) {
860
876
int fp = from_page, tp = to_page, srcCount = fz_count_pages(gctx, fz_doc);
861
877
if (pdf_specifics(gctx, fz_doc))
862
- THROWMSG("use select+write or insertPDF for PDF docs instead ");
878
+ THROWMSG("bad document type ");
863
879
if (fp < 0) fp = 0;
864
880
if (fp > srcCount - 1) fp = srcCount - 1;
865
881
if (tp < 0) tp = srcCount - 1;
@@ -872,18 +888,34 @@ struct Document
872
888
return doc;
873
889
}
874
890
891
+ FITZEXCEPTION(pageCount, !result)
875
892
CLOSECHECK0(pageCount, """Number of pages.""")
876
893
%pythoncode%{@property%}
877
894
PyObject *pageCount()
878
895
{
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);
880
904
}
881
905
906
+ FITZEXCEPTION(chapterCount, !result)
882
907
CLOSECHECK0(chapterCount, """Number of chapters.""")
883
908
%pythoncode%{@property%}
884
909
PyObject *chapterCount()
885
910
{
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);
887
919
}
888
920
889
921
FITZEXCEPTION(lastLocation, !result)
@@ -3375,6 +3407,58 @@ struct Page {
3375
3407
return text;
3376
3408
}
3377
3409
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
+
3378
3462
//---------------------------------------------------------------------
3379
3463
// page addCaretAnnot
3380
3464
//---------------------------------------------------------------------
@@ -4314,8 +4398,8 @@ struct Page {
4314
4398
path[" even_odd" ] = True
4315
4399
elif x[0] == " matrix" :
4316
4400
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)
4319
4403
elif x[0] == " w" :
4320
4404
path[" width" ] = x[1] * factor
4321
4405
elif x[0] == " lineCap" :
@@ -5560,7 +5644,7 @@ Pixmap(PDFdoc, xref) - from an image at xref in a PDF document.
5560
5644
fz_separations *seps = NULL;
5561
5645
fz_try(gctx) {
5562
5646
if (!INRANGE(alpha, 0, 1))
5563
- THROWMSG(" illegal alpha value" );
5647
+ THROWMSG(" bad alpha value" );
5564
5648
fz_colorspace *cs = fz_pixmap_colorspace(gctx, src_pix);
5565
5649
if (!cs && !alpha)
5566
5650
THROWMSG(" cannot drop alpha for ' NULL' colorspace" );
@@ -6915,8 +6999,11 @@ struct Annot
6915
6999
pdf_obj *obj = NULL;
6916
7000
const char *text = NULL;
6917
7001
fz_try(gctx) {
6918
- if (pdf_dict_gets(gctx, annot->obj, " RO" )) {
7002
+ obj = pdf_dict_gets(gctx, annot->obj, " RO" );
7003
+ if (obj) {
6919
7004
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));
6920
7007
}
6921
7008
obj = pdf_dict_gets(gctx, annot->obj, " OverlayText" );
6922
7009
if (obj) {
@@ -9150,14 +9237,14 @@ struct Font
9150
9237
cp = array("l", (0,) * gc)
9151
9238
arr = cp.buffer_info()
9152
9239
self._valid_unicodes(arr)
9153
- return array("l", sorted(set(cp)[1:]) )
9240
+ return array("l", sorted(set(cp)) [1:])
9154
9241
%}
9155
9242
void _valid_unicodes(PyObject *arr)
9156
9243
{
9157
9244
fz_font *font = (fz_font *) $self;
9158
9245
PyObject *temp = PySequence_ITEM(arr, 0);
9159
9246
void *ptr = PyLong_AsVoidPtr(temp);
9160
- jm_valid_chars (gctx, font, ptr);
9247
+ JM_valid_chars (gctx, font, ptr);
9161
9248
Py_DECREF(temp);
9162
9249
}
9163
9250
0 commit comments