From 7b11402289379a8d31d0cbbe8b4b49cd05d1685f Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Sun, 25 Nov 2018 11:57:08 -0400 Subject: [PATCH 1/4] more performance improvements --- fitz/__init__.py | 1 + fitz/fitz.i | 350 +++++++++++------ fitz/fitz.py | 264 +++++++------ fitz/fitz_wrap.c | 875 ++++++++++++++++++++++++------------------ fitz/helper-geo-py.i | 134 ++++--- fitz/helper-xobject.i | 15 +- fitz/utils.py | 41 +- fitz/version.i | 4 +- 8 files changed, 961 insertions(+), 723 deletions(-) diff --git a/fitz/__init__.py b/fitz/__init__.py index 7418399ce..a569b1288 100644 --- a/fitz/__init__.py +++ b/fitz/__init__.py @@ -10,6 +10,7 @@ csGRAY = fitz.csGRAY csCMYK = fitz.csCMYK +# create the TOOLS object TOOLS = fitz.Tools() fitz.TOOLS = TOOLS diff --git a/fitz/fitz.i b/fitz/fitz.i index 6a222b78e..f64a9128d 100644 --- a/fitz/fitz.i +++ b/fitz/fitz.i @@ -101,7 +101,7 @@ # endif // define Python None object -#define NONE Py_BuildValue("s", NULL) +#define NONE Py_BuildValue("", NULL) #include #include @@ -387,17 +387,18 @@ struct fz_document_s CLOSECHECK(embeddedFileCount) %feature("autodoc","Return number of embedded files.") embeddedFileCount; %pythoncode%{@property%} - int embeddedFileCount() + PyObject *embeddedFileCount() { pdf_document *pdf = pdf_document_from_fz_document(gctx, $self); - if (!pdf) return 0; - return pdf_count_portfolio_entries(gctx, pdf); + int i = -1; + if (pdf) i = pdf_count_portfolio_entries(gctx, pdf); + return Py_BuildValue("i", i); } - FITZEXCEPTION(embeddedFileDel, result < 1) + FITZEXCEPTION(embeddedFileDel, !result) CLOSECHECK(embeddedFileDel) %feature("autodoc","Delete embedded file by name.") embeddedFileDel; - int embeddedFileDel(char *name) + PyObject *embeddedFileDel(char *name) { pdf_document *pdf = pdf_document_from_fz_document(gctx, $self); pdf_obj *names; @@ -432,8 +433,8 @@ struct fz_document_s } m = (n - pdf_array_len(gctx, names)) / 2; } - fz_catch(gctx) return -1; - return m; + fz_catch(gctx) return NULL; + return Py_BuildValue("i", m); } FITZEXCEPTION(embeddedFileInfo, !result) @@ -599,9 +600,9 @@ struct fz_document_s buf = fz_new_buffer(gctx, name_len + 1); // has no real meaning fz_append_string(gctx, buf, name); // fill something in fz_terminate_buffer(gctx, buf); // to make it usable - pdf_add_portfolio_entry(gctx, pdf, // insert the entry - name, name_len, // except the name, - name, name_len, // everythinh will + pdf_add_portfolio_entry(gctx, pdf, // insert the entry. + name, name_len, // Except the name, + name, name_len, // everything will name, name_len, // be overwritten name, name_len, buf); @@ -662,13 +663,14 @@ struct fz_document_s CLOSECHECK0(pageCount) %pythoncode%{@property%} - int pageCount() + PyObject *pageCount() { - return fz_count_pages(gctx, $self); + return Py_BuildValue("i", fz_count_pages(gctx, $self)); } CLOSECHECK0(_getMetadata) - char *_getMetadata(const char *key) { + char *_getMetadata(const char *key) + { int vsize; char *value; vsize = fz_lookup_metadata(gctx, $self, key, NULL, 0)+1; @@ -684,10 +686,11 @@ struct fz_document_s CLOSECHECK0(needsPass) %pythoncode%{@property%} - int needsPass() { - return fz_needs_password(gctx, $self); + PyObject *needsPass() { + return Py_BuildValue("i", fz_needs_password(gctx, $self)); } + %feature("autodoc", "Calculate internal link destination.") resolveLink; PyObject *resolveLink(char *uri = NULL) { if (!uri) return NONE; @@ -702,6 +705,7 @@ struct fz_document_s } FITZEXCEPTION(layout, !result) + %feature("autodoc", "Re-layout a reflowable document.") layout; CLOSECHECK(layout) %pythonappend layout %{ self._reset_page_refs() @@ -727,6 +731,7 @@ struct fz_document_s } CLOSECHECK(makeBookmark) + %feature("autodoc", "Make page bookmark in a reflowable document.") makeBookmark; PyObject *makeBookmark(int pno = 0) { if (!fz_is_document_reflowable(gctx, $self)) return NONE; @@ -737,11 +742,16 @@ struct fz_document_s } CLOSECHECK(findBookmark) - int findBookmark(long long bookmark) + %feature("autodoc", "Find page number after layouting a document.") findBookmark; + PyObject *findBookmark(long long bookmark) { - if (!fz_is_document_reflowable(gctx, $self)) return -1; - fz_bookmark m = (fz_bookmark) bookmark; - return fz_lookup_bookmark(gctx, $self, m); + int i = -1; + if (fz_is_document_reflowable(gctx, $self)) + { + fz_bookmark m = (fz_bookmark) bookmark; + i = fz_lookup_bookmark(gctx, $self, m); + } + return Py_BuildValue("i", i); } CLOSECHECK0(isReflowable) @@ -753,7 +763,7 @@ struct fz_document_s FITZEXCEPTION(_deleteObject, !result) CLOSECHECK0(_deleteObject) - %feature("autodoc", "Delete the object given by its xref") _deleteObject; + %feature("autodoc", "Delete an object given its xref.") _deleteObject; PyObject *_deleteObject(int xref) { pdf_document *pdf = pdf_specifics(gctx, $self); @@ -769,12 +779,12 @@ struct fz_document_s } CLOSECHECK0(_getPDFroot) - %feature("autodoc", "PDF catalog xref number") _getPDFroot; - int _getPDFroot() + %feature("autodoc", "Get XREF number of PDF catalog.") _getPDFroot; + PyObject *_getPDFroot() { pdf_document *pdf = pdf_specifics(gctx, $self); int xref = 0; - if (!pdf) return xref; + if (!pdf) return Py_BuildValue("i", xref); fz_try(gctx) { pdf_obj *root = pdf_dict_get(gctx, pdf_trailer(gctx, pdf), @@ -782,7 +792,44 @@ struct fz_document_s xref = pdf_to_num(gctx, root); } fz_catch(gctx) {;} - return xref; + return Py_BuildValue("i", xref); + } + + CLOSECHECK0(_getPDFfileid) + %feature("autodoc", "Return PDF file /ID strings (hexadecimal).") _getPDFfileid; + PyObject *_getPDFfileid() + { + pdf_document *pdf = pdf_specifics(gctx, $self); + if (!pdf) return NONE; + PyObject *idlist = PyList_New(0); + fz_buffer *buffer = NULL; + char *hex; + pdf_obj *o; + int n, i, len; + PyObject *bytes; + fz_try(gctx) + { + pdf_obj *identity = pdf_dict_get(gctx, pdf_trailer(gctx, pdf), + PDF_NAME(ID)); + if (identity) + { + n = pdf_array_len(gctx, identity); + for (i = 0; i < n; i++) + { + o = pdf_array_get(gctx, identity, i); + len = pdf_to_str_len(gctx, o); + buffer = fz_new_buffer(gctx, 2 * len); + fz_buffer_storage(gctx, buffer, &hex); + hexlify(len, (unsigned char *) pdf_to_str_buf(gctx, o), (unsigned char *) hex); + PyList_Append(idlist, Py_BuildValue("s", hex)); + Py_CLEAR(bytes); + fz_drop_buffer(gctx, buffer); + buffer = NULL; + } + } + } + fz_catch(gctx) fz_drop_buffer(gctx, buffer); + return idlist; } CLOSECHECK0(isPDF) @@ -822,12 +869,14 @@ struct fz_document_s return JM_BOOL(pdf_has_unsaved_changes(gctx, pdf)); } - int _getGCTXerrcode() { - return fz_caught(gctx); + %feature("autodoc", "Retrieve last MuPDF error code.") _getGCTXerrcode; + PyObject *_getGCTXerrcode() { + return Py_BuildValue("i", fz_caught(gctx)); } - const char *_getGCTXerrmsg() { - return fz_caught_message(gctx); + %feature("autodoc", "Retrieve last MuPDF error message.") _getGCTXerrmsg; + PyObject *_getGCTXerrmsg() { + return Py_BuildValue("s", fz_caught_message(gctx)); } CLOSECHECK0(authenticate) @@ -838,9 +887,11 @@ struct fz_document_s self.initData() self.thisown = True %} - int authenticate(char *password) { - return fz_authenticate_password(gctx, $self, (const char *) password); + PyObject *authenticate(char *password) + { + return Py_BuildValue("i", fz_authenticate_password(gctx, $self, (const char *) password)); } + //--------------------------------------------------------------------- // save(filename, ...) //--------------------------------------------------------------------- @@ -1305,7 +1356,7 @@ if links: FITZEXCEPTION(extractImage, !result) CLOSECHECK(extractImage) - %feature("autodoc","Extract image an xref points to.") extractImage; + %feature("autodoc","Extract image which 'xref' is pointing to.") extractImage; PyObject *extractImage(int xref = 0) { pdf_document *pdf = pdf_specifics(gctx, $self); @@ -1540,20 +1591,20 @@ if links: //--------------------------------------------------------------------- // Get Xref Number of Outline Root, create it if missing //--------------------------------------------------------------------- - FITZEXCEPTION(_getOLRootNumber, result<0) + FITZEXCEPTION(_getOLRootNumber, !result) CLOSECHECK(_getOLRootNumber) - int _getOLRootNumber() + PyObject *_getOLRootNumber() { pdf_document *pdf = pdf_specifics(gctx, $self); fz_try(gctx) assert_PDF(pdf); - fz_catch(gctx) return -1; + fz_catch(gctx) return NULL; pdf_obj *root, *olroot, *ind_obj; // get main root root = pdf_dict_get(gctx, pdf_trailer(gctx, pdf), PDF_NAME(Root)); // get outline root olroot = pdf_dict_get(gctx, root, PDF_NAME(Outlines)); - if (olroot == NULL) + if (!olroot) { olroot = pdf_new_dict(gctx, pdf, 4); pdf_dict_put(gctx, olroot, PDF_NAME(Type), PDF_NAME(Outlines)); @@ -1563,40 +1614,40 @@ if links: pdf_drop_obj(gctx, ind_obj); pdf->dirty = 1; } - return pdf_to_num(gctx, olroot); + return Py_BuildValue("i", pdf_to_num(gctx, olroot)); } //--------------------------------------------------------------------- // Get a new Xref number //--------------------------------------------------------------------- - FITZEXCEPTION(_getNewXref, result<0) + FITZEXCEPTION(_getNewXref, !result) CLOSECHECK(_getNewXref) - int _getNewXref() + PyObject *_getNewXref() { pdf_document *pdf = pdf_specifics(gctx, $self); /* conv doc to pdf*/ fz_try(gctx) assert_PDF(pdf); - fz_catch(gctx) return -1; + fz_catch(gctx) return NULL; pdf->dirty = 1; - return pdf_create_object(gctx, pdf); + return Py_BuildValue("i", pdf_create_object(gctx, pdf)); } //--------------------------------------------------------------------- // Get Length of Xref //--------------------------------------------------------------------- CLOSECHECK0(_getXrefLength) - int _getXrefLength() + PyObject *_getXrefLength() { pdf_document *pdf = pdf_specifics(gctx, $self); - if (!pdf) return 0; - return pdf_xref_len(gctx, pdf); + int xreflen = 0; + if (pdf) xreflen = pdf_xref_len(gctx, pdf); + return Py_BuildValue("i", xreflen); } //--------------------------------------------------------------------- // Get XML Metadata xref //--------------------------------------------------------------------- - FITZEXCEPTION(_getXmlMetadataXref, result<0) CLOSECHECK0(_getXmlMetadataXref) - int _getXmlMetadataXref() + PyObject *_getXmlMetadataXref() { pdf_document *pdf = pdf_specifics(gctx, $self); // get pdf document pdf_obj *xml; @@ -1609,8 +1660,8 @@ if links: xml = pdf_dict_gets(gctx, root, "Metadata"); if (xml) xref = pdf_to_num(gctx, xml); } - fz_catch(gctx) return -1; - return xref; + fz_catch(gctx) {;} + return Py_BuildValue("i", xref); } //--------------------------------------------------------------------- @@ -1635,14 +1686,15 @@ if links: //--------------------------------------------------------------------- // Get Object String of xref //--------------------------------------------------------------------- - FITZEXCEPTION(_getObjectString, !result) - CLOSECHECK0(_getObjectString) - const char *_getObjectString(int xref) + FITZEXCEPTION(_getXrefString, !result) + CLOSECHECK0(_getXrefString) + PyObject *_getXrefString(int xref) { pdf_document *pdf = pdf_specifics(gctx, $self); // conv doc to pdf pdf_obj *obj = NULL; fz_buffer *res = NULL; fz_output *out = NULL; + PyObject *text = NULL; fz_try(gctx) { assert_PDF(pdf); @@ -1653,21 +1705,18 @@ if links: out = fz_new_output_with_buffer(gctx, res); obj = pdf_load_object(gctx, pdf, xref); pdf_print_obj(gctx, out, pdf_resolve_indirect(gctx, obj), 1); + text = JM_StrFromBuffer(gctx, res); } fz_always(gctx) { pdf_drop_obj(gctx, obj); fz_drop_output(gctx, out); - } - fz_catch(gctx) - { fz_drop_buffer(gctx, res); - return NULL; } - return fz_string_from_buffer(gctx, res); + fz_catch(gctx) return NULL; + return text; } - %pythoncode %{_getXrefString = _getObjectString%} - + //--------------------------------------------------------------------- // Get decompressed stream of an object by xref // Return NONE if not stream @@ -2850,11 +2899,10 @@ fannot._erase() //--------------------------------------------------------------------- // Show a PDF page //--------------------------------------------------------------------- - FITZEXCEPTION(_showPDFpage, result<0) - int _showPDFpage(PyObject *rect, struct fz_document_s *docsrc, int pno=0, int overlay=1, int keep_proportion=1, int reuse_xref=0, PyObject *clip = NULL, struct pdf_graft_map_s *graftmap = NULL, char *_imgname = NULL) + FITZEXCEPTION(_showPDFpage, !result) + PyObject *_showPDFpage(PyObject *rect, struct fz_document_s *docsrc, int pno=0, int overlay=1, int keep_proportion=1, int reuse_xref=0, PyObject *clip = NULL, struct pdf_graft_map_s *graftmap = NULL, char *_imgname = NULL) { - int xref; - xref = reuse_xref; + int xref = reuse_xref; pdf_obj *xobj1, *xobj2, *resources, *o; fz_buffer *res, *nres; fz_rect mediabox; @@ -2966,8 +3014,8 @@ fannot._erase() JM_insert_contents(gctx, pdfout, tpageref, nres, overlay); fz_drop_buffer(gctx, nres); } - fz_catch(gctx) return -1; - return xref; + fz_catch(gctx) return NULL; + return Py_BuildValue("i", xref); } //--------------------------------------------------------------------- @@ -3000,7 +3048,7 @@ fannot._erase() unsigned char *streamdata = NULL; size_t streamlen = JM_CharFromBytesOrArray(stream, &streamdata); - const char *template = " q %g 0 0 %g %g %g cm /%s Do Q "; + const char *template = "\nq %g 0 0 %g %g %g cm /%s Do Q "; char *cont = NULL; Py_ssize_t name_len = 0; fz_image *zimg = NULL, *image = NULL; @@ -3238,13 +3286,13 @@ fannot._erase() { icont = pdf_array_get(gctx, contents, i); xref = pdf_to_num(gctx, icont); - PyList_Append(list, PyInt_FromLong((long) xref)); + PyList_Append(list, Py_BuildValue("i", xref)); } } else { xref = pdf_to_num(gctx, contents); - PyList_Append(list, PyInt_FromLong((long) xref)); + PyList_Append(list, Py_BuildValue("i", xref)); } } fz_catch(gctx) return NULL; @@ -3870,17 +3918,17 @@ struct fz_colorspace_s // number of bytes to define color of one pixel //---------------------------------------------------------------------- %pythoncode %{@property%} - int n() + PyObject *n() { - return fz_colorspace_n(gctx, $self); + return Py_BuildValue("i", fz_colorspace_n(gctx, $self)); } //---------------------------------------------------------------------- // name of colorspace //---------------------------------------------------------------------- - const char *_name() + PyObject *_name() { - return fz_colorspace_name(gctx, $self); + return Py_BuildValue("s", fz_colorspace_name(gctx, $self)); } %pythoncode %{ @@ -4011,23 +4059,23 @@ struct fz_outline_s { %extend { %pythoncode %{@property%} %pythonappend uri %{ - if not val: - return "" - - nval = "".join([c for c in val if 32 <= ord(c) <= 127]) - val = nval + if val: + nval = "".join([c for c in val if 32 <= ord(c) <= 127]) + val = nval + else: + val = "" %} - char *uri() - { - return $self->uri; - } + PyObject *uri() + { + return Py_BuildValue("s", $self->uri); + } %pythoncode %{@property%} - int isExternal() - { - if (!$self->uri) return 0; - return fz_is_external_link(gctx, $self->uri); - } + PyObject *isExternal() + { + if (!$self->uri) Py_RETURN_FALSE; + return JM_BOOL(fz_is_external_link(gctx, $self->uri)); + } %pythoncode %{isOpen = is_open%} %pythoncode %{ @@ -4184,11 +4232,12 @@ struct fz_annot_s PARENTCHECK(_getXref) %feature("autodoc","Xref number of annotation") _getXref; %pythoncode %{@property%} - int xref() + PyObject *xref() { pdf_annot *annot = pdf_annot_from_fz_annot(gctx, $self); - if(!annot) return 0; - return pdf_to_num(gctx, annot->obj); + int i = 0; + if(annot) i = pdf_to_num(gctx, annot->obj); + return Py_BuildValue("i", i); } //--------------------------------------------------------------------- @@ -4663,14 +4712,17 @@ struct fz_annot_s //--------------------------------------------------------------------- PARENTCHECK(opacity) %pythoncode %{@property%} - float opacity() + PyObject *opacity() { pdf_annot *annot = pdf_annot_from_fz_annot(gctx, $self); - if (!annot) return -1.0f; // not a PDF - pdf_obj *ca = pdf_dict_get(gctx, annot->obj, PDF_NAME(CA)); - if (pdf_is_number(gctx, ca)) - return pdf_to_real(gctx, ca); - return -1.0f; + double opy = -1.0f; + if (annot) + { + pdf_obj *ca = pdf_dict_get(gctx, annot->obj, PDF_NAME(CA)); + if (pdf_is_number(gctx, ca)) + opy = pdf_to_real(gctx, ca); + } + return Py_BuildValue("f", opy); } //--------------------------------------------------------------------- @@ -5444,21 +5496,22 @@ struct fz_link_s %pythoncode %{@property%} %pythonappend uri %{ if not val: - return "" - nval = "".join([c for c in val if 32 <= ord(c) <= 127]) - val = nval + val = "" + else: + nval = "".join([c for c in val if 32 <= ord(c) <= 127]) + val = nval %} - char *uri() + PyObject *uri() { - return $self->uri; + return Py_BuildValue("s", $self->uri); } PARENTCHECK(isExternal) %pythoncode %{@property%} - int isExternal() + PyObject *isExternal() { - if (!$self->uri) return 0; - return fz_is_external_link(gctx, $self->uri); + if (!$self->uri) Py_RETURN_FALSE; + return JM_BOOL(fz_is_external_link(gctx, $self->uri)); } %pythoncode @@ -5562,15 +5615,15 @@ struct fz_display_list_s { return dl; } - FITZEXCEPTION(run, result) - int run(struct DeviceWrapper *dw, PyObject *m, PyObject *area) { + FITZEXCEPTION(run, !result) + PyObject *run(struct DeviceWrapper *dw, PyObject *m, PyObject *area) { fz_try(gctx) { fz_run_display_list(gctx, $self, dw->device, JM_matrix_from_py(m), JM_rect_from_py(area), NULL); } - fz_catch(gctx) return 1; - return 0; + fz_catch(gctx) return NULL; + return NONE; } //--------------------------------------------------------------------- @@ -5960,38 +6013,38 @@ struct Tools { %extend { - %feature("autodoc","Return a unique integer.") gen_id; - int gen_id() + %feature("autodoc","Return a unique positive integer.") gen_id; + PyObject *gen_id() { JM_UNIQUE_ID += 1; if (JM_UNIQUE_ID < 0) JM_UNIQUE_ID = 1; - return JM_UNIQUE_ID; + return Py_BuildValue("i", JM_UNIQUE_ID); } %feature("autodoc","Free 'percent' of current store size.") store_shrink; - size_t store_shrink(unsigned int percent) + PyObject *store_shrink(int percent) { if (percent >= 100) { fz_empty_store(gctx); - return 0; + return Py_BuildValue("i", 0); } if (percent > 0) fz_shrink_store(gctx, 100 - percent); - return gctx->store->size; + return Py_BuildValue("i", (int) gctx->store->size); } %feature("autodoc","Current store size.") store_size; %pythoncode%{@property%} - size_t store_size() + PyObject *store_size() { - return gctx->store->size; + return Py_BuildValue("i", (int) gctx->store->size); } %feature("autodoc","Maximum store size.") store_maxsize; %pythoncode%{@property%} - size_t store_maxsize() + PyObject *store_maxsize() { - return gctx->store->max; + return Py_BuildValue("i", (int) gctx->store->max); } %feature("autodoc","Show configuration data.") fitz_config; @@ -6007,13 +6060,30 @@ struct Tools fz_purge_glyph_cache(gctx); } + FITZEXCEPTION(_insert_contents, !result) + PyObject *_insert_contents(struct fz_page_s *fzpage, PyObject *newcont, int overlay) + { + fz_buffer *contbuf = NULL; + int xref = 0; + pdf_page *page = pdf_page_from_fz_page(gctx, fzpage); + fz_try(gctx) + { + assert_PDF(page); + contbuf = JM_BufferFromBytes(gctx, newcont); + xref = JM_insert_contents(gctx, page->doc, page->obj, contbuf, overlay); + } + fz_always(gctx) fz_drop_buffer(gctx, contbuf); + fz_catch(gctx) return NULL; + return Py_BuildValue("i", xref); + } + %pythoncode%{@property%} - char *fitz_stdout() + PyObject *fitz_stdout() { - return PyByteArray_AS_STRING(JM_output_log); + return Py_BuildValue("s", PyByteArray_AS_STRING(JM_output_log)); } - %feature("autodoc","Empty fitz output log.") empty_error_log; + %feature("autodoc","Empty fitz output log.") fitz_stdout_reset; void fitz_stdout_reset() { Py_CLEAR(JM_output_log); @@ -6021,29 +6091,53 @@ struct Tools } %pythoncode%{@property%} - char *fitz_stderr() + PyObject *fitz_stderr() { - return PyByteArray_AS_STRING(JM_error_log); + return Py_BuildValue("s", PyByteArray_AS_STRING(JM_error_log)); } - %feature("autodoc","Empty fitz error log.") empty_error_log; + %feature("autodoc","Empty fitz error log.") fitz_stderr_reset; void fitz_stderr_reset() { Py_CLEAR(JM_error_log); JM_error_log = PyByteArray_FromStringAndSize("", 0); } - char *mupdf_version() + %feature("autodoc","Return compiled MuPDF version.") mupdf_version; + PyObject *mupdf_version() { - return FZ_VERSION; + return Py_BuildValue("s", FZ_VERSION); } - PyObject *transform_rect(PyObject *rect, PyObject *matrix) + %feature("autodoc","Transform rectangle with matrix.") _transform_rect; + PyObject *_transform_rect(PyObject *rect, PyObject *matrix) { return JM_py_from_rect(fz_transform_rect(JM_rect_from_py(rect), JM_matrix_from_py(matrix))); } - PyObject *invert_matrix(PyObject *matrix) + %feature("autodoc","Intersect two rectangles.") _intersect_rect; + PyObject *_intersect_rect(PyObject *r1, PyObject *r2) + { + return JM_py_from_rect(fz_intersect_rect(JM_rect_from_py(r1), + JM_rect_from_py(r2))); + } + + %feature("autodoc","Include point in a rect.") _include_point_in_rect; + PyObject *_include_point_in_rect(PyObject *r, PyObject *p) + { + return JM_py_from_rect(fz_include_point_in_rect(JM_rect_from_py(r), + JM_point_from_py(p))); + } + + %feature("autodoc","Replace r1 with smallest rect containing both.") _union_rect; + PyObject *_union_rect(PyObject *r1, PyObject *r2) + { + return JM_py_from_rect(fz_union_rect(JM_rect_from_py(r1), + JM_rect_from_py(r2))); + } + + %feature("autodoc","Invert a matrix.") _invert_matrix; + PyObject *_invert_matrix(PyObject *matrix) { fz_matrix src = JM_matrix_from_py(matrix); float a = src.a; @@ -6059,9 +6153,9 @@ struct Tools a = -src.e * dst.a - src.f * dst.c; dst.f = -src.e * dst.b - src.f * dst.d; dst.e = a; - return JM_py_from_matrix(dst); + return Py_BuildValue("(i, O)", 0, JM_py_from_matrix(dst)); } - return Py_BuildValue("ffffff", 0,0,0,0,0,0); + return Py_BuildValue("(i, ())", 1); } %pythoncode %{ diff --git a/fitz/fitz.py b/fitz/fitz.py index 108d660f3..f53ded69b 100644 --- a/fitz/fitz.py +++ b/fitz/fitz.py @@ -107,8 +107,8 @@ class _object: VersionFitz = "1.14.0" VersionBind = "1.14.2" -VersionDate = "2018-11-20 06:27:22" -version = (VersionBind, VersionFitz, "20181120062722") +VersionDate = "2018-11-25 10:19:28" +version = (VersionBind, VersionFitz, "20181125101928") class Matrix(): @@ -160,16 +160,17 @@ def invert(self, src=None): current one. Else return 1 and do nothing. """ if src is None: - src = self - dst = TOOLS.invert_matrix(src) - if min(dst) >= max(dst): + dst = TOOLS._invert_matrix(self) + else: + dst = TOOLS._invert_matrix(src) + if dst[0] == 1: return 1 - self.a = dst[0] - self.b = dst[1] - self.c = dst[2] - self.d = dst[3] - self.e = dst[4] - self.f = dst[5] + self.a = dst[1][0] + self.b = dst[1][1] + self.c = dst[1][2] + self.d = dst[1][3] + self.e = dst[1][4] + self.f = dst[1][5] return 0 def preTranslate(self, tx, ty): @@ -296,9 +297,9 @@ def __truediv__(self, m): if hasattr(m, "__float__"): return Matrix(self.a * 1./m, self.b * 1./m, self.c * 1./m, self.d * 1./m, self.e * 1./m, self.f * 1./m) - m1 = TOOLS.invert_matrix(m) - if min(m1) >= max(m1): - raise ZeroDivisionError("op2 is not invertible") + m1 = TOOLS._invert_matrix(m)[1] + if not m1: + raise ZeroDivisionError("matrix not invertible") return self.concat(self, m1) __div__ = __truediv__ @@ -323,10 +324,10 @@ def __neg__(self): return Matrix(-self.a, -self.b, -self.c, -self.d, -self.e, -self.f) def __bool__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __nonzero__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __eq__(self, m): if not hasattr(m, "__len__"): @@ -484,10 +485,10 @@ def __neg__(self): return Point(-self.x, -self.y) def __bool__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __nonzero__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __eq__(self, p): if not hasattr(p, "__len__"): @@ -516,9 +517,9 @@ def __mul__(self, m): def __truediv__(self, m): if hasattr(m, "__float__"): return Point(self.x * 1./m, self.y * 1./m) - m1 = TOOLS.invert_matrix(m) - if min(m1) >= max(m1): - raise ZeroDivisionError("op2 is not invertible") + m1 = TOOLS._invert_matrix(m)[1] + if not m1: + raise ZeroDivisionError("matrix not invertible") p = Point(self) return p.transform(m1) @@ -620,9 +621,8 @@ def quad(self): return Quad(self.tl, self.tr, self.bl, self.br) def round(self): - r = Rect(self).normalize() - ir = IRect(math.floor(r.x0), math.floor(r.y0), math.ceil(r.x1), math.ceil(r.y1)) - return ir + return IRect(min(self.x0, self.x1), min(self.y0, self.y1), + max(self.x0, self.x1), max(self.y0, self.y1)) irect = property(round) @@ -631,46 +631,31 @@ def round(self): def includePoint(self, p): """Extend rectangle to include point p.""" - x0 = min(self.x0, self.x1, p[0]) - x1 = max(self.x0, self.x1, p[0]) - y0 = min(self.y0, self.y1, p[1]) - y1 = max(self.y0, self.y1, p[1]) - self.x0 = x0 - self.y0 = y0 - self.x1 = x1 - self.y1 = y1 + r0 = TOOLS._include_point_in_rect(self, p); + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self def includeRect(self, r): """Extend rectangle to include rectangle r.""" - x0 = min(self.x0, self.x1, r[0], r[2]) - x1 = max(self.x0, self.x1, r[0], r[2]) - y0 = min(self.y0, self.y1, r[1], r[3]) - y1 = max(self.y0, self.y1, r[1], r[3]) - self.x0 = x0 - self.y0 = y0 - self.x1 = x1 - self.y1 = y1 + r0 = TOOLS._union_rect(self, r) + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self def intersect(self, r): - """Restrict rectangle to common area with rectangle r.""" - if self.isEmpty: return Rect() - r1 = Rect(r) - if r1.isEmpty: return Rect() - if r1.isInfinite: return self - if self.isInfinite: return r1 - x0 = max(self.x0, r1.x0) - x1 = min(self.x1, r1.x1) - y0 = max(self.y0, r1.y0) - y1 = min(self.y1, r1.y1) - if x1 < x0 or y1 < y0: - self = Rect() - else: - self = Rect(x0, y0, x1, y1) + """Restrict self to common area with rectangle r.""" + r0 = TOOLS._intersect_rect(self, r); + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self - def __getitem__(self, i): return (self.x0, self.y0, self.x1, self.y1)[i] @@ -696,10 +681,10 @@ def __neg__(self): return Rect(-self.x0, -self.y0, -self.x1, -self.y1) def __bool__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __nonzero__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __eq__(self, p): if not hasattr(p, "__len__"): @@ -725,7 +710,11 @@ def __sub__(self, p): def transform(self, m): """Replace rectangle with its transformation by matrix m.""" - self = Rect(TOOLS.transform_rect(self, m)) + r0 = TOOLS._transform_rect(self, m) + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self def __mul__(self, m): @@ -738,9 +727,9 @@ def __mul__(self, m): def __truediv__(self, m): if hasattr(m, "__float__"): return Rect(self.x0 * 1./m, self.y0 * 1./m, self.x1 * 1./m, self.y1 * 1./m) - im = TOOLS.invert_matrix(m) - if min(im) >= max(im): - raise ZeroDivisionError("op2 is not invertible") + im = TOOLS._invert_matrix(m)[1] + if not im: + raise ZeroDivisionError("matrix not invertible") r = Rect(self) r = r.transform(im) return r @@ -803,10 +792,10 @@ class IRect(Rect): """IRect() - all zeros\nIRect(x0, y0, x1, y1)\nIRect(Rect or IRect) - new copy\nIRect(sequence) - from 'sequence'""" def __init__(self, *args): Rect.__init__(self, *args) - self.x0 = math.floor(self.x0) - self.y0 = math.floor(self.y0) - self.x1 = math.ceil(self.x1) - self.y1 = math.ceil(self.y1) + self.x0 = math.floor(self.x0 + 0.001) + self.y0 = math.floor(self.y0 + 0.001) + self.x1 = math.ceil(self.x1 - 0.001) + self.y1 = math.ceil(self.y1 - 0.001) return None @property @@ -900,6 +889,9 @@ def __init__(self, *args): @property def isRectangular(self): + """Check if quad is rectangular. + """ +# if any two of the 4 corners are equal return false upper = (self.ur - self.ul).unit if not bool(upper): return False @@ -913,13 +905,19 @@ def isRectangular(self): if not bool(lower): return False eps = 1e-5 - +# we now have 4 sides of length 1. If 3 of them have 90 deg angles, +# then it is a rectangle -- we check via scalar product == 0 return abs(sum(map(lambda x,y: x*y, upper, right))) <= eps and \ abs(sum(map(lambda x,y: x*y, upper, left))) <= eps and \ abs(sum(map(lambda x,y: x*y, left, lower))) <= eps @property def isEmpty(self): + """Check if quad is empty retangle. If rectangular, we are done (not empty). + But all 4 points may still be on one line. We check this out here. + In that case all 3 lines connecting corners to ul will have same angle with + x-axis. + """ if self.isRectangular: return False eps = 1e-5 @@ -993,13 +991,13 @@ def __mul__(self, m): return r def __truediv__(self, m): - r = Quad(self) if hasattr(m, "__float__"): im = 1. / m else: - im = TOOLS.invert_matrix(m) - if min(im) >= max(im): - raise ZeroDivisionError("op2 is not invertible") + im = TOOLS._invert_matrix(m)[1] + if not im: + raise ZeroDivisionError("matrix not invertible") + r = Quad(self) r = r.transform(im) return r @@ -1754,7 +1752,7 @@ def convertToPDF(self, from_page=0, to_page=-1, rotate=0): @property def pageCount(self): - """pageCount(self) -> int""" + """pageCount(self) -> PyObject *""" if self.isClosed: raise ValueError("operation illegal for closed doc") @@ -1771,7 +1769,7 @@ def _getMetadata(self, key): @property def needsPass(self): - """needsPass(self) -> int""" + """needsPass(self) -> PyObject *""" if self.isClosed: raise ValueError("operation illegal for closed doc") @@ -1779,12 +1777,12 @@ def needsPass(self): def resolveLink(self, uri=None): - """resolveLink(self, uri=None) -> PyObject *""" + """Calculate internal link destination.""" return _fitz.Document_resolveLink(self, uri) def layout(self, rect=None, width=0, height=0, fontsize=11): - """layout(self, rect=None, width=0, height=0, fontsize=11) -> PyObject *""" + """Re-layout a reflowable document.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") @@ -1797,7 +1795,7 @@ def layout(self, rect=None, width=0, height=0, fontsize=11): def makeBookmark(self, pno=0): - """makeBookmark(self, pno=0) -> PyObject *""" + """Make page bookmark in a reflowable document.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") @@ -1805,7 +1803,7 @@ def makeBookmark(self, pno=0): def findBookmark(self, bookmark): - """findBookmark(self, bookmark) -> int""" + """Find page number after layouting a document.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") @@ -1822,7 +1820,7 @@ def isReflowable(self): def _deleteObject(self, xref): - """Delete the object given by its xref""" + """Delete an object given its xref.""" if self.isClosed: raise ValueError("operation illegal for closed doc") @@ -1830,12 +1828,20 @@ def _deleteObject(self, xref): def _getPDFroot(self): - """PDF catalog xref number""" + """Get XREF number of PDF catalog.""" if self.isClosed: raise ValueError("operation illegal for closed doc") return _fitz.Document__getPDFroot(self) + + def _getPDFfileid(self): + """Return PDF file /ID strings (hexadecimal).""" + if self.isClosed: + raise ValueError("operation illegal for closed doc") + + return _fitz.Document__getPDFfileid(self) + @property def isPDF(self): @@ -1874,12 +1880,12 @@ def isDirty(self): def _getGCTXerrcode(self): - """_getGCTXerrcode(self) -> int""" + """Retrieve last MuPDF error code.""" return _fitz.Document__getGCTXerrcode(self) def _getGCTXerrmsg(self): - """_getGCTXerrmsg(self) -> char const *""" + """Retrieve last MuPDF error message.""" return _fitz.Document__getGCTXerrmsg(self) @@ -2041,7 +2047,7 @@ def extractFont(self, xref=0, info_only=0): def extractImage(self, xref=0): - """Extract image an xref points to.""" + """Extract image which 'xref' is pointing to.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") @@ -2086,7 +2092,7 @@ def _addFormFont(self, name, font): def _getOLRootNumber(self): - """_getOLRootNumber(self) -> int""" + """_getOLRootNumber(self) -> PyObject *""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") @@ -2094,7 +2100,7 @@ def _getOLRootNumber(self): def _getNewXref(self): - """_getNewXref(self) -> int""" + """_getNewXref(self) -> PyObject *""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") @@ -2102,7 +2108,7 @@ def _getNewXref(self): def _getXrefLength(self): - """_getXrefLength(self) -> int""" + """_getXrefLength(self) -> PyObject *""" if self.isClosed: raise ValueError("operation illegal for closed doc") @@ -2110,7 +2116,7 @@ def _getXrefLength(self): def _getXmlMetadataXref(self): - """_getXmlMetadataXref(self) -> int""" + """_getXmlMetadataXref(self) -> PyObject *""" if self.isClosed: raise ValueError("operation illegal for closed doc") @@ -2125,14 +2131,13 @@ def _delXmlMetadata(self): return _fitz.Document__delXmlMetadata(self) - def _getObjectString(self, xref): - """_getObjectString(self, xref) -> char const *""" + def _getXrefString(self, xref): + """_getXrefString(self, xref) -> PyObject *""" if self.isClosed: raise ValueError("operation illegal for closed doc") - return _fitz.Document__getObjectString(self, xref) + return _fitz.Document__getXrefString(self, xref) - _getXrefString = _getObjectString def _getXrefStream(self, xref): """_getXrefStream(self, xref) -> PyObject *""" @@ -2738,7 +2743,7 @@ def _cleanContents(self): def _showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None): - """_showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> int""" + """_showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *""" return _fitz.Page__showPDFpage(self, rect, docsrc, pno, overlay, keep_proportion, reuse_xref, clip, graftmap, _imgname) @@ -3085,12 +3090,12 @@ def __init__(self, type): @property def n(self): - """n(self) -> int""" + """n(self) -> PyObject *""" return _fitz.Colorspace_n(self) def _name(self): - """_name(self) -> char const *""" + """_name(self) -> PyObject *""" return _fitz.Colorspace__name(self) @@ -3165,14 +3170,14 @@ def __init__(self, *args, **kwargs): @property def uri(self): - """uri(self) -> char *""" + """uri(self) -> PyObject *""" val = _fitz.Outline_uri(self) - if not val: - return "" - - nval = "".join([c for c in val if 32 <= ord(c) <= 127]) - val = nval + if val: + nval = "".join([c for c in val if 32 <= ord(c) <= 127]) + val = nval + else: + val = "" return val @@ -3180,7 +3185,7 @@ def uri(self): @property def isExternal(self): - """isExternal(self) -> int""" + """isExternal(self) -> PyObject *""" return _fitz.Outline_isExternal(self) isOpen = is_open @@ -3299,7 +3304,7 @@ def rect(self): @property def xref(self): - """xref(self) -> int""" + """xref(self) -> PyObject *""" return _fitz.Annot_xref(self) @@ -3521,7 +3526,7 @@ def type(self): @property def opacity(self): - """opacity(self) -> float""" + """opacity(self) -> PyObject *""" CheckParent(self) return _fitz.Annot_opacity(self) @@ -3795,15 +3800,16 @@ def setColors(self, colors): @property def uri(self): - """uri(self) -> char *""" + """uri(self) -> PyObject *""" CheckParent(self) val = _fitz.Link_uri(self) if not val: - return "" - nval = "".join([c for c in val if 32 <= ord(c) <= 127]) - val = nval + val = "" + else: + nval = "".join([c for c in val if 32 <= ord(c) <= 127]) + val = nval return val @@ -3811,7 +3817,7 @@ def uri(self): @property def isExternal(self): - """isExternal(self) -> int""" + """isExternal(self) -> PyObject *""" CheckParent(self) return _fitz.Link_isExternal(self) @@ -3911,7 +3917,7 @@ def __init__(self, mediabox): self.this = this def run(self, dw, m, area): - """run(self, dw, m, area) -> int""" + """run(self, dw, m, area) -> PyObject *""" return _fitz.DisplayList_run(self, dw, m, area) @property @@ -4077,7 +4083,7 @@ class Tools(_object): __repr__ = _swig_repr def gen_id(self): - """Return a unique integer.""" + """Return a unique positive integer.""" return _fitz.Tools_gen_id(self) @@ -4108,42 +4114,62 @@ def glyph_cache_empty(self): """Empty the glyph cache.""" return _fitz.Tools_glyph_cache_empty(self) + + def _insert_contents(self, fzpage, newcont, overlay): + """_insert_contents(self, fzpage, newcont, overlay) -> PyObject *""" + return _fitz.Tools__insert_contents(self, fzpage, newcont, overlay) + @property def fitz_stdout(self): - """fitz_stdout(self) -> char *""" + """fitz_stdout(self) -> PyObject *""" return _fitz.Tools_fitz_stdout(self) def fitz_stdout_reset(self): - """fitz_stdout_reset(self)""" + """Empty fitz output log.""" return _fitz.Tools_fitz_stdout_reset(self) @property def fitz_stderr(self): - """fitz_stderr(self) -> char *""" + """fitz_stderr(self) -> PyObject *""" return _fitz.Tools_fitz_stderr(self) def fitz_stderr_reset(self): - """fitz_stderr_reset(self)""" + """Empty fitz error log.""" return _fitz.Tools_fitz_stderr_reset(self) def mupdf_version(self): - """mupdf_version(self) -> char *""" + """Return compiled MuPDF version.""" return _fitz.Tools_mupdf_version(self) - def transform_rect(self, rect, matrix): - """transform_rect(self, rect, matrix) -> PyObject *""" - return _fitz.Tools_transform_rect(self, rect, matrix) + def _transform_rect(self, rect, matrix): + """Transform rectangle with matrix.""" + return _fitz.Tools__transform_rect(self, rect, matrix) + + + def _intersect_rect(self, r1, r2): + """Intersect two rectangles.""" + return _fitz.Tools__intersect_rect(self, r1, r2) + + + def _include_point_in_rect(self, r, p): + """Include point in a rect.""" + return _fitz.Tools__include_point_in_rect(self, r, p) + + + def _union_rect(self, r1, r2): + """Replace r1 with smallest rect containing both.""" + return _fitz.Tools__union_rect(self, r1, r2) - def invert_matrix(self, matrix): - """invert_matrix(self, matrix) -> PyObject *""" - return _fitz.Tools_invert_matrix(self, matrix) + def _invert_matrix(self, matrix): + """Invert a matrix.""" + return _fitz.Tools__invert_matrix(self, matrix) diff --git a/fitz/fitz_wrap.c b/fitz/fitz_wrap.c index ac35342a9..7acfd95b0 100644 --- a/fitz/fitz_wrap.c +++ b/fitz/fitz_wrap.c @@ -3073,7 +3073,7 @@ static swig_module_info swig_module = {swig_types, 13, 0, 0, 0, 0}; # endif // define Python None object -#define NONE Py_BuildValue("s", NULL) +#define NONE Py_BuildValue("", NULL) #include #include @@ -8789,22 +8789,27 @@ pdf_obj *JM_xobject_from_page(fz_context *ctx, pdf_document *pdfout, pdf_documen //----------------------------------------------------------------------------- // Insert a buffer as a new separate /Contents object of a page. +// 1. Create a new stream object from buffer 'newcont' +// 2. If /Contents already is an array, then just prepend or append this object +// 3. Create new array and put old content obj and new obj into it //----------------------------------------------------------------------------- -void JM_insert_contents(fz_context *ctx, pdf_document *pdf, +int JM_insert_contents(fz_context *ctx, pdf_document *pdf, pdf_obj *pageref, fz_buffer *newcont, int overlay) { + int xref = 0; fz_try(ctx) { pdf_obj *contents = pdf_dict_get(ctx, pageref, PDF_NAME(Contents)); pdf_obj *newconts = pdf_add_stream(ctx, pdf, newcont, NULL, 0); + xref = pdf_to_num(ctx, newconts); if (pdf_is_array(ctx, contents)) { - if (overlay) + if (overlay) // append new object pdf_array_push_drop(ctx, contents, newconts); - else + else // prepend new object pdf_array_insert_drop(ctx, contents, newconts, 0); } - else + else // make new array { pdf_obj *carr = pdf_new_array(ctx, pdf, 2); if (overlay) @@ -8821,7 +8826,7 @@ void JM_insert_contents(fz_context *ctx, pdf_document *pdf, } } fz_catch(ctx) fz_rethrow(ctx); - return; + return xref; } /*----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -9628,19 +9633,13 @@ SWIGINTERN void fz_document_s__dropOutline(struct fz_document_s *self,struct fz_ fz_drop_outline(gctx, ol); DEBUGMSG2; } -SWIGINTERN int fz_document_s_embeddedFileCount(struct fz_document_s *self){ +SWIGINTERN PyObject *fz_document_s_embeddedFileCount(struct fz_document_s *self){ pdf_document *pdf = pdf_document_from_fz_document(gctx, self); - if (!pdf) return 0; - return pdf_count_portfolio_entries(gctx, pdf); + int i = -1; + if (pdf) i = pdf_count_portfolio_entries(gctx, pdf); + return Py_BuildValue("i", i); } - -SWIGINTERNINLINE PyObject* - SWIG_From_int (int value) -{ - return PyInt_FromLong((long) value); -} - -SWIGINTERN int fz_document_s_embeddedFileDel(struct fz_document_s *self,char *name){ +SWIGINTERN PyObject *fz_document_s_embeddedFileDel(struct fz_document_s *self,char *name){ pdf_document *pdf = pdf_document_from_fz_document(gctx, self); pdf_obj *names; int i, n, m; @@ -9674,8 +9673,8 @@ SWIGINTERN int fz_document_s_embeddedFileDel(struct fz_document_s *self,char *na } m = (n - pdf_array_len(gctx, names)) / 2; } - fz_catch(gctx) return -1; - return m; + fz_catch(gctx) return NULL; + return Py_BuildValue("i", m); } SWIGINTERN PyObject *fz_document_s_embeddedFileInfo(struct fz_document_s *self,PyObject *id){ pdf_document *pdf = pdf_document_from_fz_document(gctx, self); @@ -9815,9 +9814,9 @@ SWIGINTERN PyObject *fz_document_s_embeddedFileAdd(struct fz_document_s *self,Py buf = fz_new_buffer(gctx, name_len + 1); // has no real meaning fz_append_string(gctx, buf, name); // fill something in fz_terminate_buffer(gctx, buf); // to make it usable - pdf_add_portfolio_entry(gctx, pdf, // insert the entry - name, name_len, // except the name, - name, name_len, // everythinh will + pdf_add_portfolio_entry(gctx, pdf, // insert the entry. + name, name_len, // Except the name, + name, name_len, // everything will name, name_len, // be overwritten name, name_len, buf); @@ -9870,8 +9869,8 @@ SWIGINTERN PyObject *fz_document_s_convertToPDF(struct fz_document_s *self,int f fz_catch(gctx) return NULL; return doc; } -SWIGINTERN int fz_document_s_pageCount(struct fz_document_s *self){ - return fz_count_pages(gctx, self); +SWIGINTERN PyObject *fz_document_s_pageCount(struct fz_document_s *self){ + return Py_BuildValue("i", fz_count_pages(gctx, self)); } SWIGINTERN char *fz_document_s__getMetadata(struct fz_document_s *self,char const *key){ int vsize; @@ -9922,8 +9921,8 @@ SWIG_FromCharPtr(const char *cptr) return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); } -SWIGINTERN int fz_document_s_needsPass(struct fz_document_s *self){ - return fz_needs_password(gctx, self); +SWIGINTERN PyObject *fz_document_s_needsPass(struct fz_document_s *self){ + return Py_BuildValue("i", fz_needs_password(gctx, self)); } SWIGINTERN PyObject *fz_document_s_resolveLink(struct fz_document_s *self,char *uri){ if (!uri) return NONE; @@ -10008,10 +10007,14 @@ SWIG_AsVal_long_SS_long (PyObject *obj, long long *val) } #endif -SWIGINTERN int fz_document_s_findBookmark(struct fz_document_s *self,long long bookmark){ - if (!fz_is_document_reflowable(gctx, self)) return -1; - fz_bookmark m = (fz_bookmark) bookmark; - return fz_lookup_bookmark(gctx, self, m); +SWIGINTERN PyObject *fz_document_s_findBookmark(struct fz_document_s *self,long long bookmark){ + int i = -1; + if (fz_is_document_reflowable(gctx, self)) + { + fz_bookmark m = (fz_bookmark) bookmark; + i = fz_lookup_bookmark(gctx, self, m); + } + return Py_BuildValue("i", i); } SWIGINTERN PyObject *fz_document_s_isReflowable(struct fz_document_s *self){ return JM_BOOL(fz_is_document_reflowable(gctx, self)); @@ -10028,10 +10031,10 @@ SWIGINTERN PyObject *fz_document_s__deleteObject(struct fz_document_s *self,int fz_catch(gctx) return NULL; return NONE; } -SWIGINTERN int fz_document_s__getPDFroot(struct fz_document_s *self){ +SWIGINTERN PyObject *fz_document_s__getPDFroot(struct fz_document_s *self){ pdf_document *pdf = pdf_specifics(gctx, self); int xref = 0; - if (!pdf) return xref; + if (!pdf) return Py_BuildValue("i", xref); fz_try(gctx) { pdf_obj *root = pdf_dict_get(gctx, pdf_trailer(gctx, pdf), @@ -10039,7 +10042,40 @@ SWIGINTERN int fz_document_s__getPDFroot(struct fz_document_s *self){ xref = pdf_to_num(gctx, root); } fz_catch(gctx) {;} - return xref; + return Py_BuildValue("i", xref); + } +SWIGINTERN PyObject *fz_document_s__getPDFfileid(struct fz_document_s *self){ + pdf_document *pdf = pdf_specifics(gctx, self); + if (!pdf) return NONE; + PyObject *idlist = PyList_New(0); + fz_buffer *buffer = NULL; + char *hex; + pdf_obj *o; + int n, i, len; + PyObject *bytes; + fz_try(gctx) + { + pdf_obj *identity = pdf_dict_get(gctx, pdf_trailer(gctx, pdf), + PDF_NAME(ID)); + if (identity) + { + n = pdf_array_len(gctx, identity); + for (i = 0; i < n; i++) + { + o = pdf_array_get(gctx, identity, i); + len = pdf_to_str_len(gctx, o); + buffer = fz_new_buffer(gctx, 2 * len); + fz_buffer_storage(gctx, buffer, &hex); + hexlify(len, (unsigned char *) pdf_to_str_buf(gctx, o), (unsigned char *) hex); + PyList_Append(idlist, Py_BuildValue("s", hex)); + Py_CLEAR(bytes); + fz_drop_buffer(gctx, buffer); + buffer = NULL; + } + } + } + fz_catch(gctx) fz_drop_buffer(gctx, buffer); + return idlist; } SWIGINTERN PyObject *fz_document_s_isPDF(struct fz_document_s *self){ if (pdf_specifics(gctx, self)) Py_RETURN_TRUE; @@ -10062,14 +10098,14 @@ SWIGINTERN PyObject *fz_document_s_isDirty(struct fz_document_s *self){ if (!pdf) Py_RETURN_FALSE; return JM_BOOL(pdf_has_unsaved_changes(gctx, pdf)); } -SWIGINTERN int fz_document_s__getGCTXerrcode(struct fz_document_s *self){ - return fz_caught(gctx); +SWIGINTERN PyObject *fz_document_s__getGCTXerrcode(struct fz_document_s *self){ + return Py_BuildValue("i", fz_caught(gctx)); } -SWIGINTERN char const *fz_document_s__getGCTXerrmsg(struct fz_document_s *self){ - return fz_caught_message(gctx); +SWIGINTERN PyObject *fz_document_s__getGCTXerrmsg(struct fz_document_s *self){ + return Py_BuildValue("s", fz_caught_message(gctx)); } -SWIGINTERN int fz_document_s_authenticate(struct fz_document_s *self,char *password){ - return fz_authenticate_password(gctx, self, (const char *) password); +SWIGINTERN PyObject *fz_document_s_authenticate(struct fz_document_s *self,char *password){ + return Py_BuildValue("i", fz_authenticate_password(gctx, self, (const char *) password)); } SWIGINTERN PyObject *fz_document_s_save(struct fz_document_s *self,char *filename,int garbage,int clean,int deflate,int incremental,int ascii,int expand,int linear,int pretty,int decrypt){ int errors = 0; @@ -10196,6 +10232,13 @@ SWIGINTERN int fz_document_s_insertPage(struct fz_document_s *self,int pno,PyObj pdf->dirty = 1; return 0; } + +SWIGINTERNINLINE PyObject* + SWIG_From_int (int value) +{ + return PyInt_FromLong((long) value); +} + SWIGINTERN PyObject *fz_document_s_select(struct fz_document_s *self,PyObject *pyliste){ // preparatory stuff: // (1) get underlying pdf document, @@ -10598,17 +10641,17 @@ SWIGINTERN PyObject *fz_document_s__addFormFont(struct fz_document_s *self,char fz_catch(gctx) NULL; return NONE; } -SWIGINTERN int fz_document_s__getOLRootNumber(struct fz_document_s *self){ +SWIGINTERN PyObject *fz_document_s__getOLRootNumber(struct fz_document_s *self){ pdf_document *pdf = pdf_specifics(gctx, self); fz_try(gctx) assert_PDF(pdf); - fz_catch(gctx) return -1; + fz_catch(gctx) return NULL; pdf_obj *root, *olroot, *ind_obj; // get main root root = pdf_dict_get(gctx, pdf_trailer(gctx, pdf), PDF_NAME(Root)); // get outline root olroot = pdf_dict_get(gctx, root, PDF_NAME(Outlines)); - if (olroot == NULL) + if (!olroot) { olroot = pdf_new_dict(gctx, pdf, 4); pdf_dict_put(gctx, olroot, PDF_NAME(Type), PDF_NAME(Outlines)); @@ -10618,21 +10661,22 @@ SWIGINTERN int fz_document_s__getOLRootNumber(struct fz_document_s *self){ pdf_drop_obj(gctx, ind_obj); pdf->dirty = 1; } - return pdf_to_num(gctx, olroot); + return Py_BuildValue("i", pdf_to_num(gctx, olroot)); } -SWIGINTERN int fz_document_s__getNewXref(struct fz_document_s *self){ +SWIGINTERN PyObject *fz_document_s__getNewXref(struct fz_document_s *self){ pdf_document *pdf = pdf_specifics(gctx, self); /* conv doc to pdf*/ fz_try(gctx) assert_PDF(pdf); - fz_catch(gctx) return -1; + fz_catch(gctx) return NULL; pdf->dirty = 1; - return pdf_create_object(gctx, pdf); + return Py_BuildValue("i", pdf_create_object(gctx, pdf)); } -SWIGINTERN int fz_document_s__getXrefLength(struct fz_document_s *self){ +SWIGINTERN PyObject *fz_document_s__getXrefLength(struct fz_document_s *self){ pdf_document *pdf = pdf_specifics(gctx, self); - if (!pdf) return 0; - return pdf_xref_len(gctx, pdf); + int xreflen = 0; + if (pdf) xreflen = pdf_xref_len(gctx, pdf); + return Py_BuildValue("i", xreflen); } -SWIGINTERN int fz_document_s__getXmlMetadataXref(struct fz_document_s *self){ +SWIGINTERN PyObject *fz_document_s__getXmlMetadataXref(struct fz_document_s *self){ pdf_document *pdf = pdf_specifics(gctx, self); // get pdf document pdf_obj *xml; int xref = 0; @@ -10644,8 +10688,8 @@ SWIGINTERN int fz_document_s__getXmlMetadataXref(struct fz_document_s *self){ xml = pdf_dict_gets(gctx, root, "Metadata"); if (xml) xref = pdf_to_num(gctx, xml); } - fz_catch(gctx) return -1; - return xref; + fz_catch(gctx) {;} + return Py_BuildValue("i", xref); } SWIGINTERN PyObject *fz_document_s__delXmlMetadata(struct fz_document_s *self){ pdf_document *pdf = pdf_specifics(gctx, self); // get pdf document @@ -10659,11 +10703,12 @@ SWIGINTERN PyObject *fz_document_s__delXmlMetadata(struct fz_document_s *self){ pdf->dirty = 1; return NONE; } -SWIGINTERN char const *fz_document_s__getObjectString(struct fz_document_s *self,int xref){ +SWIGINTERN PyObject *fz_document_s__getXrefString(struct fz_document_s *self,int xref){ pdf_document *pdf = pdf_specifics(gctx, self); // conv doc to pdf pdf_obj *obj = NULL; fz_buffer *res = NULL; fz_output *out = NULL; + PyObject *text = NULL; fz_try(gctx) { assert_PDF(pdf); @@ -10674,18 +10719,16 @@ SWIGINTERN char const *fz_document_s__getObjectString(struct fz_document_s *self out = fz_new_output_with_buffer(gctx, res); obj = pdf_load_object(gctx, pdf, xref); pdf_print_obj(gctx, out, pdf_resolve_indirect(gctx, obj), 1); + text = JM_StrFromBuffer(gctx, res); } fz_always(gctx) { pdf_drop_obj(gctx, obj); fz_drop_output(gctx, out); - } - fz_catch(gctx) - { fz_drop_buffer(gctx, res); - return NULL; } - return fz_string_from_buffer(gctx, res); + fz_catch(gctx) return NULL; + return text; } SWIGINTERN PyObject *fz_document_s__getXrefStream(struct fz_document_s *self,int xref){ pdf_document *pdf = pdf_specifics(gctx, self); @@ -11388,9 +11431,8 @@ SWIGINTERN PyObject *fz_page_s__cleanContents(struct fz_page_s *self){ page->doc->dirty = 1; return NONE; } -SWIGINTERN int fz_page_s__showPDFpage(struct fz_page_s *self,PyObject *rect,struct fz_document_s *docsrc,int pno,int overlay,int keep_proportion,int reuse_xref,PyObject *clip,struct pdf_graft_map_s *graftmap,char *_imgname){ - int xref; - xref = reuse_xref; +SWIGINTERN PyObject *fz_page_s__showPDFpage(struct fz_page_s *self,PyObject *rect,struct fz_document_s *docsrc,int pno,int overlay,int keep_proportion,int reuse_xref,PyObject *clip,struct pdf_graft_map_s *graftmap,char *_imgname){ + int xref = reuse_xref; pdf_obj *xobj1, *xobj2, *resources, *o; fz_buffer *res, *nres; fz_rect mediabox; @@ -11502,8 +11544,8 @@ SWIGINTERN int fz_page_s__showPDFpage(struct fz_page_s *self,PyObject *rect,stru JM_insert_contents(gctx, pdfout, tpageref, nres, overlay); fz_drop_buffer(gctx, nres); } - fz_catch(gctx) return -1; - return xref; + fz_catch(gctx) return NULL; + return Py_BuildValue("i", xref); } SWIGINTERN PyObject *fz_page_s_insertImage(struct fz_page_s *self,PyObject *rect,char const *filename,struct fz_pixmap_s *pixmap,PyObject *stream,int overlay,char *_imgname){ pdf_page *page = pdf_page_from_fz_page(gctx, self); @@ -11518,7 +11560,7 @@ SWIGINTERN PyObject *fz_page_s_insertImage(struct fz_page_s *self,PyObject *rect unsigned char *streamdata = NULL; size_t streamlen = JM_CharFromBytesOrArray(stream, &streamdata); - const char *template = " q %g 0 0 %g %g %g cm /%s Do Q "; + const char *template = "\nq %g 0 0 %g %g %g cm /%s Do Q "; char *cont = NULL; Py_ssize_t name_len = 0; fz_image *zimg = NULL, *image = NULL; @@ -11717,13 +11759,13 @@ SWIGINTERN PyObject *fz_page_s__getContents(struct fz_page_s *self){ { icont = pdf_array_get(gctx, contents, i); xref = pdf_to_num(gctx, icont); - PyList_Append(list, PyInt_FromLong((long) xref)); + PyList_Append(list, Py_BuildValue("i", xref)); } } else { xref = pdf_to_num(gctx, contents); - PyList_Append(list, PyInt_FromLong((long) xref)); + PyList_Append(list, Py_BuildValue("i", xref)); } } fz_catch(gctx) return NULL; @@ -12072,11 +12114,11 @@ SWIGINTERN struct fz_colorspace_s *new_fz_colorspace_s(int type){ break; } } -SWIGINTERN int fz_colorspace_s_n(struct fz_colorspace_s *self){ - return fz_colorspace_n(gctx, self); +SWIGINTERN PyObject *fz_colorspace_s_n(struct fz_colorspace_s *self){ + return Py_BuildValue("i", fz_colorspace_n(gctx, self)); } -SWIGINTERN char const *fz_colorspace_s__name(struct fz_colorspace_s *self){ - return fz_colorspace_name(gctx, self); +SWIGINTERN PyObject *fz_colorspace_s__name(struct fz_colorspace_s *self){ + return Py_BuildValue("s", fz_colorspace_name(gctx, self)); } SWIGINTERN struct DeviceWrapper *new_DeviceWrapper__SWIG_0(struct fz_pixmap_s *pm,PyObject *clip){ struct DeviceWrapper *dw = NULL; @@ -12126,13 +12168,13 @@ SWIGINTERN void delete_DeviceWrapper(struct DeviceWrapper *self){ DEBUGMSG2; } } -SWIGINTERN char *fz_outline_s_uri(struct fz_outline_s *self){ - return self->uri; - } -SWIGINTERN int fz_outline_s_isExternal(struct fz_outline_s *self){ - if (!self->uri) return 0; - return fz_is_external_link(gctx, self->uri); - } +SWIGINTERN PyObject *fz_outline_s_uri(struct fz_outline_s *self){ + return Py_BuildValue("s", self->uri); + } +SWIGINTERN PyObject *fz_outline_s_isExternal(struct fz_outline_s *self){ + if (!self->uri) Py_RETURN_FALSE; + return JM_BOOL(fz_is_external_link(gctx, self->uri)); + } SWIGINTERN void delete_fz_annot_s(struct fz_annot_s *self){ DEBUGMSG1("annot"); fz_drop_annot(gctx, self); @@ -12142,10 +12184,11 @@ SWIGINTERN PyObject *fz_annot_s_rect(struct fz_annot_s *self){ fz_rect r = fz_bound_annot(gctx, self); return JM_py_from_rect(r); } -SWIGINTERN int fz_annot_s_xref(struct fz_annot_s *self){ +SWIGINTERN PyObject *fz_annot_s_xref(struct fz_annot_s *self){ pdf_annot *annot = pdf_annot_from_fz_annot(gctx, self); - if(!annot) return 0; - return pdf_to_num(gctx, annot->obj); + int i = 0; + if(annot) i = pdf_to_num(gctx, annot->obj); + return Py_BuildValue("i", i); } SWIGINTERN PyObject *fz_annot_s__getAP(struct fz_annot_s *self){ PyObject *r = NONE; @@ -12396,24 +12439,17 @@ SWIGINTERN PyObject *fz_annot_s_type(struct fz_annot_s *self){ const char *it = pdf_to_name(gctx, o); return Py_BuildValue("iss", type, c, it); } -SWIGINTERN float fz_annot_s_opacity(struct fz_annot_s *self){ +SWIGINTERN PyObject *fz_annot_s_opacity(struct fz_annot_s *self){ pdf_annot *annot = pdf_annot_from_fz_annot(gctx, self); - if (!annot) return -1.0f; // not a PDF - pdf_obj *ca = pdf_dict_get(gctx, annot->obj, PDF_NAME(CA)); - if (pdf_is_number(gctx, ca)) - return pdf_to_real(gctx, ca); - return -1.0f; + double opy = -1.0f; + if (annot) + { + pdf_obj *ca = pdf_dict_get(gctx, annot->obj, PDF_NAME(CA)); + if (pdf_is_number(gctx, ca)) + opy = pdf_to_real(gctx, ca); + } + return Py_BuildValue("f", opy); } - - #define SWIG_From_double PyFloat_FromDouble - - -SWIGINTERNINLINE PyObject * -SWIG_From_float (float value) -{ - return SWIG_From_double (value); -} - SWIGINTERN void fz_annot_s_setOpacity(struct fz_annot_s *self,float opacity){ pdf_annot *annot = pdf_annot_from_fz_annot(gctx, self); if (!annot) return; // not a PDF @@ -12938,12 +12974,12 @@ SWIGINTERN PyObject *fz_link_s__setColors(struct fz_link_s *self,PyObject *color pdf_drop_obj(gctx, link_obj); return NONE; } -SWIGINTERN char *fz_link_s_uri(struct fz_link_s *self){ - return self->uri; +SWIGINTERN PyObject *fz_link_s_uri(struct fz_link_s *self){ + return Py_BuildValue("s", self->uri); } -SWIGINTERN int fz_link_s_isExternal(struct fz_link_s *self){ - if (!self->uri) return 0; - return fz_is_external_link(gctx, self->uri); +SWIGINTERN PyObject *fz_link_s_isExternal(struct fz_link_s *self){ + if (!self->uri) Py_RETURN_FALSE; + return JM_BOOL(fz_is_external_link(gctx, self->uri)); } SWIGINTERN PyObject *fz_link_s_rect(struct fz_link_s *self){ return JM_py_from_rect(self->rect); @@ -12964,14 +13000,14 @@ SWIGINTERN struct fz_display_list_s *new_fz_display_list_s(PyObject *mediabox){ fz_catch(gctx) return NULL; return dl; } -SWIGINTERN int fz_display_list_s_run(struct fz_display_list_s *self,struct DeviceWrapper *dw,PyObject *m,PyObject *area){ +SWIGINTERN PyObject *fz_display_list_s_run(struct fz_display_list_s *self,struct DeviceWrapper *dw,PyObject *m,PyObject *area){ fz_try(gctx) { fz_run_display_list(gctx, self, dw->device, JM_matrix_from_py(m), JM_rect_from_py(area), NULL); } - fz_catch(gctx) return 1; - return 0; + fz_catch(gctx) return NULL; + return NONE; } SWIGINTERN PyObject *fz_display_list_s_rect(struct fz_display_list_s *self){ return JM_py_from_rect(fz_bound_display_list(gctx, self)); @@ -13216,126 +13252,25 @@ SWIGINTERN struct pdf_graft_map_s *new_pdf_graft_map_s(struct fz_document_s *doc fz_catch(gctx) return NULL; return map; } -SWIGINTERN int Tools_gen_id(struct Tools *self){ +SWIGINTERN PyObject *Tools_gen_id(struct Tools *self){ JM_UNIQUE_ID += 1; if (JM_UNIQUE_ID < 0) JM_UNIQUE_ID = 1; - return JM_UNIQUE_ID; + return Py_BuildValue("i", JM_UNIQUE_ID); } - -SWIGINTERN int -SWIG_AsVal_unsigned_SS_long (PyObject *obj, unsigned long *val) -{ -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(obj)) { - long v = PyInt_AsLong(obj); - if (v >= 0) { - if (val) *val = v; - return SWIG_OK; - } else { - return SWIG_OverflowError; - } - } else -#endif - if (PyLong_Check(obj)) { - unsigned long v = PyLong_AsUnsignedLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_OK; - } else { - PyErr_Clear(); - return SWIG_OverflowError; - } - } -#ifdef SWIG_PYTHON_CAST_MODE - { - int dispatch = 0; - unsigned long v = PyLong_AsUnsignedLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_AddCast(SWIG_OK); - } else { - PyErr_Clear(); - } - if (!dispatch) { - double d; - int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); - if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) { - if (val) *val = (unsigned long)(d); - return res; - } - } - } -#endif - return SWIG_TypeError; -} - - -SWIGINTERN int -SWIG_AsVal_unsigned_SS_int (PyObject * obj, unsigned int *val) -{ - unsigned long v; - int res = SWIG_AsVal_unsigned_SS_long (obj, &v); - if (SWIG_IsOK(res)) { - if ((v > UINT_MAX)) { - return SWIG_OverflowError; - } else { - if (val) *val = (unsigned int)(v); - } - } - return res; -} - -SWIGINTERN size_t Tools_store_shrink(struct Tools *self,unsigned int percent){ +SWIGINTERN PyObject *Tools_store_shrink(struct Tools *self,int percent){ if (percent >= 100) { fz_empty_store(gctx); - return 0; + return Py_BuildValue("i", 0); } if (percent > 0) fz_shrink_store(gctx, 100 - percent); - return gctx->store->size; + return Py_BuildValue("i", (int) gctx->store->size); } - - #define SWIG_From_long PyInt_FromLong - - -SWIGINTERNINLINE PyObject* -SWIG_From_unsigned_SS_long (unsigned long value) -{ - return (value > LONG_MAX) ? - PyLong_FromUnsignedLong(value) : PyInt_FromLong((long)(value)); -} - - -#ifdef SWIG_LONG_LONG_AVAILABLE -SWIGINTERNINLINE PyObject* -SWIG_From_unsigned_SS_long_SS_long (unsigned long long value) -{ - return (value > LONG_MAX) ? - PyLong_FromUnsignedLongLong(value) : PyInt_FromLong((long)(value)); -} -#endif - - -SWIGINTERNINLINE PyObject * -SWIG_From_size_t (size_t value) -{ -#ifdef SWIG_LONG_LONG_AVAILABLE - if (sizeof(size_t) <= sizeof(unsigned long)) { -#endif - return SWIG_From_unsigned_SS_long ((unsigned long)(value)); -#ifdef SWIG_LONG_LONG_AVAILABLE - } else { - /* assume sizeof(size_t) <= sizeof(unsigned long long) */ - return SWIG_From_unsigned_SS_long_SS_long ((unsigned long long)(value)); - } -#endif -} - -SWIGINTERN size_t Tools_store_size(struct Tools *self){ - return gctx->store->size; +SWIGINTERN PyObject *Tools_store_size(struct Tools *self){ + return Py_BuildValue("i", (int) gctx->store->size); } -SWIGINTERN size_t Tools_store_maxsize(struct Tools *self){ - return gctx->store->max; +SWIGINTERN PyObject *Tools_store_maxsize(struct Tools *self){ + return Py_BuildValue("i", (int) gctx->store->max); } SWIGINTERN PyObject *Tools_fitz_config(struct Tools *self){ return JM_fitz_config(); @@ -13343,27 +13278,53 @@ SWIGINTERN PyObject *Tools_fitz_config(struct Tools *self){ SWIGINTERN void Tools_glyph_cache_empty(struct Tools *self){ fz_purge_glyph_cache(gctx); } -SWIGINTERN char *Tools_fitz_stdout(struct Tools *self){ - return PyByteArray_AS_STRING(JM_output_log); +SWIGINTERN PyObject *Tools__insert_contents(struct Tools *self,struct fz_page_s *fzpage,PyObject *newcont,int overlay){ + fz_buffer *contbuf = NULL; + int xref = 0; + pdf_page *page = pdf_page_from_fz_page(gctx, fzpage); + fz_try(gctx) + { + assert_PDF(page); + contbuf = JM_BufferFromBytes(gctx, newcont); + xref = JM_insert_contents(gctx, page->doc, page->obj, contbuf, overlay); + } + fz_always(gctx) fz_drop_buffer(gctx, contbuf); + fz_catch(gctx) return NULL; + return Py_BuildValue("i", xref); + } +SWIGINTERN PyObject *Tools_fitz_stdout(struct Tools *self){ + return Py_BuildValue("s", PyByteArray_AS_STRING(JM_output_log)); } SWIGINTERN void Tools_fitz_stdout_reset(struct Tools *self){ Py_CLEAR(JM_output_log); JM_output_log = PyByteArray_FromStringAndSize("", 0); } -SWIGINTERN char *Tools_fitz_stderr(struct Tools *self){ - return PyByteArray_AS_STRING(JM_error_log); +SWIGINTERN PyObject *Tools_fitz_stderr(struct Tools *self){ + return Py_BuildValue("s", PyByteArray_AS_STRING(JM_error_log)); } SWIGINTERN void Tools_fitz_stderr_reset(struct Tools *self){ Py_CLEAR(JM_error_log); JM_error_log = PyByteArray_FromStringAndSize("", 0); } -SWIGINTERN char *Tools_mupdf_version(struct Tools *self){ - return FZ_VERSION; +SWIGINTERN PyObject *Tools_mupdf_version(struct Tools *self){ + return Py_BuildValue("s", FZ_VERSION); } -SWIGINTERN PyObject *Tools_transform_rect(struct Tools *self,PyObject *rect,PyObject *matrix){ +SWIGINTERN PyObject *Tools__transform_rect(struct Tools *self,PyObject *rect,PyObject *matrix){ return JM_py_from_rect(fz_transform_rect(JM_rect_from_py(rect), JM_matrix_from_py(matrix))); } -SWIGINTERN PyObject *Tools_invert_matrix(struct Tools *self,PyObject *matrix){ +SWIGINTERN PyObject *Tools__intersect_rect(struct Tools *self,PyObject *r1,PyObject *r2){ + return JM_py_from_rect(fz_intersect_rect(JM_rect_from_py(r1), + JM_rect_from_py(r2))); + } +SWIGINTERN PyObject *Tools__include_point_in_rect(struct Tools *self,PyObject *r,PyObject *p){ + return JM_py_from_rect(fz_include_point_in_rect(JM_rect_from_py(r), + JM_point_from_py(p))); + } +SWIGINTERN PyObject *Tools__union_rect(struct Tools *self,PyObject *r1,PyObject *r2){ + return JM_py_from_rect(fz_union_rect(JM_rect_from_py(r1), + JM_rect_from_py(r2))); + } +SWIGINTERN PyObject *Tools__invert_matrix(struct Tools *self,PyObject *matrix){ fz_matrix src = JM_matrix_from_py(matrix); float a = src.a; float det = a * src.d - src.b * src.c; @@ -13378,9 +13339,9 @@ SWIGINTERN PyObject *Tools_invert_matrix(struct Tools *self,PyObject *matrix){ a = -src.e * dst.a - src.f * dst.c; dst.f = -src.e * dst.b - src.f * dst.d; dst.e = a; - return JM_py_from_matrix(dst); + return Py_BuildValue("(i, O)", 0, JM_py_from_matrix(dst)); } - return Py_BuildValue("ffffff", 0,0,0,0,0,0); + return Py_BuildValue("(i, ())", 1); } #ifdef __cplusplus extern "C" { @@ -13616,7 +13577,7 @@ SWIGINTERN PyObject *_wrap_Document_embeddedFileCount(PyObject *SWIGUNUSEDPARM(s void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document_embeddedFileCount",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -13624,8 +13585,8 @@ SWIGINTERN PyObject *_wrap_Document_embeddedFileCount(PyObject *SWIGUNUSEDPARM(s SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document_embeddedFileCount" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - result = (int)fz_document_s_embeddedFileCount(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s_embeddedFileCount(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -13643,7 +13604,7 @@ SWIGINTERN PyObject *_wrap_Document_embeddedFileDel(PyObject *SWIGUNUSEDPARM(sel int alloc2 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"OO:Document_embeddedFileDel",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -13657,14 +13618,14 @@ SWIGINTERN PyObject *_wrap_Document_embeddedFileDel(PyObject *SWIGUNUSEDPARM(sel } arg2 = (char *)(buf2); { - result = (int)fz_document_s_embeddedFileDel(arg1,arg2); - if(result < 1) + result = (PyObject *)fz_document_s_embeddedFileDel(arg1,arg2); + if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); return NULL; } } - resultobj = SWIG_From_int((int)(result)); + resultobj = result; if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); return resultobj; fail: @@ -13970,7 +13931,7 @@ SWIGINTERN PyObject *_wrap_Document_pageCount(PyObject *SWIGUNUSEDPARM(self), Py void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document_pageCount",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -13978,8 +13939,8 @@ SWIGINTERN PyObject *_wrap_Document_pageCount(PyObject *SWIGUNUSEDPARM(self), Py SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document_pageCount" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - result = (int)fz_document_s_pageCount(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s_pageCount(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -14026,7 +13987,7 @@ SWIGINTERN PyObject *_wrap_Document_needsPass(PyObject *SWIGUNUSEDPARM(self), Py void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document_needsPass",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -14034,8 +13995,8 @@ SWIGINTERN PyObject *_wrap_Document_needsPass(PyObject *SWIGUNUSEDPARM(self), Py SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document_needsPass" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - result = (int)fz_document_s_needsPass(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s_needsPass(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -14188,7 +14149,7 @@ SWIGINTERN PyObject *_wrap_Document_findBookmark(PyObject *SWIGUNUSEDPARM(self), int ecode2 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"OO:Document_findBookmark",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -14201,8 +14162,8 @@ SWIGINTERN PyObject *_wrap_Document_findBookmark(PyObject *SWIGUNUSEDPARM(self), SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Document_findBookmark" "', argument " "2"" of type '" "long long""'"); } arg2 = (long long)(val2); - result = (int)fz_document_s_findBookmark(arg1,arg2); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s_findBookmark(arg1,arg2); + resultobj = result; return resultobj; fail: return NULL; @@ -14275,7 +14236,7 @@ SWIGINTERN PyObject *_wrap_Document__getPDFroot(PyObject *SWIGUNUSEDPARM(self), void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document__getPDFroot",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -14283,8 +14244,30 @@ SWIGINTERN PyObject *_wrap_Document__getPDFroot(PyObject *SWIGUNUSEDPARM(self), SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getPDFroot" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - result = (int)fz_document_s__getPDFroot(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s__getPDFroot(arg1); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Document__getPDFfileid(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + struct fz_document_s *arg1 = (struct fz_document_s *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:Document__getPDFfileid",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getPDFfileid" "', argument " "1"" of type '" "struct fz_document_s *""'"); + } + arg1 = (struct fz_document_s *)(argp1); + result = (PyObject *)fz_document_s__getPDFfileid(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -14385,7 +14368,7 @@ SWIGINTERN PyObject *_wrap_Document__getGCTXerrcode(PyObject *SWIGUNUSEDPARM(sel void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document__getGCTXerrcode",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -14393,8 +14376,8 @@ SWIGINTERN PyObject *_wrap_Document__getGCTXerrcode(PyObject *SWIGUNUSEDPARM(sel SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getGCTXerrcode" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - result = (int)fz_document_s__getGCTXerrcode(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s__getGCTXerrcode(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -14407,7 +14390,7 @@ SWIGINTERN PyObject *_wrap_Document__getGCTXerrmsg(PyObject *SWIGUNUSEDPARM(self void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document__getGCTXerrmsg",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -14415,8 +14398,8 @@ SWIGINTERN PyObject *_wrap_Document__getGCTXerrmsg(PyObject *SWIGUNUSEDPARM(self SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getGCTXerrmsg" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - result = (char *)fz_document_s__getGCTXerrmsg(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); + result = (PyObject *)fz_document_s__getGCTXerrmsg(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -14434,7 +14417,7 @@ SWIGINTERN PyObject *_wrap_Document_authenticate(PyObject *SWIGUNUSEDPARM(self), int alloc2 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"OO:Document_authenticate",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -14447,8 +14430,8 @@ SWIGINTERN PyObject *_wrap_Document_authenticate(PyObject *SWIGUNUSEDPARM(self), SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Document_authenticate" "', argument " "2"" of type '" "char *""'"); } arg2 = (char *)(buf2); - result = (int)fz_document_s_authenticate(arg1,arg2); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s_authenticate(arg1,arg2); + resultobj = result; if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); return resultobj; fail: @@ -15353,7 +15336,7 @@ SWIGINTERN PyObject *_wrap_Document__getOLRootNumber(PyObject *SWIGUNUSEDPARM(se void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document__getOLRootNumber",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -15362,14 +15345,14 @@ SWIGINTERN PyObject *_wrap_Document__getOLRootNumber(PyObject *SWIGUNUSEDPARM(se } arg1 = (struct fz_document_s *)(argp1); { - result = (int)fz_document_s__getOLRootNumber(arg1); - if(result<0) + result = (PyObject *)fz_document_s__getOLRootNumber(arg1); + if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); return NULL; } } - resultobj = SWIG_From_int((int)(result)); + resultobj = result; return resultobj; fail: return NULL; @@ -15382,7 +15365,7 @@ SWIGINTERN PyObject *_wrap_Document__getNewXref(PyObject *SWIGUNUSEDPARM(self), void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document__getNewXref",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -15391,14 +15374,14 @@ SWIGINTERN PyObject *_wrap_Document__getNewXref(PyObject *SWIGUNUSEDPARM(self), } arg1 = (struct fz_document_s *)(argp1); { - result = (int)fz_document_s__getNewXref(arg1); - if(result<0) + result = (PyObject *)fz_document_s__getNewXref(arg1); + if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); return NULL; } } - resultobj = SWIG_From_int((int)(result)); + resultobj = result; return resultobj; fail: return NULL; @@ -15411,7 +15394,7 @@ SWIGINTERN PyObject *_wrap_Document__getXrefLength(PyObject *SWIGUNUSEDPARM(self void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document__getXrefLength",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -15419,8 +15402,8 @@ SWIGINTERN PyObject *_wrap_Document__getXrefLength(PyObject *SWIGUNUSEDPARM(self SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getXrefLength" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - result = (int)fz_document_s__getXrefLength(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s__getXrefLength(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -15433,7 +15416,7 @@ SWIGINTERN PyObject *_wrap_Document__getXmlMetadataXref(PyObject *SWIGUNUSEDPARM void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Document__getXmlMetadataXref",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); @@ -15441,15 +15424,8 @@ SWIGINTERN PyObject *_wrap_Document__getXmlMetadataXref(PyObject *SWIGUNUSEDPARM SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getXmlMetadataXref" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); - { - result = (int)fz_document_s__getXmlMetadataXref(arg1); - if(result<0) - { - PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); - return NULL; - } - } - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_document_s__getXmlMetadataXref(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -15485,7 +15461,7 @@ SWIGINTERN PyObject *_wrap_Document__delXmlMetadata(PyObject *SWIGUNUSEDPARM(sel } -SWIGINTERN PyObject *_wrap_Document__getObjectString(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Document__getXrefString(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; struct fz_document_s *arg1 = (struct fz_document_s *) 0 ; int arg2 ; @@ -15495,28 +15471,28 @@ SWIGINTERN PyObject *_wrap_Document__getObjectString(PyObject *SWIGUNUSEDPARM(se int ecode2 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)"OO:Document__getObjectString",&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTuple(args,(char *)"OO:Document__getXrefString",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getObjectString" "', argument " "1"" of type '" "struct fz_document_s *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getXrefString" "', argument " "1"" of type '" "struct fz_document_s *""'"); } arg1 = (struct fz_document_s *)(argp1); ecode2 = SWIG_AsVal_int(obj1, &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Document__getObjectString" "', argument " "2"" of type '" "int""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Document__getXrefString" "', argument " "2"" of type '" "int""'"); } arg2 = (int)(val2); { - result = (char *)fz_document_s__getObjectString(arg1,arg2); + result = (PyObject *)fz_document_s__getXrefString(arg1,arg2); if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); return NULL; } } - resultobj = SWIG_FromCharPtr((const char *)result); + resultobj = result; return resultobj; fail: return NULL; @@ -16832,7 +16808,7 @@ SWIGINTERN PyObject *_wrap_Page__showPDFpage(PyObject *SWIGUNUSEDPARM(self), PyO PyObject * obj7 = 0 ; PyObject * obj8 = 0 ; PyObject * obj9 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"OOO|OOOOOOO:Page__showPDFpage",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6,&obj7,&obj8,&obj9)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_page_s, 0 | 0 ); @@ -16892,14 +16868,14 @@ SWIGINTERN PyObject *_wrap_Page__showPDFpage(PyObject *SWIGUNUSEDPARM(self), PyO arg10 = (char *)(buf10); } { - result = (int)fz_page_s__showPDFpage(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10); - if(result<0) + result = (PyObject *)fz_page_s__showPDFpage(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10); + if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); return NULL; } } - resultobj = SWIG_From_int((int)(result)); + resultobj = result; if (alloc10 == SWIG_NEWOBJ) free((char*)buf10); return resultobj; fail: @@ -18696,7 +18672,7 @@ SWIGINTERN PyObject *_wrap_Colorspace_n(PyObject *SWIGUNUSEDPARM(self), PyObject void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Colorspace_n",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_colorspace_s, 0 | 0 ); @@ -18704,8 +18680,8 @@ SWIGINTERN PyObject *_wrap_Colorspace_n(PyObject *SWIGUNUSEDPARM(self), PyObject SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Colorspace_n" "', argument " "1"" of type '" "struct fz_colorspace_s *""'"); } arg1 = (struct fz_colorspace_s *)(argp1); - result = (int)fz_colorspace_s_n(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_colorspace_s_n(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -18718,7 +18694,7 @@ SWIGINTERN PyObject *_wrap_Colorspace__name(PyObject *SWIGUNUSEDPARM(self), PyOb void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Colorspace__name",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_colorspace_s, 0 | 0 ); @@ -18726,8 +18702,8 @@ SWIGINTERN PyObject *_wrap_Colorspace__name(PyObject *SWIGUNUSEDPARM(self), PyOb SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Colorspace__name" "', argument " "1"" of type '" "struct fz_colorspace_s *""'"); } arg1 = (struct fz_colorspace_s *)(argp1); - result = (char *)fz_colorspace_s__name(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); + result = (PyObject *)fz_colorspace_s__name(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -19048,7 +19024,7 @@ SWIGINTERN PyObject *_wrap_Outline_uri(PyObject *SWIGUNUSEDPARM(self), PyObject void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Outline_uri",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_outline_s, 0 | 0 ); @@ -19056,8 +19032,8 @@ SWIGINTERN PyObject *_wrap_Outline_uri(PyObject *SWIGUNUSEDPARM(self), PyObject SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Outline_uri" "', argument " "1"" of type '" "struct fz_outline_s *""'"); } arg1 = (struct fz_outline_s *)(argp1); - result = (char *)fz_outline_s_uri(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); + result = (PyObject *)fz_outline_s_uri(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -19070,7 +19046,7 @@ SWIGINTERN PyObject *_wrap_Outline_isExternal(PyObject *SWIGUNUSEDPARM(self), Py void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Outline_isExternal",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_outline_s, 0 | 0 ); @@ -19078,8 +19054,8 @@ SWIGINTERN PyObject *_wrap_Outline_isExternal(PyObject *SWIGUNUSEDPARM(self), Py SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Outline_isExternal" "', argument " "1"" of type '" "struct fz_outline_s *""'"); } arg1 = (struct fz_outline_s *)(argp1); - result = (int)fz_outline_s_isExternal(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_outline_s_isExternal(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -19163,7 +19139,7 @@ SWIGINTERN PyObject *_wrap_Annot_xref(PyObject *SWIGUNUSEDPARM(self), PyObject * void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Annot_xref",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_annot_s, 0 | 0 ); @@ -19171,8 +19147,8 @@ SWIGINTERN PyObject *_wrap_Annot_xref(PyObject *SWIGUNUSEDPARM(self), PyObject * SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Annot_xref" "', argument " "1"" of type '" "struct fz_annot_s *""'"); } arg1 = (struct fz_annot_s *)(argp1); - result = (int)fz_annot_s_xref(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_annot_s_xref(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -19491,7 +19467,7 @@ SWIGINTERN PyObject *_wrap_Annot_opacity(PyObject *SWIGUNUSEDPARM(self), PyObjec void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - float result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Annot_opacity",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_annot_s, 0 | 0 ); @@ -19499,8 +19475,8 @@ SWIGINTERN PyObject *_wrap_Annot_opacity(PyObject *SWIGUNUSEDPARM(self), PyObjec SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Annot_opacity" "', argument " "1"" of type '" "struct fz_annot_s *""'"); } arg1 = (struct fz_annot_s *)(argp1); - result = (float)fz_annot_s_opacity(arg1); - resultobj = SWIG_From_float((float)(result)); + result = (PyObject *)fz_annot_s_opacity(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -20283,7 +20259,7 @@ SWIGINTERN PyObject *_wrap_Link_uri(PyObject *SWIGUNUSEDPARM(self), PyObject *ar void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Link_uri",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_link_s, 0 | 0 ); @@ -20291,8 +20267,8 @@ SWIGINTERN PyObject *_wrap_Link_uri(PyObject *SWIGUNUSEDPARM(self), PyObject *ar SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Link_uri" "', argument " "1"" of type '" "struct fz_link_s *""'"); } arg1 = (struct fz_link_s *)(argp1); - result = (char *)fz_link_s_uri(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); + result = (PyObject *)fz_link_s_uri(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -20305,7 +20281,7 @@ SWIGINTERN PyObject *_wrap_Link_isExternal(PyObject *SWIGUNUSEDPARM(self), PyObj void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Link_isExternal",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_link_s, 0 | 0 ); @@ -20313,8 +20289,8 @@ SWIGINTERN PyObject *_wrap_Link_isExternal(PyObject *SWIGUNUSEDPARM(self), PyObj SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Link_isExternal" "', argument " "1"" of type '" "struct fz_link_s *""'"); } arg1 = (struct fz_link_s *)(argp1); - result = (int)fz_link_s_isExternal(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)fz_link_s_isExternal(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -20430,7 +20406,7 @@ SWIGINTERN PyObject *_wrap_DisplayList_run(PyObject *SWIGUNUSEDPARM(self), PyObj PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; PyObject * obj3 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"OOOO:DisplayList_run",&obj0,&obj1,&obj2,&obj3)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_display_list_s, 0 | 0 ); @@ -20446,14 +20422,14 @@ SWIGINTERN PyObject *_wrap_DisplayList_run(PyObject *SWIGUNUSEDPARM(self), PyObj arg3 = obj2; arg4 = obj3; { - result = (int)fz_display_list_s_run(arg1,arg2,arg3,arg4); - if(result) + result = (PyObject *)fz_display_list_s_run(arg1,arg2,arg3,arg4); + if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); return NULL; } } - resultobj = SWIG_From_int((int)(result)); + resultobj = result; return resultobj; fail: return NULL; @@ -20856,7 +20832,7 @@ SWIGINTERN PyObject *_wrap_Tools_gen_id(PyObject *SWIGUNUSEDPARM(self), PyObject void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - int result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Tools_gen_id",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); @@ -20864,8 +20840,8 @@ SWIGINTERN PyObject *_wrap_Tools_gen_id(PyObject *SWIGUNUSEDPARM(self), PyObject SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_gen_id" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); - result = (int)Tools_gen_id(arg1); - resultobj = SWIG_From_int((int)(result)); + result = (PyObject *)Tools_gen_id(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -20875,14 +20851,14 @@ SWIGINTERN PyObject *_wrap_Tools_gen_id(PyObject *SWIGUNUSEDPARM(self), PyObject SWIGINTERN PyObject *_wrap_Tools_store_shrink(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; struct Tools *arg1 = (struct Tools *) 0 ; - unsigned int arg2 ; + int arg2 ; void *argp1 = 0 ; int res1 = 0 ; - unsigned int val2 ; + int val2 ; int ecode2 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; - size_t result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"OO:Tools_store_shrink",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); @@ -20890,13 +20866,13 @@ SWIGINTERN PyObject *_wrap_Tools_store_shrink(PyObject *SWIGUNUSEDPARM(self), Py SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_store_shrink" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); - ecode2 = SWIG_AsVal_unsigned_SS_int(obj1, &val2); + ecode2 = SWIG_AsVal_int(obj1, &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Tools_store_shrink" "', argument " "2"" of type '" "unsigned int""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Tools_store_shrink" "', argument " "2"" of type '" "int""'"); } - arg2 = (unsigned int)(val2); - result = Tools_store_shrink(arg1,arg2); - resultobj = SWIG_From_size_t((size_t)(result)); + arg2 = (int)(val2); + result = (PyObject *)Tools_store_shrink(arg1,arg2); + resultobj = result; return resultobj; fail: return NULL; @@ -20909,7 +20885,7 @@ SWIGINTERN PyObject *_wrap_Tools_store_size(PyObject *SWIGUNUSEDPARM(self), PyOb void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - size_t result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Tools_store_size",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); @@ -20917,8 +20893,8 @@ SWIGINTERN PyObject *_wrap_Tools_store_size(PyObject *SWIGUNUSEDPARM(self), PyOb SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_store_size" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); - result = Tools_store_size(arg1); - resultobj = SWIG_From_size_t((size_t)(result)); + result = (PyObject *)Tools_store_size(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -20931,7 +20907,7 @@ SWIGINTERN PyObject *_wrap_Tools_store_maxsize(PyObject *SWIGUNUSEDPARM(self), P void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - size_t result; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Tools_store_maxsize",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); @@ -20939,8 +20915,8 @@ SWIGINTERN PyObject *_wrap_Tools_store_maxsize(PyObject *SWIGUNUSEDPARM(self), P SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_store_maxsize" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); - result = Tools_store_maxsize(arg1); - resultobj = SWIG_From_size_t((size_t)(result)); + result = (PyObject *)Tools_store_maxsize(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -20990,13 +20966,63 @@ SWIGINTERN PyObject *_wrap_Tools_glyph_cache_empty(PyObject *SWIGUNUSEDPARM(self } +SWIGINTERN PyObject *_wrap_Tools__insert_contents(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + struct Tools *arg1 = (struct Tools *) 0 ; + struct fz_page_s *arg2 = (struct fz_page_s *) 0 ; + PyObject *arg3 = (PyObject *) 0 ; + int arg4 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + int val4 ; + int ecode4 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OOOO:Tools__insert_contents",&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools__insert_contents" "', argument " "1"" of type '" "struct Tools *""'"); + } + arg1 = (struct Tools *)(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_fz_page_s, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Tools__insert_contents" "', argument " "2"" of type '" "struct fz_page_s *""'"); + } + arg2 = (struct fz_page_s *)(argp2); + arg3 = obj2; + ecode4 = SWIG_AsVal_int(obj3, &val4); + if (!SWIG_IsOK(ecode4)) { + SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Tools__insert_contents" "', argument " "4"" of type '" "int""'"); + } + arg4 = (int)(val4); + { + result = (PyObject *)Tools__insert_contents(arg1,arg2,arg3,arg4); + if(!result) + { + PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); + return NULL; + } + } + resultobj = result; + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_Tools_fitz_stdout(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; struct Tools *arg1 = (struct Tools *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Tools_fitz_stdout",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); @@ -21004,8 +21030,8 @@ SWIGINTERN PyObject *_wrap_Tools_fitz_stdout(PyObject *SWIGUNUSEDPARM(self), PyO SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_fitz_stdout" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); - result = (char *)Tools_fitz_stdout(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); + result = (PyObject *)Tools_fitz_stdout(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -21039,7 +21065,7 @@ SWIGINTERN PyObject *_wrap_Tools_fitz_stderr(PyObject *SWIGUNUSEDPARM(self), PyO void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Tools_fitz_stderr",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); @@ -21047,8 +21073,8 @@ SWIGINTERN PyObject *_wrap_Tools_fitz_stderr(PyObject *SWIGUNUSEDPARM(self), PyO SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_fitz_stderr" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); - result = (char *)Tools_fitz_stderr(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); + result = (PyObject *)Tools_fitz_stderr(arg1); + resultobj = result; return resultobj; fail: return NULL; @@ -21082,7 +21108,7 @@ SWIGINTERN PyObject *_wrap_Tools_mupdf_version(PyObject *SWIGUNUSEDPARM(self), P void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - char *result = 0 ; + PyObject *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:Tools_mupdf_version",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); @@ -21090,15 +21116,99 @@ SWIGINTERN PyObject *_wrap_Tools_mupdf_version(PyObject *SWIGUNUSEDPARM(self), P SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_mupdf_version" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); - result = (char *)Tools_mupdf_version(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); + result = (PyObject *)Tools_mupdf_version(arg1); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Tools__transform_rect(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + struct Tools *arg1 = (struct Tools *) 0 ; + PyObject *arg2 = (PyObject *) 0 ; + PyObject *arg3 = (PyObject *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OOO:Tools__transform_rect",&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools__transform_rect" "', argument " "1"" of type '" "struct Tools *""'"); + } + arg1 = (struct Tools *)(argp1); + arg2 = obj1; + arg3 = obj2; + result = (PyObject *)Tools__transform_rect(arg1,arg2,arg3); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Tools__intersect_rect(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + struct Tools *arg1 = (struct Tools *) 0 ; + PyObject *arg2 = (PyObject *) 0 ; + PyObject *arg3 = (PyObject *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OOO:Tools__intersect_rect",&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools__intersect_rect" "', argument " "1"" of type '" "struct Tools *""'"); + } + arg1 = (struct Tools *)(argp1); + arg2 = obj1; + arg3 = obj2; + result = (PyObject *)Tools__intersect_rect(arg1,arg2,arg3); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Tools__include_point_in_rect(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + struct Tools *arg1 = (struct Tools *) 0 ; + PyObject *arg2 = (PyObject *) 0 ; + PyObject *arg3 = (PyObject *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OOO:Tools__include_point_in_rect",&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools__include_point_in_rect" "', argument " "1"" of type '" "struct Tools *""'"); + } + arg1 = (struct Tools *)(argp1); + arg2 = obj1; + arg3 = obj2; + result = (PyObject *)Tools__include_point_in_rect(arg1,arg2,arg3); + resultobj = result; return resultobj; fail: return NULL; } -SWIGINTERN PyObject *_wrap_Tools_transform_rect(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tools__union_rect(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; struct Tools *arg1 = (struct Tools *) 0 ; PyObject *arg2 = (PyObject *) 0 ; @@ -21110,15 +21220,15 @@ SWIGINTERN PyObject *_wrap_Tools_transform_rect(PyObject *SWIGUNUSEDPARM(self), PyObject * obj2 = 0 ; PyObject *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)"OOO:Tools_transform_rect",&obj0,&obj1,&obj2)) SWIG_fail; + if (!PyArg_ParseTuple(args,(char *)"OOO:Tools__union_rect",&obj0,&obj1,&obj2)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_transform_rect" "', argument " "1"" of type '" "struct Tools *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools__union_rect" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); arg2 = obj1; arg3 = obj2; - result = (PyObject *)Tools_transform_rect(arg1,arg2,arg3); + result = (PyObject *)Tools__union_rect(arg1,arg2,arg3); resultobj = result; return resultobj; fail: @@ -21126,7 +21236,7 @@ SWIGINTERN PyObject *_wrap_Tools_transform_rect(PyObject *SWIGUNUSEDPARM(self), } -SWIGINTERN PyObject *_wrap_Tools_invert_matrix(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tools__invert_matrix(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; struct Tools *arg1 = (struct Tools *) 0 ; PyObject *arg2 = (PyObject *) 0 ; @@ -21136,14 +21246,14 @@ SWIGINTERN PyObject *_wrap_Tools_invert_matrix(PyObject *SWIGUNUSEDPARM(self), P PyObject * obj1 = 0 ; PyObject *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)"OO:Tools_invert_matrix",&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTuple(args,(char *)"OO:Tools__invert_matrix",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Tools, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools_invert_matrix" "', argument " "1"" of type '" "struct Tools *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tools__invert_matrix" "', argument " "1"" of type '" "struct Tools *""'"); } arg1 = (struct Tools *)(argp1); arg2 = obj1; - result = (PyObject *)Tools_invert_matrix(arg1,arg2); + result = (PyObject *)Tools__invert_matrix(arg1,arg2); resultobj = result; return resultobj; fail: @@ -21207,22 +21317,23 @@ static PyMethodDef SwigMethods[] = { { (char *)"Document_embeddedFileGet", _wrap_Document_embeddedFileGet, METH_VARARGS, (char *)"Retrieve embedded file content by name or by number."}, { (char *)"Document_embeddedFileAdd", _wrap_Document_embeddedFileAdd, METH_VARARGS, (char *)"Embed a new file."}, { (char *)"Document_convertToPDF", _wrap_Document_convertToPDF, METH_VARARGS, (char *)"Convert document to PDF selecting page range and optional rotation. Output bytes object."}, - { (char *)"Document_pageCount", _wrap_Document_pageCount, METH_VARARGS, (char *)"Document_pageCount(self) -> int"}, + { (char *)"Document_pageCount", _wrap_Document_pageCount, METH_VARARGS, (char *)"Document_pageCount(self) -> PyObject *"}, { (char *)"Document__getMetadata", _wrap_Document__getMetadata, METH_VARARGS, (char *)"Document__getMetadata(self, key) -> char *"}, - { (char *)"Document_needsPass", _wrap_Document_needsPass, METH_VARARGS, (char *)"Document_needsPass(self) -> int"}, - { (char *)"Document_resolveLink", _wrap_Document_resolveLink, METH_VARARGS, (char *)"Document_resolveLink(self, uri=None) -> PyObject *"}, - { (char *)"Document_layout", _wrap_Document_layout, METH_VARARGS, (char *)"Document_layout(self, rect=None, width=0, height=0, fontsize=11) -> PyObject *"}, - { (char *)"Document_makeBookmark", _wrap_Document_makeBookmark, METH_VARARGS, (char *)"Document_makeBookmark(self, pno=0) -> PyObject *"}, - { (char *)"Document_findBookmark", _wrap_Document_findBookmark, METH_VARARGS, (char *)"Document_findBookmark(self, bookmark) -> int"}, + { (char *)"Document_needsPass", _wrap_Document_needsPass, METH_VARARGS, (char *)"Document_needsPass(self) -> PyObject *"}, + { (char *)"Document_resolveLink", _wrap_Document_resolveLink, METH_VARARGS, (char *)"Calculate internal link destination."}, + { (char *)"Document_layout", _wrap_Document_layout, METH_VARARGS, (char *)"Re-layout a reflowable document."}, + { (char *)"Document_makeBookmark", _wrap_Document_makeBookmark, METH_VARARGS, (char *)"Make page bookmark in a reflowable document."}, + { (char *)"Document_findBookmark", _wrap_Document_findBookmark, METH_VARARGS, (char *)"Find page number after layouting a document."}, { (char *)"Document_isReflowable", _wrap_Document_isReflowable, METH_VARARGS, (char *)"Document_isReflowable(self) -> PyObject *"}, - { (char *)"Document__deleteObject", _wrap_Document__deleteObject, METH_VARARGS, (char *)"Delete the object given by its xref"}, - { (char *)"Document__getPDFroot", _wrap_Document__getPDFroot, METH_VARARGS, (char *)"PDF catalog xref number"}, + { (char *)"Document__deleteObject", _wrap_Document__deleteObject, METH_VARARGS, (char *)"Delete an object given its xref."}, + { (char *)"Document__getPDFroot", _wrap_Document__getPDFroot, METH_VARARGS, (char *)"Get XREF number of PDF catalog."}, + { (char *)"Document__getPDFfileid", _wrap_Document__getPDFfileid, METH_VARARGS, (char *)"Return PDF file /ID strings (hexadecimal)."}, { (char *)"Document_isPDF", _wrap_Document_isPDF, METH_VARARGS, (char *)"Document_isPDF(self) -> PyObject *"}, { (char *)"Document__hasXrefStream", _wrap_Document__hasXrefStream, METH_VARARGS, (char *)"Document__hasXrefStream(self) -> PyObject *"}, { (char *)"Document__hasXrefOldStyle", _wrap_Document__hasXrefOldStyle, METH_VARARGS, (char *)"Document__hasXrefOldStyle(self) -> PyObject *"}, { (char *)"Document_isDirty", _wrap_Document_isDirty, METH_VARARGS, (char *)"Document_isDirty(self) -> PyObject *"}, - { (char *)"Document__getGCTXerrcode", _wrap_Document__getGCTXerrcode, METH_VARARGS, (char *)"Document__getGCTXerrcode(self) -> int"}, - { (char *)"Document__getGCTXerrmsg", _wrap_Document__getGCTXerrmsg, METH_VARARGS, (char *)"Document__getGCTXerrmsg(self) -> char const *"}, + { (char *)"Document__getGCTXerrcode", _wrap_Document__getGCTXerrcode, METH_VARARGS, (char *)"Retrieve last MuPDF error code."}, + { (char *)"Document__getGCTXerrmsg", _wrap_Document__getGCTXerrmsg, METH_VARARGS, (char *)"Retrieve last MuPDF error message."}, { (char *)"Document_authenticate", _wrap_Document_authenticate, METH_VARARGS, (char *)"Decrypt document with a password."}, { (char *)"Document_save", _wrap_Document_save, METH_VARARGS, (char *)"Document_save(self, filename, garbage=0, clean=0, deflate=0, incremental=0, ascii=0, expand=0, linear=0, pretty=0, decrypt=1) -> PyObject *"}, { (char *)"Document_write", _wrap_Document_write, METH_VARARGS, (char *)"Write document to a bytes object."}, @@ -21234,17 +21345,17 @@ static PyMethodDef SwigMethods[] = { { (char *)"Document__getPageObjNumber", _wrap_Document__getPageObjNumber, METH_VARARGS, (char *)"Document__getPageObjNumber(self, pno) -> PyObject *"}, { (char *)"Document__getPageInfo", _wrap_Document__getPageInfo, METH_VARARGS, (char *)"Show fonts or images used on a page."}, { (char *)"Document_extractFont", _wrap_Document_extractFont, METH_VARARGS, (char *)"Document_extractFont(self, xref=0, info_only=0) -> PyObject *"}, - { (char *)"Document_extractImage", _wrap_Document_extractImage, METH_VARARGS, (char *)"Extract image an xref points to."}, + { (char *)"Document_extractImage", _wrap_Document_extractImage, METH_VARARGS, (char *)"Extract image which 'xref' is pointing to."}, { (char *)"Document__delToC", _wrap_Document__delToC, METH_VARARGS, (char *)"Document__delToC(self) -> PyObject *"}, { (char *)"Document_isFormPDF", _wrap_Document_isFormPDF, METH_VARARGS, (char *)"Document_isFormPDF(self) -> PyObject *"}, { (char *)"Document_FormFonts", _wrap_Document_FormFonts, METH_VARARGS, (char *)"Document_FormFonts(self) -> PyObject *"}, { (char *)"Document__addFormFont", _wrap_Document__addFormFont, METH_VARARGS, (char *)"Document__addFormFont(self, name, font) -> PyObject *"}, - { (char *)"Document__getOLRootNumber", _wrap_Document__getOLRootNumber, METH_VARARGS, (char *)"Document__getOLRootNumber(self) -> int"}, - { (char *)"Document__getNewXref", _wrap_Document__getNewXref, METH_VARARGS, (char *)"Document__getNewXref(self) -> int"}, - { (char *)"Document__getXrefLength", _wrap_Document__getXrefLength, METH_VARARGS, (char *)"Document__getXrefLength(self) -> int"}, - { (char *)"Document__getXmlMetadataXref", _wrap_Document__getXmlMetadataXref, METH_VARARGS, (char *)"Document__getXmlMetadataXref(self) -> int"}, + { (char *)"Document__getOLRootNumber", _wrap_Document__getOLRootNumber, METH_VARARGS, (char *)"Document__getOLRootNumber(self) -> PyObject *"}, + { (char *)"Document__getNewXref", _wrap_Document__getNewXref, METH_VARARGS, (char *)"Document__getNewXref(self) -> PyObject *"}, + { (char *)"Document__getXrefLength", _wrap_Document__getXrefLength, METH_VARARGS, (char *)"Document__getXrefLength(self) -> PyObject *"}, + { (char *)"Document__getXmlMetadataXref", _wrap_Document__getXmlMetadataXref, METH_VARARGS, (char *)"Document__getXmlMetadataXref(self) -> PyObject *"}, { (char *)"Document__delXmlMetadata", _wrap_Document__delXmlMetadata, METH_VARARGS, (char *)"Document__delXmlMetadata(self) -> PyObject *"}, - { (char *)"Document__getObjectString", _wrap_Document__getObjectString, METH_VARARGS, (char *)"Document__getObjectString(self, xref) -> char const *"}, + { (char *)"Document__getXrefString", _wrap_Document__getXrefString, METH_VARARGS, (char *)"Document__getXrefString(self, xref) -> PyObject *"}, { (char *)"Document__getXrefStream", _wrap_Document__getXrefStream, METH_VARARGS, (char *)"Document__getXrefStream(self, xref) -> PyObject *"}, { (char *)"Document__updateObject", _wrap_Document__updateObject, METH_VARARGS, (char *)"Document__updateObject(self, xref, text, page=None) -> PyObject *"}, { (char *)"Document__updateStream", _wrap_Document__updateStream, METH_VARARGS, (char *)"Document__updateStream(self, xref=0, stream=None, new=0) -> PyObject *"}, @@ -21282,7 +21393,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Page__addAnnot_FromString", _wrap_Page__addAnnot_FromString, METH_VARARGS, (char *)"Page__addAnnot_FromString(self, linklist) -> PyObject *"}, { (char *)"Page__getLinkXrefs", _wrap_Page__getLinkXrefs, METH_VARARGS, (char *)"Page__getLinkXrefs(self) -> PyObject *"}, { (char *)"Page__cleanContents", _wrap_Page__cleanContents, METH_VARARGS, (char *)"Page__cleanContents(self) -> PyObject *"}, - { (char *)"Page__showPDFpage", _wrap_Page__showPDFpage, METH_VARARGS, (char *)"Page__showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> int"}, + { (char *)"Page__showPDFpage", _wrap_Page__showPDFpage, METH_VARARGS, (char *)"Page__showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *"}, { (char *)"Page_insertImage", _wrap_Page_insertImage, METH_VARARGS, (char *)"Insert a new image into a rectangle."}, { (char *)"Page_insertFont", _wrap_Page_insertFont, METH_VARARGS, (char *)"Page_insertFont(self, fontname=None, fontfile=None, fontbuffer=None, xref=0, set_simple=0, idx=0) -> PyObject *"}, { (char *)"Page__getContents", _wrap_Page__getContents, METH_VARARGS, (char *)"Page__getContents(self) -> PyObject *"}, @@ -21335,8 +21446,8 @@ static PyMethodDef SwigMethods[] = { { (char *)"Pixmap_swigregister", Pixmap_swigregister, METH_VARARGS, NULL}, { (char *)"delete_Colorspace", _wrap_delete_Colorspace, METH_VARARGS, (char *)"delete_Colorspace(self)"}, { (char *)"new_Colorspace", _wrap_new_Colorspace, METH_VARARGS, (char *)"new_Colorspace(type) -> Colorspace"}, - { (char *)"Colorspace_n", _wrap_Colorspace_n, METH_VARARGS, (char *)"Colorspace_n(self) -> int"}, - { (char *)"Colorspace__name", _wrap_Colorspace__name, METH_VARARGS, (char *)"Colorspace__name(self) -> char const *"}, + { (char *)"Colorspace_n", _wrap_Colorspace_n, METH_VARARGS, (char *)"Colorspace_n(self) -> PyObject *"}, + { (char *)"Colorspace__name", _wrap_Colorspace__name, METH_VARARGS, (char *)"Colorspace__name(self) -> PyObject *"}, { (char *)"Colorspace_swigregister", Colorspace_swigregister, METH_VARARGS, NULL}, { (char *)"new_Device", _wrap_new_Device, METH_VARARGS, (char *)"\n" "Device(pm, clip)\n" @@ -21350,13 +21461,13 @@ static PyMethodDef SwigMethods[] = { { (char *)"Outline_next_get", _wrap_Outline_next_get, METH_VARARGS, (char *)"Outline_next_get(self) -> Outline"}, { (char *)"Outline_down_get", _wrap_Outline_down_get, METH_VARARGS, (char *)"Outline_down_get(self) -> Outline"}, { (char *)"Outline_is_open_get", _wrap_Outline_is_open_get, METH_VARARGS, (char *)"Outline_is_open_get(self) -> int"}, - { (char *)"Outline_uri", _wrap_Outline_uri, METH_VARARGS, (char *)"Outline_uri(self) -> char *"}, - { (char *)"Outline_isExternal", _wrap_Outline_isExternal, METH_VARARGS, (char *)"Outline_isExternal(self) -> int"}, + { (char *)"Outline_uri", _wrap_Outline_uri, METH_VARARGS, (char *)"Outline_uri(self) -> PyObject *"}, + { (char *)"Outline_isExternal", _wrap_Outline_isExternal, METH_VARARGS, (char *)"Outline_isExternal(self) -> PyObject *"}, { (char *)"delete_Outline", _wrap_delete_Outline, METH_VARARGS, (char *)"delete_Outline(self)"}, { (char *)"Outline_swigregister", Outline_swigregister, METH_VARARGS, NULL}, { (char *)"delete_Annot", _wrap_delete_Annot, METH_VARARGS, (char *)"delete_Annot(self)"}, { (char *)"Annot_rect", _wrap_Annot_rect, METH_VARARGS, (char *)"Rectangle containing the annot"}, - { (char *)"Annot_xref", _wrap_Annot_xref, METH_VARARGS, (char *)"Annot_xref(self) -> int"}, + { (char *)"Annot_xref", _wrap_Annot_xref, METH_VARARGS, (char *)"Annot_xref(self) -> PyObject *"}, { (char *)"Annot__getAP", _wrap_Annot__getAP, METH_VARARGS, (char *)"Get contents source of a PDF annot"}, { (char *)"Annot__setAP", _wrap_Annot__setAP, METH_VARARGS, (char *)"Update contents source of a PDF annot"}, { (char *)"Annot_setRect", _wrap_Annot_setRect, METH_VARARGS, (char *)"Annot_setRect(self, rect)"}, @@ -21370,7 +21481,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Annot_lineEnds", _wrap_Annot_lineEnds, METH_VARARGS, (char *)"Annot_lineEnds(self) -> PyObject *"}, { (char *)"Annot_setLineEnds", _wrap_Annot_setLineEnds, METH_VARARGS, (char *)"Annot_setLineEnds(self, start, end)"}, { (char *)"Annot_type", _wrap_Annot_type, METH_VARARGS, (char *)"Annot_type(self) -> PyObject *"}, - { (char *)"Annot_opacity", _wrap_Annot_opacity, METH_VARARGS, (char *)"Annot_opacity(self) -> float"}, + { (char *)"Annot_opacity", _wrap_Annot_opacity, METH_VARARGS, (char *)"Annot_opacity(self) -> PyObject *"}, { (char *)"Annot_setOpacity", _wrap_Annot_setOpacity, METH_VARARGS, (char *)"Annot_setOpacity(self, opacity)"}, { (char *)"Annot_widget_type", _wrap_Annot_widget_type, METH_VARARGS, (char *)"Annot_widget_type(self) -> PyObject *"}, { (char *)"Annot_widget_value", _wrap_Annot_widget_value, METH_VARARGS, (char *)"Annot_widget_value(self) -> PyObject *"}, @@ -21396,14 +21507,14 @@ static PyMethodDef SwigMethods[] = { { (char *)"Link__setBorder", _wrap_Link__setBorder, METH_VARARGS, (char *)"Link__setBorder(self, border, doc, xref) -> PyObject *"}, { (char *)"Link__colors", _wrap_Link__colors, METH_VARARGS, (char *)"Link__colors(self, doc, xref) -> PyObject *"}, { (char *)"Link__setColors", _wrap_Link__setColors, METH_VARARGS, (char *)"Link__setColors(self, colors, doc, xref) -> PyObject *"}, - { (char *)"Link_uri", _wrap_Link_uri, METH_VARARGS, (char *)"Link_uri(self) -> char *"}, - { (char *)"Link_isExternal", _wrap_Link_isExternal, METH_VARARGS, (char *)"Link_isExternal(self) -> int"}, + { (char *)"Link_uri", _wrap_Link_uri, METH_VARARGS, (char *)"Link_uri(self) -> PyObject *"}, + { (char *)"Link_isExternal", _wrap_Link_isExternal, METH_VARARGS, (char *)"Link_isExternal(self) -> PyObject *"}, { (char *)"Link_rect", _wrap_Link_rect, METH_VARARGS, (char *)"Link_rect(self) -> PyObject *"}, { (char *)"Link_next", _wrap_Link_next, METH_VARARGS, (char *)"Link_next(self) -> Link"}, { (char *)"Link_swigregister", Link_swigregister, METH_VARARGS, NULL}, { (char *)"delete_DisplayList", _wrap_delete_DisplayList, METH_VARARGS, (char *)"delete_DisplayList(self)"}, { (char *)"new_DisplayList", _wrap_new_DisplayList, METH_VARARGS, (char *)"new_DisplayList(mediabox) -> DisplayList"}, - { (char *)"DisplayList_run", _wrap_DisplayList_run, METH_VARARGS, (char *)"DisplayList_run(self, dw, m, area) -> int"}, + { (char *)"DisplayList_run", _wrap_DisplayList_run, METH_VARARGS, (char *)"DisplayList_run(self, dw, m, area) -> PyObject *"}, { (char *)"DisplayList_rect", _wrap_DisplayList_rect, METH_VARARGS, (char *)"DisplayList_rect(self) -> PyObject *"}, { (char *)"DisplayList_getPixmap", _wrap_DisplayList_getPixmap, METH_VARARGS, (char *)"DisplayList_getPixmap(self, matrix=None, colorspace=None, alpha=0, clip=None) -> Pixmap"}, { (char *)"DisplayList_getTextPage", _wrap_DisplayList_getTextPage, METH_VARARGS, (char *)"DisplayList_getTextPage(self, flags=3) -> TextPage"}, @@ -21418,19 +21529,23 @@ static PyMethodDef SwigMethods[] = { { (char *)"delete_Graftmap", _wrap_delete_Graftmap, METH_VARARGS, (char *)"delete_Graftmap(self)"}, { (char *)"new_Graftmap", _wrap_new_Graftmap, METH_VARARGS, (char *)"new_Graftmap(doc) -> Graftmap"}, { (char *)"Graftmap_swigregister", Graftmap_swigregister, METH_VARARGS, NULL}, - { (char *)"Tools_gen_id", _wrap_Tools_gen_id, METH_VARARGS, (char *)"Return a unique integer."}, + { (char *)"Tools_gen_id", _wrap_Tools_gen_id, METH_VARARGS, (char *)"Return a unique positive integer."}, { (char *)"Tools_store_shrink", _wrap_Tools_store_shrink, METH_VARARGS, (char *)"Free 'percent' of current store size."}, { (char *)"Tools_store_size", _wrap_Tools_store_size, METH_VARARGS, (char *)"Current store size."}, { (char *)"Tools_store_maxsize", _wrap_Tools_store_maxsize, METH_VARARGS, (char *)"Maximum store size."}, { (char *)"Tools_fitz_config", _wrap_Tools_fitz_config, METH_VARARGS, (char *)"Show configuration data."}, { (char *)"Tools_glyph_cache_empty", _wrap_Tools_glyph_cache_empty, METH_VARARGS, (char *)"Empty the glyph cache."}, - { (char *)"Tools_fitz_stdout", _wrap_Tools_fitz_stdout, METH_VARARGS, (char *)"Tools_fitz_stdout(self) -> char *"}, - { (char *)"Tools_fitz_stdout_reset", _wrap_Tools_fitz_stdout_reset, METH_VARARGS, (char *)"Tools_fitz_stdout_reset(self)"}, - { (char *)"Tools_fitz_stderr", _wrap_Tools_fitz_stderr, METH_VARARGS, (char *)"Tools_fitz_stderr(self) -> char *"}, - { (char *)"Tools_fitz_stderr_reset", _wrap_Tools_fitz_stderr_reset, METH_VARARGS, (char *)"Tools_fitz_stderr_reset(self)"}, - { (char *)"Tools_mupdf_version", _wrap_Tools_mupdf_version, METH_VARARGS, (char *)"Tools_mupdf_version(self) -> char *"}, - { (char *)"Tools_transform_rect", _wrap_Tools_transform_rect, METH_VARARGS, (char *)"Tools_transform_rect(self, rect, matrix) -> PyObject *"}, - { (char *)"Tools_invert_matrix", _wrap_Tools_invert_matrix, METH_VARARGS, (char *)"Tools_invert_matrix(self, matrix) -> PyObject *"}, + { (char *)"Tools__insert_contents", _wrap_Tools__insert_contents, METH_VARARGS, (char *)"Tools__insert_contents(self, fzpage, newcont, overlay) -> PyObject *"}, + { (char *)"Tools_fitz_stdout", _wrap_Tools_fitz_stdout, METH_VARARGS, (char *)"Tools_fitz_stdout(self) -> PyObject *"}, + { (char *)"Tools_fitz_stdout_reset", _wrap_Tools_fitz_stdout_reset, METH_VARARGS, (char *)"Empty fitz output log."}, + { (char *)"Tools_fitz_stderr", _wrap_Tools_fitz_stderr, METH_VARARGS, (char *)"Tools_fitz_stderr(self) -> PyObject *"}, + { (char *)"Tools_fitz_stderr_reset", _wrap_Tools_fitz_stderr_reset, METH_VARARGS, (char *)"Empty fitz error log."}, + { (char *)"Tools_mupdf_version", _wrap_Tools_mupdf_version, METH_VARARGS, (char *)"Return compiled MuPDF version."}, + { (char *)"Tools__transform_rect", _wrap_Tools__transform_rect, METH_VARARGS, (char *)"Transform rectangle with matrix."}, + { (char *)"Tools__intersect_rect", _wrap_Tools__intersect_rect, METH_VARARGS, (char *)"Intersect two rectangles."}, + { (char *)"Tools__include_point_in_rect", _wrap_Tools__include_point_in_rect, METH_VARARGS, (char *)"Include point in a rect."}, + { (char *)"Tools__union_rect", _wrap_Tools__union_rect, METH_VARARGS, (char *)"Replace r1 with smallest rect containing both."}, + { (char *)"Tools__invert_matrix", _wrap_Tools__invert_matrix, METH_VARARGS, (char *)"Invert a matrix."}, { (char *)"new_Tools", _wrap_new_Tools, METH_VARARGS, (char *)"new_Tools() -> Tools"}, { (char *)"delete_Tools", _wrap_delete_Tools, METH_VARARGS, (char *)"delete_Tools(self)"}, { (char *)"Tools_swigregister", Tools_swigregister, METH_VARARGS, NULL}, diff --git a/fitz/helper-geo-py.i b/fitz/helper-geo-py.i index fbf135a8c..5908ae63e 100644 --- a/fitz/helper-geo-py.i +++ b/fitz/helper-geo-py.i @@ -48,16 +48,17 @@ class Matrix(): current one. Else return 1 and do nothing. """ if src is None: - src = self - dst = TOOLS.invert_matrix(src) - if min(dst) >= max(dst): + dst = TOOLS._invert_matrix(self) + else: + dst = TOOLS._invert_matrix(src) + if dst[0] == 1: return 1 - self.a = dst[0] - self.b = dst[1] - self.c = dst[2] - self.d = dst[3] - self.e = dst[4] - self.f = dst[5] + self.a = dst[1][0] + self.b = dst[1][1] + self.c = dst[1][2] + self.d = dst[1][3] + self.e = dst[1][4] + self.f = dst[1][5] return 0 def preTranslate(self, tx, ty): @@ -184,9 +185,9 @@ class Matrix(): if hasattr(m, "__float__"): return Matrix(self.a * 1./m, self.b * 1./m, self.c * 1./m, self.d * 1./m, self.e * 1./m, self.f * 1./m) - m1 = TOOLS.invert_matrix(m) - if min(m1) >= max(m1): - raise ZeroDivisionError("op2 is not invertible") + m1 = TOOLS._invert_matrix(m)[1] + if not m1: + raise ZeroDivisionError("matrix not invertible") return self.concat(self, m1) __div__ = __truediv__ @@ -211,10 +212,10 @@ class Matrix(): return Matrix(-self.a, -self.b, -self.c, -self.d, -self.e, -self.f) def __bool__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __nonzero__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __eq__(self, m): if not hasattr(m, "__len__"): @@ -372,10 +373,10 @@ class Point(): return Point(-self.x, -self.y) def __bool__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __nonzero__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __eq__(self, p): if not hasattr(p, "__len__"): @@ -404,9 +405,9 @@ class Point(): def __truediv__(self, m): if hasattr(m, "__float__"): return Point(self.x * 1./m, self.y * 1./m) - m1 = TOOLS.invert_matrix(m) - if min(m1) >= max(m1): - raise ZeroDivisionError("op2 is not invertible") + m1 = TOOLS._invert_matrix(m)[1] + if not m1: + raise ZeroDivisionError("matrix not invertible") p = Point(self) return p.transform(m1) @@ -508,9 +509,8 @@ class Rect(): return Quad(self.tl, self.tr, self.bl, self.br) def round(self): - r = Rect(self).normalize() - ir = IRect(math.floor(r.x0), math.floor(r.y0), math.ceil(r.x1), math.ceil(r.y1)) - return ir + return IRect(min(self.x0, self.x1), min(self.y0, self.y1), + max(self.x0, self.x1), max(self.y0, self.y1)) irect = property(round) @@ -519,46 +519,31 @@ class Rect(): def includePoint(self, p): """Extend rectangle to include point p.""" - x0 = min(self.x0, self.x1, p[0]) - x1 = max(self.x0, self.x1, p[0]) - y0 = min(self.y0, self.y1, p[1]) - y1 = max(self.y0, self.y1, p[1]) - self.x0 = x0 - self.y0 = y0 - self.x1 = x1 - self.y1 = y1 + r0 = TOOLS._include_point_in_rect(self, p); + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self def includeRect(self, r): """Extend rectangle to include rectangle r.""" - x0 = min(self.x0, self.x1, r[0], r[2]) - x1 = max(self.x0, self.x1, r[0], r[2]) - y0 = min(self.y0, self.y1, r[1], r[3]) - y1 = max(self.y0, self.y1, r[1], r[3]) - self.x0 = x0 - self.y0 = y0 - self.x1 = x1 - self.y1 = y1 + r0 = TOOLS._union_rect(self, r) + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self def intersect(self, r): - """Restrict rectangle to common area with rectangle r.""" - if self.isEmpty: return Rect() - r1 = Rect(r) - if r1.isEmpty: return Rect() - if r1.isInfinite: return self - if self.isInfinite: return r1 - x0 = max(self.x0, r1.x0) - x1 = min(self.x1, r1.x1) - y0 = max(self.y0, r1.y0) - y1 = min(self.y1, r1.y1) - if x1 < x0 or y1 < y0: - self = Rect() - else: - self = Rect(x0, y0, x1, y1) + """Restrict self to common area with rectangle r.""" + r0 = TOOLS._intersect_rect(self, r); + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self - def __getitem__(self, i): return (self.x0, self.y0, self.x1, self.y1)[i] @@ -584,10 +569,10 @@ class Rect(): return Rect(-self.x0, -self.y0, -self.x1, -self.y1) def __bool__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __nonzero__(self): - return max(self) > 0 or min(self) < 0 + return not (max(self) == min(self) == 0) def __eq__(self, p): if not hasattr(p, "__len__"): @@ -613,7 +598,11 @@ class Rect(): def transform(self, m): """Replace rectangle with its transformation by matrix m.""" - self = Rect(TOOLS.transform_rect(self, m)) + r0 = TOOLS._transform_rect(self, m) + self.x0 = r0[0] + self.y0 = r0[1] + self.x1 = r0[2] + self.y1 = r0[3] return self def __mul__(self, m): @@ -626,9 +615,9 @@ class Rect(): def __truediv__(self, m): if hasattr(m, "__float__"): return Rect(self.x0 * 1./m, self.y0 * 1./m, self.x1 * 1./m, self.y1 * 1./m) - im = TOOLS.invert_matrix(m) - if min(im) >= max(im): - raise ZeroDivisionError("op2 is not invertible") + im = TOOLS._invert_matrix(m)[1] + if not im: + raise ZeroDivisionError("matrix not invertible") r = Rect(self) r = r.transform(im) return r @@ -691,10 +680,10 @@ class IRect(Rect): """IRect() - all zeros\nIRect(x0, y0, x1, y1)\nIRect(Rect or IRect) - new copy\nIRect(sequence) - from 'sequence'""" def __init__(self, *args): Rect.__init__(self, *args) - self.x0 = math.floor(self.x0) - self.y0 = math.floor(self.y0) - self.x1 = math.ceil(self.x1) - self.y1 = math.ceil(self.y1) + self.x0 = math.floor(self.x0 + 0.001) + self.y0 = math.floor(self.y0 + 0.001) + self.x1 = math.ceil(self.x1 - 0.001) + self.y1 = math.ceil(self.y1 - 0.001) return None @property @@ -788,6 +777,9 @@ class Quad(): @property def isRectangular(self): + """Check if quad is rectangular. + """ + # if any two of the 4 corners are equal return false upper = (self.ur - self.ul).unit if not bool(upper): return False @@ -801,13 +793,19 @@ class Quad(): if not bool(lower): return False eps = 1e-5 - + # we now have 4 sides of length 1. If 3 of them have 90 deg angles, + # then it is a rectangle -- we check via scalar product == 0 return abs(sum(map(lambda x,y: x*y, upper, right))) <= eps and \ abs(sum(map(lambda x,y: x*y, upper, left))) <= eps and \ abs(sum(map(lambda x,y: x*y, left, lower))) <= eps @property def isEmpty(self): + """Check if quad is empty retangle. If rectangular, we are done (not empty). + But all 4 points may still be on one line. We check this out here. + In that case all 3 lines connecting corners to ul will have same angle with + x-axis. + """ if self.isRectangular: return False eps = 1e-5 @@ -881,13 +879,13 @@ class Quad(): return r def __truediv__(self, m): - r = Quad(self) if hasattr(m, "__float__"): im = 1. / m else: - im = TOOLS.invert_matrix(m) - if min(im) >= max(im): - raise ZeroDivisionError("op2 is not invertible") + im = TOOLS._invert_matrix(m)[1] + if not im: + raise ZeroDivisionError("matrix not invertible") + r = Quad(self) r = r.transform(im) return r diff --git a/fitz/helper-xobject.i b/fitz/helper-xobject.i index 833415a75..dad010344 100644 --- a/fitz/helper-xobject.i +++ b/fitz/helper-xobject.i @@ -79,22 +79,27 @@ pdf_obj *JM_xobject_from_page(fz_context *ctx, pdf_document *pdfout, pdf_documen //----------------------------------------------------------------------------- // Insert a buffer as a new separate /Contents object of a page. +// 1. Create a new stream object from buffer 'newcont' +// 2. If /Contents already is an array, then just prepend or append this object +// 3. Create new array and put old content obj and new obj into it //----------------------------------------------------------------------------- -void JM_insert_contents(fz_context *ctx, pdf_document *pdf, +int JM_insert_contents(fz_context *ctx, pdf_document *pdf, pdf_obj *pageref, fz_buffer *newcont, int overlay) { + int xref = 0; fz_try(ctx) { pdf_obj *contents = pdf_dict_get(ctx, pageref, PDF_NAME(Contents)); pdf_obj *newconts = pdf_add_stream(ctx, pdf, newcont, NULL, 0); + xref = pdf_to_num(ctx, newconts); if (pdf_is_array(ctx, contents)) { - if (overlay) + if (overlay) // append new object pdf_array_push_drop(ctx, contents, newconts); - else + else // prepend new object pdf_array_insert_drop(ctx, contents, newconts, 0); } - else + else // make new array { pdf_obj *carr = pdf_new_array(ctx, pdf, 2); if (overlay) @@ -111,7 +116,7 @@ void JM_insert_contents(fz_context *ctx, pdf_document *pdf, } } fz_catch(ctx) fz_rethrow(ctx); - return; + return xref; } /*----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/fitz/utils.py b/fitz/utils.py index d74bc206d..e4dce4bb3 100644 --- a/fitz/utils.py +++ b/fitz/utils.py @@ -1759,6 +1759,8 @@ def updateRect(self, x): def drawLine(self, p1, p2): """Draw a line between two points. """ + p1 = Point(p1) + p2 = Point(p2) if not (self.lastPoint == p1): self.contents += "%g %g m\n" % (p1.x + self.x, self.height - p1.y - self.y) @@ -1789,6 +1791,10 @@ def drawPolyline(self, points): def drawBezier(self, p1, p2, p3, p4): """Draw a standard cubic Bezier curve. """ + p1 = Point(p1) + p2 = Point(p2) + p3 = Point(p3) + p4 = Point(p4) if not (self.lastPoint == Point(p1)): self.contents += "%g %g m\n" % (p1[0] + self.x, self.height - p1[1] - self.y) @@ -1802,14 +1808,13 @@ def drawBezier(self, p1, p2, p3, p4): self.updateRect(p2) self.updateRect(p3) self.updateRect(p4) - self.lastPoint = Point(p4) + self.lastPoint = p4 return self.lastPoint def drawOval(self, rect): """Draw an ellipse inside a rectangle. """ - if type(rect) is not Rect: - rect = Rect(rect) + rect = Rect(rect) if rect.isEmpty or rect.isInfinite: raise ValueError("rectangle must be finite and not empty") mt = rect.tl + (rect.tr - rect.tl)*0.5 @@ -1831,8 +1836,7 @@ def drawCircle(self, center, radius): """Draw a circle given its center and radius. """ assert radius > 1e-5, "radius must be postive" - if type(center) is not Point: - center = Point(center) + center = Point(center) p1 = center - (radius, 0) return self.drawSector(center, p1, 360, fullSector = False) @@ -1840,9 +1844,9 @@ def drawCurve(self, p1, p2, p3): """Draw a curve between points using one control point. """ kappa = 0.55228474983 - if type(p1) is not Point: p1 = Point(p1) - if type(p2) is not Point: p2 = Point(p2) - if type(p3) is not Point: p3 = Point(p3) + p1 = Point(p1) + p2 = Point(p2) + p3 = Point(p3) k1 = p1 + (p2 - p1) * kappa k2 = p3 + (p2 - p3) * kappa return self.drawBezier(p1, k1, k2, p3) @@ -1850,8 +1854,8 @@ def drawCurve(self, p1, p2, p3): def drawSector(self, center, point, beta, fullSector = True): """Draw a circle sector. """ - if type(center) is not Point: center = Point(center) - if type(point) is not Point: point = Point(point) + center = Point(center) + point = Point(point) h = self.height l3 = "%g %g m\n" l4 = "%g %g %g %g %g %g c\n" @@ -2415,17 +2419,12 @@ def commit(self, overlay = True): if str is not bytes: # bytes object needed in Python 3 self.totalcont = bytes(self.totalcont, "utf-8") - - if overlay: # last one if foreground - xref = self.page._getContents()[-1] - cont = self.doc._getXrefStream(xref) - cont += self.totalcont # append our stuff - else: # first one if background - xref = self.page._getContents()[0] - cont = self.doc._getXrefStream(xref) - cont = self.totalcont + cont # prepend our stuff - - self.doc._updateStream(xref, cont) # replace the PDF stream + + # make /Contents object with dummy stream + xref = TOOLS._insert_contents(self.page, b" ", overlay) + # update it with potential compression + self.doc._updateStream(xref, self.totalcont) + self.lastPoint = None # clean up ... self.rect = None # self.contents = "" # for possible ... diff --git a/fitz/version.i b/fitz/version.i index 8b6aafef5..2e8881363 100644 --- a/fitz/version.i +++ b/fitz/version.i @@ -1,6 +1,6 @@ %pythoncode %{ VersionFitz = "1.14.0" VersionBind = "1.14.2" -VersionDate = "2018-11-20 06:27:22" -version = (VersionBind, VersionFitz, "20181120062722") +VersionDate = "2018-11-25 10:19:28" +version = (VersionBind, VersionFitz, "20181125101928") %} \ No newline at end of file From bffaabb21725883f1114f52ccdcf4f1029c950a9 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Thu, 29 Nov 2018 07:48:51 -0400 Subject: [PATCH 2/4] upload v1.14.3 --- README.md | 4 +- fitz/fitz.i | 255 +++++++++++++++++------------ fitz/fitz.py | 71 ++++++-- fitz/fitz_wrap.c | 377 +++++++++++++++++++++++++++---------------- fitz/helper-geo-py.i | 8 + fitz/helper-python.i | 20 +++ fitz/utils.py | 21 +-- fitz/version.i | 6 +- setup.py | 2 +- 9 files changed, 491 insertions(+), 273 deletions(-) diff --git a/README.md b/README.md index c601d5e89..e0b959d78 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PyMuPDF 1.14.2 +# PyMuPDF 1.14.3 ![logo](https://github.com/rk700/PyMuPDF/blob/master/demo/pymupdf.jpg) @@ -14,7 +14,7 @@ On **[PyPI](https://pypi.org/project/PyMuPDF)** since August 2016: [![](https:// # Introduction -This is **version 1.14.2 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.14.x](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer". +This is **version 1.14.3 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.14.x](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer". 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. diff --git a/fitz/fitz.i b/fitz/fitz.i index f64a9128d..f4e13f810 100644 --- a/fitz/fitz.i +++ b/fitz/fitz.i @@ -1166,7 +1166,8 @@ if links: FITZEXCEPTION(_getCharWidths, !result) CLOSECHECK(_getCharWidths) %feature("autodoc","Return list of glyphs and glyph widths of a font.") _getCharWidths; - PyObject *_getCharWidths(int xref, int limit, int idx = 0) + PyObject *_getCharWidths(int xref, char *bfname, char *ext, + int ordering, int limit, int idx = 0) { pdf_document *pdf = pdf_specifics(gctx, $self); PyObject *wlist = NULL; @@ -1174,49 +1175,45 @@ if links: mylimit = limit; if (mylimit < 256) mylimit = 256; int cwlen = 0; + int lang = 0; const char *data; - int size; - fz_font *font = NULL; + int size, index; + fz_font *font = NULL, *fb_font= NULL; fz_buffer *buf = NULL; - pdf_obj *basefont = NULL; - const char *bfname = NULL; + fz_try(gctx) { assert_PDF(pdf); - if (xref < 1) THROWMSG("xref must at least 1"); - pdf_obj *o = pdf_load_object(gctx, pdf, xref); - if (pdf_is_dict(gctx, o)) + if (ordering >= 0) { - basefont = pdf_dict_get(gctx, o, PDF_NAME(BaseFont)); - if (pdf_is_name(gctx, basefont)) - { - bfname = (char *) pdf_to_name(gctx, basefont); - data = fz_lookup_base14_font(gctx, bfname, &size); - if (data) - { - font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); - } - else - { - buf = fontbuffer(gctx, pdf, xref); - if (!buf) THROWMSG("xref is not a supported font"); - font = fz_new_font_from_buffer(gctx, NULL, buf, idx, 0); - } - } + data = fz_lookup_cjk_font(gctx, ordering, &size, &index); + font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); + goto weiter; } - else + data = fz_lookup_base14_font(gctx, bfname, &size); + if (data) { - buf = fontbuffer(gctx, pdf, xref); - if (!buf) THROWMSG("xref is not a supported font"); - font = fz_new_font_from_buffer(gctx, NULL, buf, idx, 0); + font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); + goto weiter; } + buf = fontbuffer(gctx, pdf, xref); + if (!buf) THROWMSG("xref is not a supported font"); + font = fz_new_font_from_buffer(gctx, NULL, buf, idx, 0); + + weiter:; wlist = PyList_New(0); + float adv; for (i = 0; i < mylimit; i++) { glyph = fz_encode_character(gctx, font, i); + adv = fz_advance_glyph(gctx, font, glyph, 0); + if (ordering >= 0) + glyph = i; + + if (glyph > 0) { - PyList_Append(wlist, Py_BuildValue("(i, f)", glyph, fz_advance_glyph(gctx, font, glyph, 0))); + PyList_Append(wlist, Py_BuildValue("(i, f)", glyph, adv)); } else { @@ -3163,106 +3160,160 @@ fannot._erase() //--------------------------------------------------------------------- // insert font //--------------------------------------------------------------------- - FITZEXCEPTION(insertFont, !result) - %pythonprepend insertFont %{ - if not self.parent: - raise ValueError("orphaned object: parent is None") + %pythoncode +%{ +def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, + set_simple=False, idx=0, wmode=0, style=0, encoding=0): + if not self.parent: + raise ValueError("orphaned object: parent is None") + f = CheckFont(self, fontname) + if f is not None: # drop out if fontname already in page list + return f[0] + bfname = "" + + if not fontname: + fontname = "helv" + + if fontname.lower() in Base14_fontdict.keys(): + bfname = Base14_fontdict[fontname.lower()] + + serif = 0 + CJK_number = -1 + CJK_list_n = ["china-t", "china-s", "japan", "korea"] + CJK_list_s = ["china-ts", "china-ss", "japan-s", "korea-s"] + if fontname in CJK_list_n: + CJK_number = CJK_list.index(fontname) + serif = 0 + + if fontname in CJK_list_s: + CJK_number = CJK_list_s.index(fontname) + serif = 1 + + val = self._insertFont(fontname, bfname, fontfile, fontbuffer, set_simple, idx, + wmode, style, serif, encoding, CJK_number) + + if val: + xref = val[0] f = CheckFont(self, fontname) - if f is not None: # drop out if fontname already in page list - return f[0] - if not fontname: - fontname = "Helvetica" - if xref > 0: - _, _, _, fontbuffer = self.parent.extractFont(xref) - if not fontbuffer: - raise ValueError("xref is no valid font") - %} - %pythonappend insertFont %{ - if val: - xref = val[0] - f = CheckFont(self, fontname) - if f is not None: - val[1]["type"] = f[2] # put /Subtype in font info - val[1]["glyphs"] = None - doc = self.parent # now add to document font info - fi = CheckFontInfo(doc, xref) - if fi is None: # look if we are already present - doc.FontInfos.append(val) # no: add me to document object - return xref - %} - PyObject *insertFont(const char *fontname = NULL, const char *fontfile = NULL, PyObject *fontbuffer = NULL, int xref = 0, int set_simple = 0, int idx = 0) + if f is not None: + val[1]["type"] = f[2] # put /Subtype in font info + val[1]["glyphs"] = None + doc = self.parent # now add to document font info + fi = CheckFontInfo(doc, xref) + if fi is None: # look if we are already present + doc.FontInfos.append(val) # no: add me to document object + return xref +%} + + FITZEXCEPTION(_insertFont, !result) + PyObject *_insertFont(const char *fontname, const char *bfname, + const char *fontfile, + PyObject *fontbuffer, + int set_simple, int idx, + int wmode, int style, int serif, + int encoding, int ordering) { pdf_page *page = pdf_page_from_fz_page(gctx, $self); pdf_document *pdf; pdf_obj *resources, *fonts, *font_obj; fz_font *font; const char *data = NULL; - int size, ixref = 0; - PyObject *info; + int size, ixref = 0, index = 0, simple = 0; + PyObject *info, *value; + PyObject *exto = NULL; fz_try(gctx) { assert_PDF(page); pdf = page->doc; - // get objects "Resources", "Resources/Font" + // get the objects /Resources, /Resources/Font resources = pdf_dict_get(gctx, page->obj, PDF_NAME(Resources)); fonts = pdf_dict_get(gctx, resources, PDF_NAME(Font)); - int simple = 0; if (!fonts) // page has no fonts yet - fonts = pdf_add_object_drop(gctx, pdf, pdf_new_dict(gctx, pdf, 1)); - - data = fz_lookup_base14_font(gctx, fontname, &size); - if (data) // base 14 font found { - font = fz_new_font_from_memory(gctx, fontname, data, size, 0, 0); - font_obj = pdf_add_simple_font(gctx, pdf, font, PDF_SIMPLE_ENCODING_LATIN); - simple = 1; + fonts = pdf_new_dict(gctx, pdf, 10); + pdf_dict_put_drop(gctx, resources, PDF_NAME(Font), fonts); } - else + + //------------------------------------------------------------- + // check for CJK font + //------------------------------------------------------------- + if (ordering > -1) { - if (!fontfile && !fontbuffer) THROWMSG("unknown PDF Base 14 font"); - if (fontfile) + data = fz_lookup_cjk_font(gctx, ordering, &size, &index); + if (data) { - font = fz_new_font_from_file(gctx, NULL, fontfile, idx, 0); - } - else - { - if (!PyBytes_Check(fontbuffer)) THROWMSG("fontbuffer must be bytes"); - data = PyBytes_AsString(fontbuffer); - size = PyBytes_Size(fontbuffer); - font = fz_new_font_from_memory(gctx, NULL, data, size, idx, 0); - } - if (set_simple == 0) - { - font_obj = pdf_add_cid_font(gctx, pdf, font); + font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); + font_obj = pdf_add_cjk_font(gctx, pdf, font, ordering, wmode, serif); + exto = Py_BuildValue("s", "n/a"); simple = 0; - } - else - { - font_obj = pdf_add_simple_font(gctx, pdf, font, PDF_SIMPLE_ENCODING_LATIN); - simple = 2; + goto weiter; } } - ixref = pdf_to_num(gctx, font_obj); - PyObject *name = PyString_FromString(fz_font_name(gctx, font)); - PyObject *exto; - if (simple != 1) - exto = PyString_FromString(fontextension(gctx, pdf, ixref)); + + //------------------------------------------------------------- + // check for PDF Base-14 font + //------------------------------------------------------------- + data = fz_lookup_base14_font(gctx, bfname, &size); + if (data) + { + font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); + font_obj = pdf_add_simple_font(gctx, pdf, font, encoding); + exto = Py_BuildValue("s", "n/a"); + simple = 1; + goto weiter; + } + + if (!fontfile && !fontbuffer) THROWMSG("unknown Base-14 or CJK font"); + if (fontfile) + font = fz_new_font_from_file(gctx, NULL, fontfile, idx, 0); else - exto = PyString_FromString("n/a"); - PyObject *simpleo = JM_BOOL(simple); - PyObject *idxo = PyInt_FromLong((long) idx); - info = PyDict_New(); - PyDict_SetItemString(info, "name", name); - PyDict_SetItemString(info, "simple", simpleo); - PyDict_SetItemString(info, "ext", exto); - fz_drop_font(gctx, font); + { + if (!PyBytes_Check(fontbuffer)) THROWMSG("fontbuffer must be bytes"); + data = PyBytes_AsString(fontbuffer); + size = PyBytes_Size(fontbuffer); + font = fz_new_font_from_memory(gctx, NULL, data, size, idx, 0); + } + if (set_simple == 0) + { + font_obj = pdf_add_cid_font(gctx, pdf, font); + simple = 0; + } + else + { + font_obj = pdf_add_simple_font(gctx, pdf, font, encoding); + simple = 2; + } + + weiter: ; + ixref = pdf_to_num(gctx, font_obj); + + PyObject *name = Py_BuildValue("s", pdf_to_name(gctx, + pdf_dict_get(gctx, font_obj, PDF_NAME(BaseFont)))); + + PyObject *subt = Py_BuildValue("s", pdf_to_name(gctx, + pdf_dict_get(gctx, font_obj, PDF_NAME(Subtype)))); + + if (!exto) + exto = Py_BuildValue("s", fontextension(gctx, pdf, ixref)); + + value = Py_BuildValue("[i, {s:O, s:O, s:O, s:O, s:i}]", + ixref, + "name", name, + "type", subt, + "ext", exto, + "simple", JM_BOOL(simple), + "ordering", ordering); + Py_CLEAR(exto); + Py_CLEAR(name); + // resources and fonts objects will contain named reference to font pdf_dict_puts(gctx, fonts, fontname, font_obj); - pdf_dict_put(gctx, resources, PDF_NAME(Font), fonts); + pdf_drop_obj(gctx, font_obj); + fz_drop_font(gctx, font); } fz_catch(gctx) return NULL; pdf->dirty = 1; - return Py_BuildValue("[i, O]", ixref, info); + return value; } //--------------------------------------------------------------------- diff --git a/fitz/fitz.py b/fitz/fitz.py index f53ded69b..a83e1ea7a 100644 --- a/fitz/fitz.py +++ b/fitz/fitz.py @@ -106,9 +106,9 @@ class _object: VersionFitz = "1.14.0" -VersionBind = "1.14.2" -VersionDate = "2018-11-25 10:19:28" -version = (VersionBind, VersionFitz, "20181125101928") +VersionBind = "1.14.3" +VersionDate = "2018-11-29 05:23:32" +version = (VersionBind, VersionFitz, "20181129052332") class Matrix(): @@ -501,11 +501,15 @@ def __abs__(self): def __add__(self, p): if hasattr(p, "__float__"): return Point(self.x + p, self.y + p) + if len(p) != 2: + raise ValueError("require point-like object") return Point(self.x + p[0], self.y + p[1]) def __sub__(self, p): if hasattr(p, "__float__"): return Point(self.x - p, self.y - p) + if len(p) != 2: + raise ValueError("require point-like object") return Point(self.x - p[0], self.y - p[1]) def __mul__(self, m): @@ -700,12 +704,16 @@ def __add__(self, p): if hasattr(p, "__float__"): r = Rect(self.x0 + p, self.y0 + p, self.x1 + p, self.y1 + p) else: + if len(p) != 4: + raise ValueError("require rect-like object") r = Rect(self.x0 + p[0], self.y0 + p[1], self.x1 + p[2], self.y1 + p[3]) return r def __sub__(self, p): if hasattr(p, "__float__"): return Rect(self.x0 - p, self.y0 - p, self.x1 - p, self.y1 - p) + if len(p) != 4: + raise ValueError("require rect-like object") return Rect(self.x0 - p[0], self.y0 - p[1], self.x1 - p[2], self.y1 - p[3]) def transform(self, m): @@ -1226,6 +1234,24 @@ def _check5(self): "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic", "Symbol", "ZapfDingbats") +Base14_fontdict = {} +for f in Base14_fontnames: + Base14_fontdict[f.lower()] = f +Base14_fontdict["helv"] = "Helvetica" +Base14_fontdict["heit"] = "Helvetica-Oblique" +Base14_fontdict["hebo"] = "Helvetica-Bold" +Base14_fontdict["hebi"] = "Helvetica-BoldOblique" +Base14_fontdict["cour"] = "Courier" +Base14_fontdict["coit"] = "Courier-Oblique" +Base14_fontdict["cobo"] = "Courier-Bold" +Base14_fontdict["cobi"] = "Courier-BoldOblique" +Base14_fontdict["tiro"] = "Times-Roman" +Base14_fontdict["tibo"] = "Times-Bold" +Base14_fontdict["tiit"] = "Times-Italic" +Base14_fontdict["tibi"] = "Times-BoldItalic" +Base14_fontdict["symb"] = "Symbol" +Base14_fontdict["zadb"] = "ZapfDingbats" + #------------------------------------------------------------------------------ # Emulate old linkDest class #------------------------------------------------------------------------------ @@ -1361,8 +1387,10 @@ def getTJstr(text, glyphs): if glyphs is None: # this is a simple font otxt = "".join([hex(ord(c))[2:].rjust(2, "0") if ord(c)<256 else "3f" for c in text]) return "[<" + otxt + ">]" + # this is not a simple font -> take the glyphs of a character otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(4, "0") for c in text]) + return "[<" + otxt + ">]" ''' @@ -2006,12 +2034,12 @@ def permissions(self): return _fitz.Document_permissions(self) - def _getCharWidths(self, xref, limit, idx=0): + def _getCharWidths(self, xref, bfname, ext, ordering, limit, idx=0): """Return list of glyphs and glyph widths of a font.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") - return _fitz.Document__getCharWidths(self, xref, limit, idx) + return _fitz.Document__getCharWidths(self, xref, bfname, ext, ordering, limit, idx) def _getPageObjNumber(self, pno): @@ -2763,23 +2791,34 @@ def insertImage(self, rect, filename=None, pixmap=None, stream=None, overlay=1, return _fitz.Page_insertImage(self, rect, filename, pixmap, stream, overlay, _imgname) - def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, xref=0, set_simple=0, idx=0): - """insertFont(self, fontname=None, fontfile=None, fontbuffer=None, xref=0, set_simple=0, idx=0) -> PyObject *""" - + def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, + set_simple=False, idx=0, wmode=0, style=0, encoding=0): if not self.parent: raise ValueError("orphaned object: parent is None") f = CheckFont(self, fontname) if f is not None: # drop out if fontname already in page list return f[0] + bfname = "" + if not fontname: - fontname = "Helvetica" - if xref > 0: - _, _, _, fontbuffer = self.parent.extractFont(xref) - if not fontbuffer: - raise ValueError("xref is no valid font") + fontname = "helv" + + if fontname.lower() in Base14_fontdict.keys(): + bfname = Base14_fontdict[fontname.lower()] + CJK_number = -1 + CJK_list_n = ["china-t", "china-s", "japan", "korea"] + CJK_list_s = ["china-ts", "china-ss", "japan-s", "korea-s"] + if fontname in CJK_list_n: + CJK_number = CJK_list.index(fontname) + serif = 0 - val = _fitz.Page_insertFont(self, fontname, fontfile, fontbuffer, xref, set_simple, idx) + if fontname in CJK_list_s: + CJK_number = CJK_list_s.index(fontname) + serif = 1 + + val = self._insertFont(fontname, bfname, fontfile, fontbuffer, set_simple, idx, + wmode, style, serif, encoding, CJK_number) if val: xref = val[0] @@ -2794,7 +2833,9 @@ def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, xref=0, set_ return xref - return val + def _insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering): + """_insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering) -> PyObject *""" + return _fitz.Page__insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering) def _getContents(self): diff --git a/fitz/fitz_wrap.c b/fitz/fitz_wrap.c index 7acfd95b0..aa079bc55 100644 --- a/fitz/fitz_wrap.c +++ b/fitz/fitz_wrap.c @@ -10274,56 +10274,52 @@ SWIGINTERN PyObject *fz_document_s_permissions(struct fz_document_s *self){ PyDict_SetItemString(res, "note", n); return res; } -SWIGINTERN PyObject *fz_document_s__getCharWidths(struct fz_document_s *self,int xref,int limit,int idx){ +SWIGINTERN PyObject *fz_document_s__getCharWidths(struct fz_document_s *self,int xref,char *bfname,char *ext,int ordering,int limit,int idx){ pdf_document *pdf = pdf_specifics(gctx, self); PyObject *wlist = NULL; int i, glyph, mylimit; mylimit = limit; if (mylimit < 256) mylimit = 256; int cwlen = 0; + int lang = 0; const char *data; - int size; - fz_font *font = NULL; + int size, index; + fz_font *font = NULL, *fb_font= NULL; fz_buffer *buf = NULL; - pdf_obj *basefont = NULL; - const char *bfname = NULL; + fz_try(gctx) { assert_PDF(pdf); - if (xref < 1) THROWMSG("xref must at least 1"); - pdf_obj *o = pdf_load_object(gctx, pdf, xref); - if (pdf_is_dict(gctx, o)) + if (ordering >= 0) { - basefont = pdf_dict_get(gctx, o, PDF_NAME(BaseFont)); - if (pdf_is_name(gctx, basefont)) - { - bfname = (char *) pdf_to_name(gctx, basefont); - data = fz_lookup_base14_font(gctx, bfname, &size); - if (data) - { - font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); - } - else - { - buf = fontbuffer(gctx, pdf, xref); - if (!buf) THROWMSG("xref is not a supported font"); - font = fz_new_font_from_buffer(gctx, NULL, buf, idx, 0); - } - } + data = fz_lookup_cjk_font(gctx, ordering, &size, &index); + font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); + goto weiter; } - else + data = fz_lookup_base14_font(gctx, bfname, &size); + if (data) { - buf = fontbuffer(gctx, pdf, xref); - if (!buf) THROWMSG("xref is not a supported font"); - font = fz_new_font_from_buffer(gctx, NULL, buf, idx, 0); + font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); + goto weiter; } + buf = fontbuffer(gctx, pdf, xref); + if (!buf) THROWMSG("xref is not a supported font"); + font = fz_new_font_from_buffer(gctx, NULL, buf, idx, 0); + + weiter:; wlist = PyList_New(0); + float adv; for (i = 0; i < mylimit; i++) { glyph = fz_encode_character(gctx, font, i); + adv = fz_advance_glyph(gctx, font, glyph, 0); + if (ordering >= 0) + glyph = i; + + if (glyph > 0) { - PyList_Append(wlist, Py_BuildValue("(i, f)", glyph, fz_advance_glyph(gctx, font, glyph, 0))); + PyList_Append(wlist, Py_BuildValue("(i, f)", glyph, adv)); } else { @@ -11671,78 +11667,108 @@ SWIGINTERN PyObject *fz_page_s_insertImage(struct fz_page_s *self,PyObject *rect pdf->dirty = 1; return NONE; } -SWIGINTERN PyObject *fz_page_s_insertFont(struct fz_page_s *self,char const *fontname,char const *fontfile,PyObject *fontbuffer,int xref,int set_simple,int idx){ +SWIGINTERN PyObject *fz_page_s__insertFont(struct fz_page_s *self,char const *fontname,char const *bfname,char const *fontfile,PyObject *fontbuffer,int set_simple,int idx,int wmode,int style,int serif,int encoding,int ordering){ pdf_page *page = pdf_page_from_fz_page(gctx, self); pdf_document *pdf; pdf_obj *resources, *fonts, *font_obj; fz_font *font; const char *data = NULL; - int size, ixref = 0; - PyObject *info; + int size, ixref = 0, index = 0, simple = 0; + PyObject *info, *value; + PyObject *exto = NULL; fz_try(gctx) { assert_PDF(page); pdf = page->doc; - // get objects "Resources", "Resources/Font" + // get the objects /Resources, /Resources/Font resources = pdf_dict_get(gctx, page->obj, PDF_NAME(Resources)); fonts = pdf_dict_get(gctx, resources, PDF_NAME(Font)); - int simple = 0; if (!fonts) // page has no fonts yet - fonts = pdf_add_object_drop(gctx, pdf, pdf_new_dict(gctx, pdf, 1)); - - data = fz_lookup_base14_font(gctx, fontname, &size); - if (data) // base 14 font found { - font = fz_new_font_from_memory(gctx, fontname, data, size, 0, 0); - font_obj = pdf_add_simple_font(gctx, pdf, font, PDF_SIMPLE_ENCODING_LATIN); - simple = 1; + fonts = pdf_new_dict(gctx, pdf, 10); + pdf_dict_put_drop(gctx, resources, PDF_NAME(Font), fonts); } - else + + //------------------------------------------------------------- + // check for CJK font + //------------------------------------------------------------- + if (ordering > -1) { - if (!fontfile && !fontbuffer) THROWMSG("unknown PDF Base 14 font"); - if (fontfile) + data = fz_lookup_cjk_font(gctx, ordering, &size, &index); + if (data) { - font = fz_new_font_from_file(gctx, NULL, fontfile, idx, 0); - } - else - { - if (!PyBytes_Check(fontbuffer)) THROWMSG("fontbuffer must be bytes"); - data = PyBytes_AsString(fontbuffer); - size = PyBytes_Size(fontbuffer); - font = fz_new_font_from_memory(gctx, NULL, data, size, idx, 0); - } - if (set_simple == 0) - { - font_obj = pdf_add_cid_font(gctx, pdf, font); + font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); + font_obj = pdf_add_cjk_font(gctx, pdf, font, ordering, wmode, serif); + exto = Py_BuildValue("s", "n/a"); simple = 0; - } - else - { - font_obj = pdf_add_simple_font(gctx, pdf, font, PDF_SIMPLE_ENCODING_LATIN); - simple = 2; + goto weiter; } } - ixref = pdf_to_num(gctx, font_obj); - PyObject *name = PyString_FromString(fz_font_name(gctx, font)); - PyObject *exto; - if (simple != 1) - exto = PyString_FromString(fontextension(gctx, pdf, ixref)); + + //------------------------------------------------------------- + // check for PDF Base-14 font + //------------------------------------------------------------- + data = fz_lookup_base14_font(gctx, bfname, &size); + if (data) + { + font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); + font_obj = pdf_add_simple_font(gctx, pdf, font, encoding); + exto = Py_BuildValue("s", "n/a"); + simple = 1; + goto weiter; + } + + if (!fontfile && !fontbuffer) THROWMSG("unknown Base-14 or CJK font"); + if (fontfile) + font = fz_new_font_from_file(gctx, NULL, fontfile, idx, 0); else - exto = PyString_FromString("n/a"); - PyObject *simpleo = JM_BOOL(simple); - PyObject *idxo = PyInt_FromLong((long) idx); - info = PyDict_New(); - PyDict_SetItemString(info, "name", name); - PyDict_SetItemString(info, "simple", simpleo); - PyDict_SetItemString(info, "ext", exto); - fz_drop_font(gctx, font); + { + if (!PyBytes_Check(fontbuffer)) THROWMSG("fontbuffer must be bytes"); + data = PyBytes_AsString(fontbuffer); + size = PyBytes_Size(fontbuffer); + font = fz_new_font_from_memory(gctx, NULL, data, size, idx, 0); + } + if (set_simple == 0) + { + font_obj = pdf_add_cid_font(gctx, pdf, font); + simple = 0; + } + else + { + font_obj = pdf_add_simple_font(gctx, pdf, font, encoding); + simple = 2; + } + + weiter: ; + ixref = pdf_to_num(gctx, font_obj); + + PyObject *name = Py_BuildValue("s", pdf_to_name(gctx, + pdf_dict_get(gctx, font_obj, PDF_NAME(BaseFont)))); + + PyObject *subt = Py_BuildValue("s", pdf_to_name(gctx, + pdf_dict_get(gctx, font_obj, PDF_NAME(Subtype)))); + + if (!exto) + exto = Py_BuildValue("s", fontextension(gctx, pdf, ixref)); + + value = Py_BuildValue("[i, {s:O, s:O, s:O, s:O, s:i}]", + ixref, + "name", name, + "type", subt, + "ext", exto, + "simple", JM_BOOL(simple), + "ordering", ordering); + Py_CLEAR(exto); + Py_CLEAR(name); + // resources and fonts objects will contain named reference to font pdf_dict_puts(gctx, fonts, fontname, font_obj); - pdf_dict_put(gctx, resources, PDF_NAME(Font), fonts); + pdf_drop_obj(gctx, font_obj); + fz_drop_font(gctx, font); } fz_catch(gctx) return NULL; pdf->dirty = 1; - return Py_BuildValue("[i, O]", ixref, info); + return value; } SWIGINTERN PyObject *fz_page_s__getContents(struct fz_page_s *self){ pdf_page *page = pdf_page_from_fz_page(gctx, self); @@ -14981,23 +15007,37 @@ SWIGINTERN PyObject *_wrap_Document__getCharWidths(PyObject *SWIGUNUSEDPARM(self PyObject *resultobj = 0; struct fz_document_s *arg1 = (struct fz_document_s *) 0 ; int arg2 ; - int arg3 ; - int arg4 = (int) 0 ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; + int arg5 ; + int arg6 ; + int arg7 = (int) 0 ; void *argp1 = 0 ; int res1 = 0 ; int val2 ; int ecode2 = 0 ; - int val3 ; - int ecode3 = 0 ; - int val4 ; - int ecode4 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + int val5 ; + int ecode5 = 0 ; + int val6 ; + int ecode6 = 0 ; + int val7 ; + int ecode7 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; PyObject * obj3 = 0 ; + PyObject * obj4 = 0 ; + PyObject * obj5 = 0 ; + PyObject * obj6 = 0 ; PyObject *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)"OOO|O:Document__getCharWidths",&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + if (!PyArg_ParseTuple(args,(char *)"OOOOOO|O:Document__getCharWidths",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_document_s, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Document__getCharWidths" "', argument " "1"" of type '" "struct fz_document_s *""'"); @@ -15008,20 +15048,35 @@ SWIGINTERN PyObject *_wrap_Document__getCharWidths(PyObject *SWIGUNUSEDPARM(self SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Document__getCharWidths" "', argument " "2"" of type '" "int""'"); } arg2 = (int)(val2); - ecode3 = SWIG_AsVal_int(obj2, &val3); - if (!SWIG_IsOK(ecode3)) { - SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Document__getCharWidths" "', argument " "3"" of type '" "int""'"); + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Document__getCharWidths" "', argument " "3"" of type '" "char *""'"); + } + arg3 = (char *)(buf3); + res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "Document__getCharWidths" "', argument " "4"" of type '" "char *""'"); + } + arg4 = (char *)(buf4); + ecode5 = SWIG_AsVal_int(obj4, &val5); + if (!SWIG_IsOK(ecode5)) { + SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "Document__getCharWidths" "', argument " "5"" of type '" "int""'"); } - arg3 = (int)(val3); - if (obj3) { - ecode4 = SWIG_AsVal_int(obj3, &val4); - if (!SWIG_IsOK(ecode4)) { - SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Document__getCharWidths" "', argument " "4"" of type '" "int""'"); + arg5 = (int)(val5); + ecode6 = SWIG_AsVal_int(obj5, &val6); + if (!SWIG_IsOK(ecode6)) { + SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "Document__getCharWidths" "', argument " "6"" of type '" "int""'"); + } + arg6 = (int)(val6); + if (obj6) { + ecode7 = SWIG_AsVal_int(obj6, &val7); + if (!SWIG_IsOK(ecode7)) { + SWIG_exception_fail(SWIG_ArgError(ecode7), "in method '" "Document__getCharWidths" "', argument " "7"" of type '" "int""'"); } - arg4 = (int)(val4); + arg7 = (int)(val7); } { - result = (PyObject *)fz_document_s__getCharWidths(arg1,arg2,arg3,arg4); + result = (PyObject *)fz_document_s__getCharWidths(arg1,arg2,arg3,arg4,arg5,arg6,arg7); if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); @@ -15029,8 +15084,12 @@ SWIGINTERN PyObject *_wrap_Document__getCharWidths(PyObject *SWIGUNUSEDPARM(self } } resultobj = result; + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); return resultobj; fail: + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); return NULL; } @@ -16971,15 +17030,20 @@ SWIGINTERN PyObject *_wrap_Page_insertImage(PyObject *SWIGUNUSEDPARM(self), PyOb } -SWIGINTERN PyObject *_wrap_Page_insertFont(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Page__insertFont(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; struct fz_page_s *arg1 = (struct fz_page_s *) 0 ; - char *arg2 = (char *) NULL ; - char *arg3 = (char *) NULL ; - PyObject *arg4 = (PyObject *) NULL ; - int arg5 = (int) 0 ; - int arg6 = (int) 0 ; - int arg7 = (int) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; + PyObject *arg5 = (PyObject *) 0 ; + int arg6 ; + int arg7 ; + int arg8 ; + int arg9 ; + int arg10 ; + int arg11 ; + int arg12 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -16988,12 +17052,23 @@ SWIGINTERN PyObject *_wrap_Page_insertFont(PyObject *SWIGUNUSEDPARM(self), PyObj int res3 ; char *buf3 = 0 ; int alloc3 = 0 ; - int val5 ; - int ecode5 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; int val6 ; int ecode6 = 0 ; int val7 ; int ecode7 = 0 ; + int val8 ; + int ecode8 = 0 ; + int val9 ; + int ecode9 = 0 ; + int val10 ; + int ecode10 = 0 ; + int val11 ; + int ecode11 = 0 ; + int val12 ; + int ecode12 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; @@ -17001,54 +17076,72 @@ SWIGINTERN PyObject *_wrap_Page_insertFont(PyObject *SWIGUNUSEDPARM(self), PyObj PyObject * obj4 = 0 ; PyObject * obj5 = 0 ; PyObject * obj6 = 0 ; + PyObject * obj7 = 0 ; + PyObject * obj8 = 0 ; + PyObject * obj9 = 0 ; + PyObject * obj10 = 0 ; + PyObject * obj11 = 0 ; PyObject *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)"O|OOOOOO:Page_insertFont",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6)) SWIG_fail; + if (!PyArg_ParseTuple(args,(char *)"OOOOOOOOOOOO:Page__insertFont",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6,&obj7,&obj8,&obj9,&obj10,&obj11)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_page_s, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Page_insertFont" "', argument " "1"" of type '" "struct fz_page_s *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Page__insertFont" "', argument " "1"" of type '" "struct fz_page_s *""'"); } arg1 = (struct fz_page_s *)(argp1); - if (obj1) { - res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Page_insertFont" "', argument " "2"" of type '" "char const *""'"); - } - arg2 = (char *)(buf2); - } - if (obj2) { - res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Page_insertFont" "', argument " "3"" of type '" "char const *""'"); - } - arg3 = (char *)(buf3); - } - if (obj3) { - arg4 = obj3; - } - if (obj4) { - ecode5 = SWIG_AsVal_int(obj4, &val5); - if (!SWIG_IsOK(ecode5)) { - SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "Page_insertFont" "', argument " "5"" of type '" "int""'"); - } - arg5 = (int)(val5); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Page__insertFont" "', argument " "2"" of type '" "char const *""'"); } - if (obj5) { - ecode6 = SWIG_AsVal_int(obj5, &val6); - if (!SWIG_IsOK(ecode6)) { - SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "Page_insertFont" "', argument " "6"" of type '" "int""'"); - } - arg6 = (int)(val6); + arg2 = (char *)(buf2); + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Page__insertFont" "', argument " "3"" of type '" "char const *""'"); } - if (obj6) { - ecode7 = SWIG_AsVal_int(obj6, &val7); - if (!SWIG_IsOK(ecode7)) { - SWIG_exception_fail(SWIG_ArgError(ecode7), "in method '" "Page_insertFont" "', argument " "7"" of type '" "int""'"); - } - arg7 = (int)(val7); + arg3 = (char *)(buf3); + res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "Page__insertFont" "', argument " "4"" of type '" "char const *""'"); } + arg4 = (char *)(buf4); + arg5 = obj4; + ecode6 = SWIG_AsVal_int(obj5, &val6); + if (!SWIG_IsOK(ecode6)) { + SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "Page__insertFont" "', argument " "6"" of type '" "int""'"); + } + arg6 = (int)(val6); + ecode7 = SWIG_AsVal_int(obj6, &val7); + if (!SWIG_IsOK(ecode7)) { + SWIG_exception_fail(SWIG_ArgError(ecode7), "in method '" "Page__insertFont" "', argument " "7"" of type '" "int""'"); + } + arg7 = (int)(val7); + ecode8 = SWIG_AsVal_int(obj7, &val8); + if (!SWIG_IsOK(ecode8)) { + SWIG_exception_fail(SWIG_ArgError(ecode8), "in method '" "Page__insertFont" "', argument " "8"" of type '" "int""'"); + } + arg8 = (int)(val8); + ecode9 = SWIG_AsVal_int(obj8, &val9); + if (!SWIG_IsOK(ecode9)) { + SWIG_exception_fail(SWIG_ArgError(ecode9), "in method '" "Page__insertFont" "', argument " "9"" of type '" "int""'"); + } + arg9 = (int)(val9); + ecode10 = SWIG_AsVal_int(obj9, &val10); + if (!SWIG_IsOK(ecode10)) { + SWIG_exception_fail(SWIG_ArgError(ecode10), "in method '" "Page__insertFont" "', argument " "10"" of type '" "int""'"); + } + arg10 = (int)(val10); + ecode11 = SWIG_AsVal_int(obj10, &val11); + if (!SWIG_IsOK(ecode11)) { + SWIG_exception_fail(SWIG_ArgError(ecode11), "in method '" "Page__insertFont" "', argument " "11"" of type '" "int""'"); + } + arg11 = (int)(val11); + ecode12 = SWIG_AsVal_int(obj11, &val12); + if (!SWIG_IsOK(ecode12)) { + SWIG_exception_fail(SWIG_ArgError(ecode12), "in method '" "Page__insertFont" "', argument " "12"" of type '" "int""'"); + } + arg12 = (int)(val12); { - result = (PyObject *)fz_page_s_insertFont(arg1,(char const *)arg2,(char const *)arg3,arg4,arg5,arg6,arg7); + result = (PyObject *)fz_page_s__insertFont(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12); if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); @@ -17058,10 +17151,12 @@ SWIGINTERN PyObject *_wrap_Page_insertFont(PyObject *SWIGUNUSEDPARM(self), PyObj resultobj = result; if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); return NULL; } @@ -21395,7 +21490,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Page__cleanContents", _wrap_Page__cleanContents, METH_VARARGS, (char *)"Page__cleanContents(self) -> PyObject *"}, { (char *)"Page__showPDFpage", _wrap_Page__showPDFpage, METH_VARARGS, (char *)"Page__showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *"}, { (char *)"Page_insertImage", _wrap_Page_insertImage, METH_VARARGS, (char *)"Insert a new image into a rectangle."}, - { (char *)"Page_insertFont", _wrap_Page_insertFont, METH_VARARGS, (char *)"Page_insertFont(self, fontname=None, fontfile=None, fontbuffer=None, xref=0, set_simple=0, idx=0) -> PyObject *"}, + { (char *)"Page__insertFont", _wrap_Page__insertFont, METH_VARARGS, (char *)"Page__insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering) -> PyObject *"}, { (char *)"Page__getContents", _wrap_Page__getContents, METH_VARARGS, (char *)"Page__getContents(self) -> PyObject *"}, { (char *)"Page__setContents", _wrap_Page__setContents, METH_VARARGS, (char *)"Set the /Contents object in page definition"}, { (char *)"Page_swigregister", Page_swigregister, METH_VARARGS, NULL}, diff --git a/fitz/helper-geo-py.i b/fitz/helper-geo-py.i index 5908ae63e..0629f2ffe 100644 --- a/fitz/helper-geo-py.i +++ b/fitz/helper-geo-py.i @@ -389,11 +389,15 @@ class Point(): def __add__(self, p): if hasattr(p, "__float__"): return Point(self.x + p, self.y + p) + if len(p) != 2: + raise ValueError("require point-like object") return Point(self.x + p[0], self.y + p[1]) def __sub__(self, p): if hasattr(p, "__float__"): return Point(self.x - p, self.y - p) + if len(p) != 2: + raise ValueError("require point-like object") return Point(self.x - p[0], self.y - p[1]) def __mul__(self, m): @@ -588,12 +592,16 @@ class Rect(): if hasattr(p, "__float__"): r = Rect(self.x0 + p, self.y0 + p, self.x1 + p, self.y1 + p) else: + if len(p) != 4: + raise ValueError("require rect-like object") r = Rect(self.x0 + p[0], self.y0 + p[1], self.x1 + p[2], self.y1 + p[3]) return r def __sub__(self, p): if hasattr(p, "__float__"): return Rect(self.x0 - p, self.y0 - p, self.x1 - p, self.y1 - p) + if len(p) != 4: + raise ValueError("require rect-like object") return Rect(self.x0 - p[0], self.y0 - p[1], self.x1 - p[2], self.y1 - p[3]) def transform(self, m): diff --git a/fitz/helper-python.i b/fitz/helper-python.i index 58f3d2979..30cfa3dc0 100644 --- a/fitz/helper-python.i +++ b/fitz/helper-python.i @@ -62,6 +62,24 @@ Base14_fontnames = ("Courier", "Courier-Oblique", "Courier-Bold", "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic", "Symbol", "ZapfDingbats") +Base14_fontdict = {} +for f in Base14_fontnames: + Base14_fontdict[f.lower()] = f +Base14_fontdict["helv"] = "Helvetica" +Base14_fontdict["heit"] = "Helvetica-Oblique" +Base14_fontdict["hebo"] = "Helvetica-Bold" +Base14_fontdict["hebi"] = "Helvetica-BoldOblique" +Base14_fontdict["cour"] = "Courier" +Base14_fontdict["coit"] = "Courier-Oblique" +Base14_fontdict["cobo"] = "Courier-Bold" +Base14_fontdict["cobi"] = "Courier-BoldOblique" +Base14_fontdict["tiro"] = "Times-Roman" +Base14_fontdict["tibo"] = "Times-Bold" +Base14_fontdict["tiit"] = "Times-Italic" +Base14_fontdict["tibi"] = "Times-BoldItalic" +Base14_fontdict["symb"] = "Symbol" +Base14_fontdict["zadb"] = "ZapfDingbats" + #------------------------------------------------------------------------------ # Emulate old linkDest class #------------------------------------------------------------------------------ @@ -197,8 +215,10 @@ def getTJstr(text, glyphs): if glyphs is None: # this is a simple font otxt = "".join([hex(ord(c))[2:].rjust(2, "0") if ord(c)<256 else "3f" for c in text]) return "[<" + otxt + ">]" + # this is not a simple font -> take the glyphs of a character otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(4, "0") for c in text]) + return "[<" + otxt + ">]" ''' diff --git a/fitz/utils.py b/fitz/utils.py index e4dce4bb3..ac2c0ed45 100644 --- a/fitz/utils.py +++ b/fitz/utils.py @@ -790,7 +790,7 @@ def insertLink(page, lnk, mark = True): # Page.insertTextbox #------------------------------------------------------------------------------- def insertTextbox(page, rect, buffer, - fontname = "Helvetica", + fontname = "helv", fontfile = None, idx = 0, set_simple = 0, @@ -837,7 +837,7 @@ def insertTextbox(page, rect, buffer, #------------------------------------------------------------------------------ def insertText(page, point, text, fontsize = 11, - fontname = "Helvetica", + fontname = "helv", fontfile = None, idx = 0, set_simple = 0, @@ -1663,7 +1663,7 @@ def getCharWidths(doc, xref, limit = 256, idx = 0): glyphs = None fontdict = {"name": name, "type": stype, "ext": ext} if ext == "": - raise ValueError("xref is no valid font") + raise ValueError("xref is not a font") if stype in ("Type1", "MMType1", "TrueType"): simple = True else: @@ -1687,7 +1687,10 @@ def getCharWidths(doc, xref, limit = 256, idx = 0): if mylimit <= oldlimit: return glyphs - new_glyphs = doc._getCharWidths(xref, mylimit, idx) + new_glyphs = doc._getCharWidths(xref, fontdict["name"], + fontdict["ext"], + fontdict["ordering"], + mylimit, idx) glyphs = new_glyphs fontdict["glyphs"] = glyphs fontinfo[1] = fontdict @@ -2001,7 +2004,7 @@ def drawSquiggle(self, p1, p2, breadth = 2): #============================================================================== def insertText(self, point, buffer, fontsize = 11, - fontname = "Helvetica", + fontname = "helv", fontfile = None, idx = 0, set_simple = 0, @@ -2027,7 +2030,7 @@ def insertText(self, point, buffer, fname = fontname f = None if not fname: - fname = "Helvetica" + fname = "helv" if fname[0] == "/": fname = fname[1:] f = CheckFont(self.page, fname) @@ -2043,7 +2046,7 @@ def insertText(self, point, buffer, basename, ext, stype, _ = self.doc.extractFont(xref, info_only = True) simple = True if stype in ("Type1", "TrueType", "MMType1") else False # decide how text is presented to PDF: - # simple fonts: use the chars directly in PDF text-showing operators + # simple fonts: use the chars directly in PDF operators # cid fonts: use glyph number of each character glyphs = None if not simple: @@ -2135,7 +2138,7 @@ def insertText(self, point, buffer, #============================================================================== # Shape.insertTextbox #============================================================================== - def insertTextbox(self, rect, buffer, fontname = "Helvetica", fontfile = None, + def insertTextbox(self, rect, buffer, fontname = "helv", fontfile = None, fontsize = 11, idx = 0, set_simple = 0, color = (0,0,0), expandtabs = 1, align = 0, rotate = 0, morph = None): @@ -2174,7 +2177,7 @@ def insertTextbox(self, rect, buffer, fontname = "Helvetica", fontfile = None, fname = fontname f = None if not fname: - fname = "Helvetica" + fname = "helv" if fname[0] == "/": fname = fname[1:] f = CheckFont(self.page, fname) diff --git a/fitz/version.i b/fitz/version.i index 2e8881363..36138c96d 100644 --- a/fitz/version.i +++ b/fitz/version.i @@ -1,6 +1,6 @@ %pythoncode %{ VersionFitz = "1.14.0" -VersionBind = "1.14.2" -VersionDate = "2018-11-25 10:19:28" -version = (VersionBind, VersionFitz, "20181125101928") +VersionBind = "1.14.3" +VersionDate = "2018-11-29 05:23:32" +version = (VersionBind, VersionFitz, "20181129052332") %} \ No newline at end of file diff --git a/setup.py b/setup.py index fed2008df..df38dac89 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ sources=['./fitz/fitz_wrap.c',]) setup(name = 'PyMuPDF', - version = "1.14.2", + version = "1.14.3", description = 'Python bindings for the PDF rendering library MuPDF', classifiers = ['Development Status :: 5 - Production/Stable', 'Environment :: Console', From 785951582d1698d45156fcc5b1d88f4cff247a39 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Sun, 2 Dec 2018 08:13:01 -0400 Subject: [PATCH 3/4] generate v1.14.3 --- fitz/fitz.i | 125 ++++++++++++---------- fitz/fitz.py | 246 +++++++++++++++++++++++++++++++++---------- fitz/fitz_wrap.c | 66 +++++------- fitz/helper-python.i | 161 +++++++++++++++++++++++----- fitz/utils.py | 158 +++++++++++++++------------ fitz/version.i | 4 +- 6 files changed, 516 insertions(+), 244 deletions(-) diff --git a/fitz/fitz.i b/fitz/fitz.i index f4e13f810..ddaa8fd2f 100644 --- a/fitz/fitz.i +++ b/fitz/fitz.i @@ -3162,62 +3162,80 @@ fannot._erase() //--------------------------------------------------------------------- %pythoncode %{ -def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, - set_simple=False, idx=0, wmode=0, style=0, encoding=0): - if not self.parent: +def insertFont(self, fontname="helv", fontfile=None, fontbuffer=None, + set_simple=False, wmode=0, encoding=0): + doc = self.parent + if not doc: raise ValueError("orphaned object: parent is None") - f = CheckFont(self, fontname) - if f is not None: # drop out if fontname already in page list - return f[0] - bfname = "" + idx = 0 + + if fontname.startswith("/"): + fontname = fontname[1:] + + font = CheckFont(self, fontname) + if font is not None: # font already in font list of page + xref = font[0] # this is the xref + if CheckFontInfo(doc, xref): # also in our document font list? + return xref # yes: we are done + # need to build the doc FontInfo entry - done via getCharWidths + doc.getCharWidths(xref) + return xref - if not fontname: - fontname = "helv" + #-------------------------------------------------------------------------- + # the font is not present for this page + #-------------------------------------------------------------------------- - if fontname.lower() in Base14_fontdict.keys(): - bfname = Base14_fontdict[fontname.lower()] + bfname = Base14_fontdict.get(fontname.lower(), None) # BaseFont if Base-14 font serif = 0 CJK_number = -1 CJK_list_n = ["china-t", "china-s", "japan", "korea"] CJK_list_s = ["china-ts", "china-ss", "japan-s", "korea-s"] - if fontname in CJK_list_n: - CJK_number = CJK_list.index(fontname) + + try: + CJK_number = CJK_list_n.index(fontname) serif = 0 + except: + pass - if fontname in CJK_list_s: - CJK_number = CJK_list_s.index(fontname) - serif = 1 + if CJK_number < 0: + try: + CJK_number = CJK_list_s.index(fontname) + serif = 1 + except: + pass + # install the font for the page val = self._insertFont(fontname, bfname, fontfile, fontbuffer, set_simple, idx, - wmode, style, serif, encoding, CJK_number) - - if val: - xref = val[0] - f = CheckFont(self, fontname) - if f is not None: - val[1]["type"] = f[2] # put /Subtype in font info - val[1]["glyphs"] = None - doc = self.parent # now add to document font info - fi = CheckFontInfo(doc, xref) - if fi is None: # look if we are already present - doc.FontInfos.append(val) # no: add me to document object - return xref + wmode, serif, encoding, CJK_number) + + if not val: # did not work, error return + return val + + xref = val[0] # xref of installed font + + if CheckFontInfo(doc, xref): # check again: document already has this font + return xref # we are done + + # need to create document font info + doc.getCharWidths(xref) + return xref + %} FITZEXCEPTION(_insertFont, !result) - PyObject *_insertFont(const char *fontname, const char *bfname, - const char *fontfile, + PyObject *_insertFont(char *fontname, char *bfname, + char *fontfile, PyObject *fontbuffer, int set_simple, int idx, - int wmode, int style, int serif, + int wmode, int serif, int encoding, int ordering) { pdf_page *page = pdf_page_from_fz_page(gctx, $self); pdf_document *pdf; pdf_obj *resources, *fonts, *font_obj; fz_font *font; - const char *data = NULL; + char *data = NULL; int size, ixref = 0, index = 0, simple = 0; PyObject *info, *value; PyObject *exto = NULL; @@ -3237,23 +3255,20 @@ def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, //------------------------------------------------------------- // check for CJK font //------------------------------------------------------------- - if (ordering > -1) + if (ordering > -1) data = fz_lookup_cjk_font(gctx, ordering, &size, &index); + if (data) { - data = fz_lookup_cjk_font(gctx, ordering, &size, &index); - if (data) - { - font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); - font_obj = pdf_add_cjk_font(gctx, pdf, font, ordering, wmode, serif); - exto = Py_BuildValue("s", "n/a"); - simple = 0; - goto weiter; - } + font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); + font_obj = pdf_add_cjk_font(gctx, pdf, font, ordering, wmode, serif); + exto = Py_BuildValue("s", "n/a"); + simple = 0; + goto weiter; } //------------------------------------------------------------- // check for PDF Base-14 font //------------------------------------------------------------- - data = fz_lookup_base14_font(gctx, bfname, &size); + if (bfname) data = fz_lookup_base14_font(gctx, bfname, &size); if (data) { font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); @@ -3263,17 +3278,16 @@ def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, goto weiter; } - if (!fontfile && !fontbuffer) THROWMSG("unknown Base-14 or CJK font"); if (fontfile) font = fz_new_font_from_file(gctx, NULL, fontfile, idx, 0); else { - if (!PyBytes_Check(fontbuffer)) THROWMSG("fontbuffer must be bytes"); - data = PyBytes_AsString(fontbuffer); - size = PyBytes_Size(fontbuffer); + size = (int) JM_CharFromBytesOrArray(fontbuffer, &data); + if (!size) THROWMSG("one of fontfile, fontbuffer must be given"); font = fz_new_font_from_memory(gctx, NULL, data, size, idx, 0); } - if (set_simple == 0) + + if (!set_simple) { font_obj = pdf_add_cid_font(gctx, pdf, font); simple = 0; @@ -3283,7 +3297,7 @@ def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, font_obj = pdf_add_simple_font(gctx, pdf, font, encoding); simple = 2; } - + weiter: ; ixref = pdf_to_num(gctx, font_obj); @@ -3298,13 +3312,14 @@ def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, value = Py_BuildValue("[i, {s:O, s:O, s:O, s:O, s:i}]", ixref, - "name", name, - "type", subt, - "ext", exto, - "simple", JM_BOOL(simple), - "ordering", ordering); + "name", name, // base font name + "type", subt, // subtype + "ext", exto, // file extension + "simple", JM_BOOL(simple), // simple font? + "ordering", ordering); // CJK font? Py_CLEAR(exto); Py_CLEAR(name); + Py_CLEAR(subt); // resources and fonts objects will contain named reference to font pdf_dict_puts(gctx, fonts, fontname, font_obj); diff --git a/fitz/fitz.py b/fitz/fitz.py index a83e1ea7a..f935fd7c5 100644 --- a/fitz/fitz.py +++ b/fitz/fitz.py @@ -107,8 +107,8 @@ class _object: VersionFitz = "1.14.0" VersionBind = "1.14.3" -VersionDate = "2018-11-29 05:23:32" -version = (VersionBind, VersionFitz, "20181129052332") +VersionDate = "2018-12-01 18:33:20" +version = (VersionBind, VersionFitz, "20181201183320") class Matrix(): @@ -1225,9 +1225,8 @@ def _check5(self): STAMP_Draft = 13 #------------------------------------------------------------------------------ -# Base 14 font names +# Base 14 font names and dictionary #------------------------------------------------------------------------------ - Base14_fontnames = ("Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique", "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique", @@ -1253,8 +1252,115 @@ def _check5(self): Base14_fontdict["zadb"] = "ZapfDingbats" #------------------------------------------------------------------------------ -# Emulate old linkDest class +# Glyph list for the built-in font 'ZapfDingbats' +#------------------------------------------------------------------------------ +zapf_glyphs = ( + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (33, 0.974), (34, 0.961), (35, 0.974), + (36, 0.98), (37, 0.719), (38, 0.789), (39, 0.79), (40, 0.791), (41, 0.69), + (42, 0.96), (43, 0.939), (44, 0.549), (45, 0.855), (46, 0.911), (47, 0.933), + (48, 0.911), (49, 0.945), (50, 0.974), (51, 0.755), (52, 0.846), (53, 0.762), + (54, 0.761), (55, 0.571), (56, 0.677), (57, 0.763), (58, 0.76), (59, 0.759), + (60, 0.754), (61, 0.494), (62, 0.552), (63, 0.537), (64, 0.577), (65, 0.692), + (66, 0.786), (67, 0.788), (68, 0.788), (69, 0.79), (70, 0.793), (71, 0.794), + (72, 0.816), (73, 0.823), (74, 0.789), (75, 0.841), (76, 0.823), (77, 0.833), + (78, 0.816), (79, 0.831), (80, 0.923), (81, 0.744), (82, 0.723), (83, 0.749), + (84, 0.79), (85, 0.792), (86, 0.695), (87, 0.776), (88, 0.768), (89, 0.792), + (90, 0.759), (91, 0.707), (92, 0.708), (93, 0.682), (94, 0.701), (95, 0.826), + (96, 0.815), (97, 0.789), (98, 0.789), (99, 0.707), (100, 0.687), (101, 0.696), + (102, 0.689), (103, 0.786), (104, 0.787), (105, 0.713), (106, 0.791), + (107, 0.785), (108, 0.791), (109, 0.873), (110, 0.761), (111, 0.762), + (112, 0.762), (113, 0.759), (114, 0.759), (115, 0.892), (116, 0.892), + (117, 0.788), (118, 0.784), (119, 0.438), (120, 0.138), (121, 0.277), + (122, 0.415), (123, 0.392), (124, 0.392), (125, 0.668), (126, 0.668), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (161, 0.732), (162, 0.544), + (163, 0.544), (164, 0.91), (165, 0.667), (166, 0.76), (167, 0.76), + (168, 0.776), (169, 0.595), (170, 0.694), (171, 0.626), (172, 0.788), + (173, 0.788), (174, 0.788), (175, 0.788), (176, 0.788), (177, 0.788), + (178, 0.788), (179, 0.788), (180, 0.788), (181, 0.788), (182, 0.788), + (183, 0.788), (184, 0.788), (185, 0.788), (186, 0.788), (187, 0.788), + (188, 0.788), (189, 0.788), (190, 0.788), (191, 0.788), (192, 0.788), + (193, 0.788), (194, 0.788), (195, 0.788), (196, 0.788), (197, 0.788), + (198, 0.788), (199, 0.788), (200, 0.788), (201, 0.788), (202, 0.788), + (203, 0.788), (204, 0.788), (205, 0.788), (206, 0.788), (207, 0.788), + (208, 0.788), (209, 0.788), (210, 0.788), (211, 0.788), (212, 0.894), + (213, 0.838), (214, 1.016), (215, 0.458), (216, 0.748), (217, 0.924), + (218, 0.748), (219, 0.918), (220, 0.927), (221, 0.928), (222, 0.928), + (223, 0.834), (224, 0.873), (225, 0.828), (226, 0.924), (227, 0.924), + (228, 0.917), (229, 0.93), (230, 0.931), (231, 0.463), (232, 0.883), + (233, 0.836), (234, 0.836), (235, 0.867), (236, 0.867), (237, 0.696), + (238, 0.696), (239, 0.874), (32, 0.278), (241, 0.874), (242, 0.76), + (243, 0.946), (244, 0.771), (245, 0.865), (246, 0.771), (247, 0.888), + (248, 0.967), (249, 0.888), (250, 0.831), (251, 0.873), (252, 0.927), + (253, 0.97), (32, 0.278), (32, 0.278) + ) + +#------------------------------------------------------------------------------ +# Glyph list for the built-in font 'Symbol' #------------------------------------------------------------------------------ +symbol_glyphs = ( + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (32, 0.25), (33, 0.333), (34, 0.713), + (35, 0.5), (36, 0.549), (37, 0.833), (38, 0.778), (39, 0.439), + (40, 0.333), (41, 0.333), (42, 0.5), (43, 0.549), (44, 0.25), (45, 0.549), + (46, 0.25), (47, 0.278), (48, 0.5), (49, 0.5), (50, 0.5), (51, 0.5), + (52, 0.5), (53, 0.5), (54, 0.5), (55, 0.5), (56, 0.5), (57, 0.5), + (58, 0.278), (59, 0.278), (60, 0.549), (61, 0.549), (62, 0.549), + (63, 0.444), (64, 0.549), (65, 0.722), (66, 0.667), (67, 0.722), + (68, 0.612), (69, 0.611), (70, 0.763), (71, 0.603), (72, 0.722), + (73, 0.333), (74, 0.631), (75, 0.722), (76, 0.686), (77, 0.889), + (78, 0.722), (79, 0.722), (80, 0.768), (81, 0.741), (82, 0.556), + (83, 0.592), (84, 0.611), (85, 0.69), (86, 0.439), (87, 0.768), + (88, 0.645), (89, 0.795), (90, 0.611), (91, 0.333), (92, 0.863), + (93, 0.333), (94, 0.658), (95, 0.5), (96, 0.5), (97, 0.631), (98, 0.549), + (99, 0.549), (100, 0.494), (101, 0.439), (102, 0.521), (103, 0.411), + (104, 0.603), (105, 0.329), (106, 0.603), (107, 0.549), (108, 0.549), + (109, 0.576), (110, 0.521), (111, 0.549), (112, 0.549), (113, 0.521), + (114, 0.549), (115, 0.603), (116, 0.439), (117, 0.576), (118, 0.713), + (119, 0.686), (120, 0.493), (121, 0.686), (122, 0.494), (123, 0.48), + (124, 0.2), (125, 0.48), (126, 0.549), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (160, 0.25), (161, 0.62), (162, 0.247), (163, 0.549), + (164, 0.167), (165, 0.713), (166, 0.5), (167, 0.753), (168, 0.753), + (169, 0.753), (170, 0.753), (171, 1.042), (172, 0.713), (173, 0.603), + (174, 0.987), (175, 0.603), (176, 0.4), (177, 0.549), (178, 0.411), + (179, 0.549), (180, 0.549), (181, 0.576), (182, 0.494), (183, 0.46), + (184, 0.549), (185, 0.549), (186, 0.549), (187, 0.549), (188, 1), + (189, 0.603), (190, 1), (191, 0.658), (192, 0.823), (193, 0.686), + (194, 0.795), (195, 0.987), (196, 0.768), (197, 0.768), (198, 0.823), + (199, 0.768), (200, 0.768), (201, 0.713), (202, 0.713), (203, 0.713), + (204, 0.713), (205, 0.713), (206, 0.713), (207, 0.713), (208, 0.768), + (209, 0.713), (210, 0.79), (211, 0.79), (212, 0.89), (213, 0.823), + (214, 0.549), (215, 0.549), (216, 0.713), (217, 0.603), (218, 0.603), + (219, 1.042), (220, 0.987), (221, 0.603), (222, 0.987), (223, 0.603), + (224, 0.494), (225, 0.329), (226, 0.79), (227, 0.79), (228, 0.786), + (229, 0.713), (230, 0.384), (231, 0.384), (232, 0.384), (233, 0.384), + (234, 0.384), (235, 0.384), (236, 0.494), (237, 0.494), (238, 0.494), + (239, 0.494), (63, 0.444), (241, 0.329), (242, 0.274), (243, 0.686), + (244, 0.686), (245, 0.686), (246, 0.384), (247, 0.549), (248, 0.384), + (249, 0.384), (250, 0.384), (251, 0.384), (252, 0.494), (253, 0.494), + (254, 0.494), (63, 0.444) + ) + class linkDest(): """link or outline destination details""" def __init__(self, obj, rlink): @@ -1372,24 +1478,34 @@ def getPDFstr(x): return "(" + r + ")" -#------------------------------------------------------------------------------ -# Return a PDF string suitable for the TJ operator enclosed in "[]" brackets. -# The input string is converted to either 2 or 4 hex digits per character. -# If no glyphs are supplied, then a simple font is assumed and each character -# taken directly. -# Otherwise a char's glyph is taken and 4 hex digits per char are put out. -#------------------------------------------------------------------------------ -def getTJstr(text, glyphs): +def getTJstr(text, glyphs, simple, ordering): + """Return a PDF string enclosed in [] brackets, suitable for the PDF TJ + operator. + The input string is converted to either 2 or 4 hex digits per character. + * simple: + - no glyphs: 2-chars, use char codes as the glyph + - glyphs: 2-chars, use glyphs instead of char codes (Symbol, ZapfDingbats) + * not simple: + - ordering < 0: 4-chars, use glyphs not char codes + - ordering >=0: a CJK font! 4 chars, use char codes as glyphs +""" if text.startswith("[<") and text.endswith(">]"): # already done return text + if not bool(text): return "[<>]" - if glyphs is None: # this is a simple font - otxt = "".join([hex(ord(c))[2:].rjust(2, "0") if ord(c)<256 else "3f" for c in text]) + + if simple: + if glyphs is None: # simple and not Symbol / ZapfDingbats + otxt = "".join([hex(ord(c))[2:].rjust(2, "0") if ord(c)<256 else "3f" for c in text]) + else: # Symbol or ZapfDingbats + otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(2, "0") for c in text]) return "[<" + otxt + ">]" -# this is not a simple font -> take the glyphs of a character - otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(4, "0") for c in text]) + if ordering < 0: # not a CJK font: use the glyphs + otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(4, "0") for c in text]) + else: # CJK: use char codes, no glyphs + otxt = "".join([hex(ord(c))[2:].rjust(4, "0") for c in text]) return "[<" + otxt + ">]" @@ -1490,23 +1606,18 @@ def CheckMorph(o): def CheckFont(page, fontname): """Return an entry in the page's font list if reference name matches. """ - fl = page.getFontList() - refname = None - for f in fl: + for f in page.getFontList(): if f[4] == fontname: - refname = f - break - return refname + return f + return None def CheckFontInfo(doc, xref): """Return a font info if present in the document. """ - fi = None for f in doc.FontInfos: if xref == f[0]: - fi = f - break - return fi + return f + return None def UpdateFontInfo(doc, info): xref = info[0] @@ -2791,51 +2902,70 @@ def insertImage(self, rect, filename=None, pixmap=None, stream=None, overlay=1, return _fitz.Page_insertImage(self, rect, filename, pixmap, stream, overlay, _imgname) - def insertFont(self, fontname=None, fontfile=None, fontbuffer=None, - set_simple=False, idx=0, wmode=0, style=0, encoding=0): - if not self.parent: + def insertFont(self, fontname="helv", fontfile=None, fontbuffer=None, + set_simple=False, wmode=0, encoding=0): + doc = self.parent + if not doc: raise ValueError("orphaned object: parent is None") - f = CheckFont(self, fontname) - if f is not None: # drop out if fontname already in page list - return f[0] - bfname = "" + idx = 0 + + if fontname.startswith("/"): + fontname = fontname[1:] + + font = CheckFont(self, fontname) + if font is not None: # font already in font list of page + xref = font[0] # this is the xref + if CheckFontInfo(doc, xref): # also in our document font list? + return xref # yes: we are done + # need to build the doc FontInfo entry - done via getCharWidths + doc.getCharWidths(xref) + return xref - if not fontname: - fontname = "helv" + #-------------------------------------------------------------------------- + # the font is not present for this page + #-------------------------------------------------------------------------- - if fontname.lower() in Base14_fontdict.keys(): - bfname = Base14_fontdict[fontname.lower()] + bfname = Base14_fontdict.get(fontname.lower(), None) # BaseFont if Base-14 font + serif = 0 CJK_number = -1 CJK_list_n = ["china-t", "china-s", "japan", "korea"] CJK_list_s = ["china-ts", "china-ss", "japan-s", "korea-s"] - if fontname in CJK_list_n: - CJK_number = CJK_list.index(fontname) + + try: + CJK_number = CJK_list_n.index(fontname) serif = 0 + except: + pass - if fontname in CJK_list_s: - CJK_number = CJK_list_s.index(fontname) - serif = 1 + if CJK_number < 0: + try: + CJK_number = CJK_list_s.index(fontname) + serif = 1 + except: + pass + # install the font for the page val = self._insertFont(fontname, bfname, fontfile, fontbuffer, set_simple, idx, - wmode, style, serif, encoding, CJK_number) + wmode, serif, encoding, CJK_number) + + if not val: # did not work, error return + return val + + xref = val[0] # xref of installed font + + if CheckFontInfo(doc, xref): # check again: document already has this font + return xref # we are done + + # need to create document font info + doc.getCharWidths(xref) + return xref - if val: - xref = val[0] - f = CheckFont(self, fontname) - if f is not None: - val[1]["type"] = f[2] # put /Subtype in font info - val[1]["glyphs"] = None - doc = self.parent # now add to document font info - fi = CheckFontInfo(doc, xref) - if fi is None: # look if we are already present - doc.FontInfos.append(val) # no: add me to document object - return xref - def _insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering): - """_insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering) -> PyObject *""" - return _fitz.Page__insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering) + def _insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering): + """_insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering) -> PyObject *""" + return _fitz.Page__insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering) def _getContents(self): diff --git a/fitz/fitz_wrap.c b/fitz/fitz_wrap.c index aa079bc55..b5cceaa92 100644 --- a/fitz/fitz_wrap.c +++ b/fitz/fitz_wrap.c @@ -11667,12 +11667,12 @@ SWIGINTERN PyObject *fz_page_s_insertImage(struct fz_page_s *self,PyObject *rect pdf->dirty = 1; return NONE; } -SWIGINTERN PyObject *fz_page_s__insertFont(struct fz_page_s *self,char const *fontname,char const *bfname,char const *fontfile,PyObject *fontbuffer,int set_simple,int idx,int wmode,int style,int serif,int encoding,int ordering){ +SWIGINTERN PyObject *fz_page_s__insertFont(struct fz_page_s *self,char *fontname,char *bfname,char *fontfile,PyObject *fontbuffer,int set_simple,int idx,int wmode,int serif,int encoding,int ordering){ pdf_page *page = pdf_page_from_fz_page(gctx, self); pdf_document *pdf; pdf_obj *resources, *fonts, *font_obj; fz_font *font; - const char *data = NULL; + char *data = NULL; int size, ixref = 0, index = 0, simple = 0; PyObject *info, *value; PyObject *exto = NULL; @@ -11692,23 +11692,20 @@ SWIGINTERN PyObject *fz_page_s__insertFont(struct fz_page_s *self,char const *fo //------------------------------------------------------------- // check for CJK font //------------------------------------------------------------- - if (ordering > -1) + if (ordering > -1) data = fz_lookup_cjk_font(gctx, ordering, &size, &index); + if (data) { - data = fz_lookup_cjk_font(gctx, ordering, &size, &index); - if (data) - { - font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); - font_obj = pdf_add_cjk_font(gctx, pdf, font, ordering, wmode, serif); - exto = Py_BuildValue("s", "n/a"); - simple = 0; - goto weiter; - } + font = fz_new_font_from_memory(gctx, NULL, data, size, index, 0); + font_obj = pdf_add_cjk_font(gctx, pdf, font, ordering, wmode, serif); + exto = Py_BuildValue("s", "n/a"); + simple = 0; + goto weiter; } //------------------------------------------------------------- // check for PDF Base-14 font //------------------------------------------------------------- - data = fz_lookup_base14_font(gctx, bfname, &size); + if (bfname) data = fz_lookup_base14_font(gctx, bfname, &size); if (data) { font = fz_new_font_from_memory(gctx, bfname, data, size, 0, 0); @@ -11718,17 +11715,16 @@ SWIGINTERN PyObject *fz_page_s__insertFont(struct fz_page_s *self,char const *fo goto weiter; } - if (!fontfile && !fontbuffer) THROWMSG("unknown Base-14 or CJK font"); if (fontfile) font = fz_new_font_from_file(gctx, NULL, fontfile, idx, 0); else { - if (!PyBytes_Check(fontbuffer)) THROWMSG("fontbuffer must be bytes"); - data = PyBytes_AsString(fontbuffer); - size = PyBytes_Size(fontbuffer); + size = (int) JM_CharFromBytesOrArray(fontbuffer, &data); + if (!size) THROWMSG("one of fontfile, fontbuffer must be given"); font = fz_new_font_from_memory(gctx, NULL, data, size, idx, 0); } - if (set_simple == 0) + + if (!set_simple) { font_obj = pdf_add_cid_font(gctx, pdf, font); simple = 0; @@ -11738,7 +11734,7 @@ SWIGINTERN PyObject *fz_page_s__insertFont(struct fz_page_s *self,char const *fo font_obj = pdf_add_simple_font(gctx, pdf, font, encoding); simple = 2; } - + weiter: ; ixref = pdf_to_num(gctx, font_obj); @@ -11753,13 +11749,14 @@ SWIGINTERN PyObject *fz_page_s__insertFont(struct fz_page_s *self,char const *fo value = Py_BuildValue("[i, {s:O, s:O, s:O, s:O, s:i}]", ixref, - "name", name, - "type", subt, - "ext", exto, - "simple", JM_BOOL(simple), - "ordering", ordering); + "name", name, // base font name + "type", subt, // subtype + "ext", exto, // file extension + "simple", JM_BOOL(simple), // simple font? + "ordering", ordering); // CJK font? Py_CLEAR(exto); Py_CLEAR(name); + Py_CLEAR(subt); // resources and fonts objects will contain named reference to font pdf_dict_puts(gctx, fonts, fontname, font_obj); @@ -17043,7 +17040,6 @@ SWIGINTERN PyObject *_wrap_Page__insertFont(PyObject *SWIGUNUSEDPARM(self), PyOb int arg9 ; int arg10 ; int arg11 ; - int arg12 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -17067,8 +17063,6 @@ SWIGINTERN PyObject *_wrap_Page__insertFont(PyObject *SWIGUNUSEDPARM(self), PyOb int ecode10 = 0 ; int val11 ; int ecode11 = 0 ; - int val12 ; - int ecode12 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; @@ -17080,10 +17074,9 @@ SWIGINTERN PyObject *_wrap_Page__insertFont(PyObject *SWIGUNUSEDPARM(self), PyOb PyObject * obj8 = 0 ; PyObject * obj9 = 0 ; PyObject * obj10 = 0 ; - PyObject * obj11 = 0 ; PyObject *result = 0 ; - if (!PyArg_ParseTuple(args,(char *)"OOOOOOOOOOOO:Page__insertFont",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6,&obj7,&obj8,&obj9,&obj10,&obj11)) SWIG_fail; + if (!PyArg_ParseTuple(args,(char *)"OOOOOOOOOOO:Page__insertFont",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6,&obj7,&obj8,&obj9,&obj10)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_fz_page_s, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Page__insertFont" "', argument " "1"" of type '" "struct fz_page_s *""'"); @@ -17091,17 +17084,17 @@ SWIGINTERN PyObject *_wrap_Page__insertFont(PyObject *SWIGUNUSEDPARM(self), PyOb arg1 = (struct fz_page_s *)(argp1); res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Page__insertFont" "', argument " "2"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Page__insertFont" "', argument " "2"" of type '" "char *""'"); } arg2 = (char *)(buf2); res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Page__insertFont" "', argument " "3"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Page__insertFont" "', argument " "3"" of type '" "char *""'"); } arg3 = (char *)(buf3); res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "Page__insertFont" "', argument " "4"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "Page__insertFont" "', argument " "4"" of type '" "char *""'"); } arg4 = (char *)(buf4); arg5 = obj4; @@ -17135,13 +17128,8 @@ SWIGINTERN PyObject *_wrap_Page__insertFont(PyObject *SWIGUNUSEDPARM(self), PyOb SWIG_exception_fail(SWIG_ArgError(ecode11), "in method '" "Page__insertFont" "', argument " "11"" of type '" "int""'"); } arg11 = (int)(val11); - ecode12 = SWIG_AsVal_int(obj11, &val12); - if (!SWIG_IsOK(ecode12)) { - SWIG_exception_fail(SWIG_ArgError(ecode12), "in method '" "Page__insertFont" "', argument " "12"" of type '" "int""'"); - } - arg12 = (int)(val12); { - result = (PyObject *)fz_page_s__insertFont(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12); + result = (PyObject *)fz_page_s__insertFont(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11); if(!result) { PyErr_SetString(PyExc_RuntimeError, fz_caught_message(gctx)); @@ -21490,7 +21478,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Page__cleanContents", _wrap_Page__cleanContents, METH_VARARGS, (char *)"Page__cleanContents(self) -> PyObject *"}, { (char *)"Page__showPDFpage", _wrap_Page__showPDFpage, METH_VARARGS, (char *)"Page__showPDFpage(self, rect, docsrc, pno=0, overlay=1, keep_proportion=1, reuse_xref=0, clip=None, graftmap=None, _imgname=None) -> PyObject *"}, { (char *)"Page_insertImage", _wrap_Page_insertImage, METH_VARARGS, (char *)"Insert a new image into a rectangle."}, - { (char *)"Page__insertFont", _wrap_Page__insertFont, METH_VARARGS, (char *)"Page__insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, style, serif, encoding, ordering) -> PyObject *"}, + { (char *)"Page__insertFont", _wrap_Page__insertFont, METH_VARARGS, (char *)"Page__insertFont(self, fontname, bfname, fontfile, fontbuffer, set_simple, idx, wmode, serif, encoding, ordering) -> PyObject *"}, { (char *)"Page__getContents", _wrap_Page__getContents, METH_VARARGS, (char *)"Page__getContents(self) -> PyObject *"}, { (char *)"Page__setContents", _wrap_Page__setContents, METH_VARARGS, (char *)"Set the /Contents object in page definition"}, { (char *)"Page_swigregister", Page_swigregister, METH_VARARGS, NULL}, diff --git a/fitz/helper-python.i b/fitz/helper-python.i index 30cfa3dc0..50a347232 100644 --- a/fitz/helper-python.i +++ b/fitz/helper-python.i @@ -53,9 +53,8 @@ STAMP_TopSecret = 12 STAMP_Draft = 13 #------------------------------------------------------------------------------ -# Base 14 font names +# Base 14 font names and dictionary #------------------------------------------------------------------------------ - Base14_fontnames = ("Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique", "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique", @@ -81,8 +80,115 @@ Base14_fontdict["symb"] = "Symbol" Base14_fontdict["zadb"] = "ZapfDingbats" #------------------------------------------------------------------------------ -# Emulate old linkDest class +# Glyph list for the built-in font 'ZapfDingbats' +#------------------------------------------------------------------------------ +zapf_glyphs = ( + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (33, 0.974), (34, 0.961), (35, 0.974), + (36, 0.98), (37, 0.719), (38, 0.789), (39, 0.79), (40, 0.791), (41, 0.69), + (42, 0.96), (43, 0.939), (44, 0.549), (45, 0.855), (46, 0.911), (47, 0.933), + (48, 0.911), (49, 0.945), (50, 0.974), (51, 0.755), (52, 0.846), (53, 0.762), + (54, 0.761), (55, 0.571), (56, 0.677), (57, 0.763), (58, 0.76), (59, 0.759), + (60, 0.754), (61, 0.494), (62, 0.552), (63, 0.537), (64, 0.577), (65, 0.692), + (66, 0.786), (67, 0.788), (68, 0.788), (69, 0.79), (70, 0.793), (71, 0.794), + (72, 0.816), (73, 0.823), (74, 0.789), (75, 0.841), (76, 0.823), (77, 0.833), + (78, 0.816), (79, 0.831), (80, 0.923), (81, 0.744), (82, 0.723), (83, 0.749), + (84, 0.79), (85, 0.792), (86, 0.695), (87, 0.776), (88, 0.768), (89, 0.792), + (90, 0.759), (91, 0.707), (92, 0.708), (93, 0.682), (94, 0.701), (95, 0.826), + (96, 0.815), (97, 0.789), (98, 0.789), (99, 0.707), (100, 0.687), (101, 0.696), + (102, 0.689), (103, 0.786), (104, 0.787), (105, 0.713), (106, 0.791), + (107, 0.785), (108, 0.791), (109, 0.873), (110, 0.761), (111, 0.762), + (112, 0.762), (113, 0.759), (114, 0.759), (115, 0.892), (116, 0.892), + (117, 0.788), (118, 0.784), (119, 0.438), (120, 0.138), (121, 0.277), + (122, 0.415), (123, 0.392), (124, 0.392), (125, 0.668), (126, 0.668), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), + (32, 0.278), (32, 0.278), (32, 0.278), (32, 0.278), (161, 0.732), (162, 0.544), + (163, 0.544), (164, 0.91), (165, 0.667), (166, 0.76), (167, 0.76), + (168, 0.776), (169, 0.595), (170, 0.694), (171, 0.626), (172, 0.788), + (173, 0.788), (174, 0.788), (175, 0.788), (176, 0.788), (177, 0.788), + (178, 0.788), (179, 0.788), (180, 0.788), (181, 0.788), (182, 0.788), + (183, 0.788), (184, 0.788), (185, 0.788), (186, 0.788), (187, 0.788), + (188, 0.788), (189, 0.788), (190, 0.788), (191, 0.788), (192, 0.788), + (193, 0.788), (194, 0.788), (195, 0.788), (196, 0.788), (197, 0.788), + (198, 0.788), (199, 0.788), (200, 0.788), (201, 0.788), (202, 0.788), + (203, 0.788), (204, 0.788), (205, 0.788), (206, 0.788), (207, 0.788), + (208, 0.788), (209, 0.788), (210, 0.788), (211, 0.788), (212, 0.894), + (213, 0.838), (214, 1.016), (215, 0.458), (216, 0.748), (217, 0.924), + (218, 0.748), (219, 0.918), (220, 0.927), (221, 0.928), (222, 0.928), + (223, 0.834), (224, 0.873), (225, 0.828), (226, 0.924), (227, 0.924), + (228, 0.917), (229, 0.93), (230, 0.931), (231, 0.463), (232, 0.883), + (233, 0.836), (234, 0.836), (235, 0.867), (236, 0.867), (237, 0.696), + (238, 0.696), (239, 0.874), (32, 0.278), (241, 0.874), (242, 0.76), + (243, 0.946), (244, 0.771), (245, 0.865), (246, 0.771), (247, 0.888), + (248, 0.967), (249, 0.888), (250, 0.831), (251, 0.873), (252, 0.927), + (253, 0.97), (32, 0.278), (32, 0.278) + ) + +#------------------------------------------------------------------------------ +# Glyph list for the built-in font 'Symbol' #------------------------------------------------------------------------------ +symbol_glyphs = ( + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (32, 0.25), (33, 0.333), (34, 0.713), + (35, 0.5), (36, 0.549), (37, 0.833), (38, 0.778), (39, 0.439), + (40, 0.333), (41, 0.333), (42, 0.5), (43, 0.549), (44, 0.25), (45, 0.549), + (46, 0.25), (47, 0.278), (48, 0.5), (49, 0.5), (50, 0.5), (51, 0.5), + (52, 0.5), (53, 0.5), (54, 0.5), (55, 0.5), (56, 0.5), (57, 0.5), + (58, 0.278), (59, 0.278), (60, 0.549), (61, 0.549), (62, 0.549), + (63, 0.444), (64, 0.549), (65, 0.722), (66, 0.667), (67, 0.722), + (68, 0.612), (69, 0.611), (70, 0.763), (71, 0.603), (72, 0.722), + (73, 0.333), (74, 0.631), (75, 0.722), (76, 0.686), (77, 0.889), + (78, 0.722), (79, 0.722), (80, 0.768), (81, 0.741), (82, 0.556), + (83, 0.592), (84, 0.611), (85, 0.69), (86, 0.439), (87, 0.768), + (88, 0.645), (89, 0.795), (90, 0.611), (91, 0.333), (92, 0.863), + (93, 0.333), (94, 0.658), (95, 0.5), (96, 0.5), (97, 0.631), (98, 0.549), + (99, 0.549), (100, 0.494), (101, 0.439), (102, 0.521), (103, 0.411), + (104, 0.603), (105, 0.329), (106, 0.603), (107, 0.549), (108, 0.549), + (109, 0.576), (110, 0.521), (111, 0.549), (112, 0.549), (113, 0.521), + (114, 0.549), (115, 0.603), (116, 0.439), (117, 0.576), (118, 0.713), + (119, 0.686), (120, 0.493), (121, 0.686), (122, 0.494), (123, 0.48), + (124, 0.2), (125, 0.48), (126, 0.549), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), (63, 0.444), + (63, 0.444), (160, 0.25), (161, 0.62), (162, 0.247), (163, 0.549), + (164, 0.167), (165, 0.713), (166, 0.5), (167, 0.753), (168, 0.753), + (169, 0.753), (170, 0.753), (171, 1.042), (172, 0.713), (173, 0.603), + (174, 0.987), (175, 0.603), (176, 0.4), (177, 0.549), (178, 0.411), + (179, 0.549), (180, 0.549), (181, 0.576), (182, 0.494), (183, 0.46), + (184, 0.549), (185, 0.549), (186, 0.549), (187, 0.549), (188, 1), + (189, 0.603), (190, 1), (191, 0.658), (192, 0.823), (193, 0.686), + (194, 0.795), (195, 0.987), (196, 0.768), (197, 0.768), (198, 0.823), + (199, 0.768), (200, 0.768), (201, 0.713), (202, 0.713), (203, 0.713), + (204, 0.713), (205, 0.713), (206, 0.713), (207, 0.713), (208, 0.768), + (209, 0.713), (210, 0.79), (211, 0.79), (212, 0.89), (213, 0.823), + (214, 0.549), (215, 0.549), (216, 0.713), (217, 0.603), (218, 0.603), + (219, 1.042), (220, 0.987), (221, 0.603), (222, 0.987), (223, 0.603), + (224, 0.494), (225, 0.329), (226, 0.79), (227, 0.79), (228, 0.786), + (229, 0.713), (230, 0.384), (231, 0.384), (232, 0.384), (233, 0.384), + (234, 0.384), (235, 0.384), (236, 0.494), (237, 0.494), (238, 0.494), + (239, 0.494), (63, 0.444), (241, 0.329), (242, 0.274), (243, 0.686), + (244, 0.686), (245, 0.686), (246, 0.384), (247, 0.549), (248, 0.384), + (249, 0.384), (250, 0.384), (251, 0.384), (252, 0.494), (253, 0.494), + (254, 0.494), (63, 0.444) + ) + class linkDest(): """link or outline destination details""" def __init__(self, obj, rlink): @@ -200,24 +306,34 @@ def getPDFstr(x): return "(" + r + ")" -#------------------------------------------------------------------------------ -# Return a PDF string suitable for the TJ operator enclosed in "[]" brackets. -# The input string is converted to either 2 or 4 hex digits per character. -# If no glyphs are supplied, then a simple font is assumed and each character -# taken directly. -# Otherwise a char's glyph is taken and 4 hex digits per char are put out. -#------------------------------------------------------------------------------ -def getTJstr(text, glyphs): +def getTJstr(text, glyphs, simple, ordering): + """Return a PDF string enclosed in [] brackets, suitable for the PDF TJ + operator. + The input string is converted to either 2 or 4 hex digits per character. + * simple: + - no glyphs: 2-chars, use char codes as the glyph + - glyphs: 2-chars, use glyphs instead of char codes (Symbol, ZapfDingbats) + * not simple: + - ordering < 0: 4-chars, use glyphs not char codes + - ordering >=0: a CJK font! 4 chars, use char codes as glyphs +""" if text.startswith("[<") and text.endswith(">]"): # already done return text + if not bool(text): return "[<>]" - if glyphs is None: # this is a simple font - otxt = "".join([hex(ord(c))[2:].rjust(2, "0") if ord(c)<256 else "3f" for c in text]) + + if simple: + if glyphs is None: # simple and not Symbol / ZapfDingbats + otxt = "".join([hex(ord(c))[2:].rjust(2, "0") if ord(c)<256 else "3f" for c in text]) + else: # Symbol or ZapfDingbats + otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(2, "0") for c in text]) return "[<" + otxt + ">]" - # this is not a simple font -> take the glyphs of a character - otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(4, "0") for c in text]) + if ordering < 0: # not a CJK font: use the glyphs + otxt = "".join([hex(glyphs[ord(c)][0])[2:].rjust(4, "0") for c in text]) + else: # CJK: use char codes, no glyphs + otxt = "".join([hex(ord(c))[2:].rjust(4, "0") for c in text]) return "[<" + otxt + ">]" @@ -318,23 +434,18 @@ def CheckMorph(o): def CheckFont(page, fontname): """Return an entry in the page's font list if reference name matches. """ - fl = page.getFontList() - refname = None - for f in fl: + for f in page.getFontList(): if f[4] == fontname: - refname = f - break - return refname + return f + return None def CheckFontInfo(doc, xref): """Return a font info if present in the document. """ - fi = None for f in doc.FontInfos: if xref == f[0]: - fi = f - break - return fi + return f + return None def UpdateFontInfo(doc, info): xref = info[0] diff --git a/fitz/utils.py b/fitz/utils.py index ac2c0ed45..1f3b21a92 100644 --- a/fitz/utils.py +++ b/fitz/utils.py @@ -792,7 +792,6 @@ def insertLink(page, lnk, mark = True): def insertTextbox(page, rect, buffer, fontname = "helv", fontfile = None, - idx = 0, set_simple = 0, fontsize = 11, color = (0,0,0), @@ -821,7 +820,6 @@ def insertTextbox(page, rect, buffer, fontsize = fontsize, fontname = fontname, fontfile = fontfile, - idx = idx, set_simple = set_simple, color = color, expandtabs = expandtabs, @@ -839,7 +837,6 @@ def insertText(page, point, text, fontsize = 11, fontname = "helv", fontfile = None, - idx = 0, set_simple = 0, color = (0,0,0), rotate = 0, @@ -851,7 +848,6 @@ def insertText(page, point, text, fontsize = fontsize, fontname = fontname, fontfile = fontfile, - idx = idx, set_simple = set_simple, color = color, rotate = rotate, @@ -1657,25 +1653,60 @@ def getColorHSV(name): # Document.getCharWidths #------------------------------------------------------------------------------ def getCharWidths(doc, xref, limit = 256, idx = 0): + """Get list of glyph information of a font, which must be provided by its + XREF number. If we already dealt with the font, it will be recorded in + doc.FontInfos. Otherwise we insert an entry there. + Finally we return the glyphs for the font. This is a list of (glyph, width) + where glyph is an integer controlling the char appearance, and width is a + float controlling the char's spacing: width * fontsize is the actual space. + For 'simple' fonts, glyph == ord(char) will usually be true. + Exceptions are 'Symbol' and 'ZapfDingbats'. We are providing data for these + directly here. + """ fontinfo = CheckFontInfo(doc, xref) - if fontinfo is None: + if fontinfo is None: # not recorded yet: create it name, ext, stype, _ = doc.extractFont(xref, info_only = True) - glyphs = None fontdict = {"name": name, "type": stype, "ext": ext} + if ext == "": raise ValueError("xref is not a font") + + # check for 'simple' fonts if stype in ("Type1", "MMType1", "TrueType"): simple = True else: simple = False + + # check for CJK fonts + if name in ("Fangti", "Ming"): + ordering = 0 + elif name in ("Heiti", "Song"): + ordering = 1 + elif name in ("Gothic", "Mincho"): + ordering = 2 + elif name in ("Dotum", "Batang"): + ordering = 3 + else: + ordering = -1 + fontdict["simple"] = simple - fontdict["glyphs"] = None + + if name == "ZapfDingbats": + glyphs = zapf_glyphs + elif name == "Symbol": + glyphs = symbol_glyphs + else: + glyphs = None + + fontdict["glyphs"] = glyphs + fontdict["ordering"] = ordering fontinfo = [xref, fontdict] doc.FontInfos.append(fontinfo) else: fontdict = fontinfo[1] glyphs = fontdict["glyphs"] simple = fontdict["simple"] + ordering = fontdict["ordering"] if glyphs is None: oldlimit = 0 @@ -1686,15 +1717,19 @@ def getCharWidths(doc, xref, limit = 256, idx = 0): if mylimit <= oldlimit: return glyphs - - new_glyphs = doc._getCharWidths(xref, fontdict["name"], + + if ordering < 0: # not a CJK font + glyphs = doc._getCharWidths(xref, fontdict["name"], fontdict["ext"], fontdict["ordering"], mylimit, idx) - glyphs = new_glyphs + else: # CJK fonts use char codes and width = 1 + glyphs = None + fontdict["glyphs"] = glyphs fontinfo[1] = fontdict UpdateFontInfo(doc, fontinfo) + return glyphs #------------------------------------------------------------------------------ @@ -2006,13 +2041,12 @@ def insertText(self, point, buffer, fontsize = 11, fontname = "helv", fontfile = None, - idx = 0, set_simple = 0, color = (0,0,0), rotate = 0, morph = None): - # ensure 'text' is a list of strings worth dealing with + # ensure 'text' is a list of strings, worth dealing with if not bool(buffer): return 0 if type(buffer) not in (list, tuple): @@ -2024,37 +2058,30 @@ def insertText(self, point, buffer, return 0 point = Point(point) - maxcode = max([ord(c) for c in "\n".join(text)]) + maxcode = max([ord(c) for c in " ".join(text)]) + # ensure valid 'fontname' - xref = 0 # xref of font object fname = fontname - f = None - if not fname: - fname = "helv" if fname[0] == "/": fname = fname[1:] - f = CheckFont(self.page, fname) - - if f is not None: - xref = f[0] - else: - xref = self.page.insertFont(fontname = fname, fontfile = fontfile, - set_simple = set_simple, idx = idx) - f = CheckFont(self.page, fname) - - assert xref > 0, "invalid fontname" - basename, ext, stype, _ = self.doc.extractFont(xref, info_only = True) - simple = True if stype in ("Type1", "TrueType", "MMType1") else False - # decide how text is presented to PDF: - # simple fonts: use the chars directly in PDF operators - # cid fonts: use glyph number of each character - glyphs = None - if not simple: - glyphs = self.doc.getCharWidths(xref, limit = maxcode+1) - + + xref = self.page.insertFont(fontname = fname, fontfile = fontfile, + set_simple = set_simple) + fontinfo = CheckFontInfo(self.doc, xref) + + fontdict = fontinfo[1] + ordering = fontdict["ordering"] + simple = fontdict["simple"] + glyphs = fontdict["glyphs"] + bfname = fontdict["name"] + tab = [] for t in text: - tab.append(getTJstr(t, glyphs)) + if simple and bfname not in ("Symbol", "ZapfDingbats"): + g = None + else: + g = glyphs + tab.append(getTJstr(t, g, simple, ordering)) text = tab CheckColor(color) @@ -2139,7 +2166,7 @@ def insertText(self, point, buffer, # Shape.insertTextbox #============================================================================== def insertTextbox(self, rect, buffer, fontname = "helv", fontfile = None, - fontsize = 11, idx = 0, set_simple = 0, + fontsize = 11, set_simple = 0, color = (0,0,0), expandtabs = 1, align = 0, rotate = 0, morph = None): """Insert text into a given rectangle. Arguments: @@ -2173,27 +2200,20 @@ def insertTextbox(self, rect, buffer, fontname = "helv", fontfile = None, cmm90 = "0 -1 1 0 0 0 cm\n" # rotates clockwise cm180 = "-1 0 0 -1 0 0 cm\n" # rotates by 180 deg. height = self.height - xref = 0 # xref of font object + fname = fontname - f = None - if not fname: - fname = "helv" - if fname[0] == "/": + if fname.startswith("/"): fname = fname[1:] - f = CheckFont(self.page, fname) - if f is None: - raise ValueError("invalid font reference " + fname) - - if f is not None: - xref = f[0] - else: - xref = self.page.insertFont(fontname = fname, fontfile = fontfile, - set_simple = set_simple, idx = idx) - f = CheckFont(self.page, fname) - assert xref > 0, "invalid fontname" - basename, ext, stype, _ = self.doc.extractFont(xref, info_only = True) - simple = True if stype in ("Type1", "TrueType", "MMType1") else False + xref = self.page.insertFont(fontname = fname, fontfile = fontfile, + set_simple = set_simple) + fontinfo = CheckFontInfo(self.doc, xref) + + fontdict = fontinfo[1] + ordering = fontdict["ordering"] + simple = fontdict["simple"] + glyphs = fontdict["glyphs"] + bfname = fontdict["name"] # create a list from buffer, split into its lines if type(buffer) in (list, tuple): @@ -2208,17 +2228,29 @@ def insertTextbox(self, rect, buffer, fontname = "helv", fontfile = None, t0 = t0.splitlines() - widthtab = self.doc.getCharWidths(xref, maxcode + 1) - + glyphs = self.doc.getCharWidths(xref, maxcode + 1) + if simple and bfname not in ("Symbol", "ZapfDingbats"): + tj_glyphs = None + else: + tj_glyphs = glyphs + + #---------------------------------------------------------------------- # calculate pixel length of a string #---------------------------------------------------------------------- def pixlen(x): """Calculate pixel length of x.""" - return sum([widthtab[ord(c)][1] for c in x]) * fontsize + if ordering < 0: + return sum([glyphs[ord(c)][1] for c in x]) * fontsize + else: + return len(x) * fontsize #---------------------------------------------------------------------- - blen = widthtab[32][1] * fontsize # pixel size of space character + if ordering < 0: + blen = glyphs[32][1] * fontsize # pixel size of space character + else: + blen = fontsize + text = "" # output buffer lheight = fontsize * 1.2 # line height if CheckMorph(morph): @@ -2270,10 +2302,6 @@ def pixlen(x): # line loop #======================================================================= just_tab = [] # 'justify' indicators per line - if simple: - glyphs = None - else: - glyphs = widthtab # indicator for getTJstr()! for i, line in enumerate(t0): line_t = line.expandtabs(expandtabs).split(" ") # split into words @@ -2364,7 +2392,7 @@ def pixlen(x): left = -pnt.x - self.x top = -height + pnt.y + self.y nres += templ % (left, top, fname, fontsize, - spacing, red, green, blue, getTJstr(t, glyphs)) + spacing, red, green, blue, getTJstr(t, tj_glyphs, simple, ordering)) nres += "ET Q\n" self.totalcont += nres diff --git a/fitz/version.i b/fitz/version.i index 36138c96d..464c99f54 100644 --- a/fitz/version.i +++ b/fitz/version.i @@ -1,6 +1,6 @@ %pythoncode %{ VersionFitz = "1.14.0" VersionBind = "1.14.3" -VersionDate = "2018-11-29 05:23:32" -version = (VersionBind, VersionFitz, "20181129052332") +VersionDate = "2018-12-01 18:33:20" +version = (VersionBind, VersionFitz, "20181201183320") %} \ No newline at end of file From 51e81c72af703b03ae648ac53b833ea8a888447e Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Sun, 2 Dec 2018 15:29:29 -0400 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0b959d78..81139cbaf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![logo](https://github.com/rk700/PyMuPDF/blob/master/demo/pymupdf.jpg) -Release date: November 15, 2018 +Release date: December 2, 2018 **Travis-CI:** [![Build Status](https://travis-ci.org/JorjMcKie/py-mupdf.svg?branch=master)](https://travis-ci.org/JorjMcKie/py-mupdf)