@@ -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+
95111char *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
100116int fz_pixmap_size (fz_context *ctx, fz_pixmap *src);
101117void fz_subsample_pixmap (fz_context *ctx, fz_pixmap *tile, int factor);
102118void 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
106122PyObject *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
0 commit comments