@@ -231,7 +231,7 @@ struct fz_document_s
231231 elif type (stream) is io.BytesIO :
232232 self.stream = stream.getvalue ()
233233 else :
234- raise ValueError (" 'stream' has bad type" )
234+ raise ValueError (" bad type: 'stream' " )
235235 stream = self.stream
236236 else :
237237 self.stream = None
@@ -523,7 +523,7 @@ struct fz_document_s
523523 if (!filespec) THROWMSG("bad PDF: /EF object not found");
524524
525525 res = JM_BufferFromBytes(gctx, buffer);
526- if (buffer && !res) THROWMSG("' buffer ' has bad type");
526+ if (buffer && !res) THROWMSG("bad type: ' buffer ' ");
527527 if (res)
528528 {
529529 JM_update_stream(gctx, pdf, filespec, res);
@@ -605,7 +605,7 @@ if self.isClosed or self.isEncrypted:
605605 {
606606 assert_PDF(pdf);
607607 data = JM_BufferFromBytes(gctx, buffer);
608- if (!data) THROWMSG("bad type ' buffer' ");
608+ if (!data) THROWMSG("bad type: ' buffer' ");
609609 size = fz_buffer_storage(gctx, data, &buffdata);
610610
611611 // we do not allow duplicate names
@@ -1710,7 +1710,7 @@ if links:
17101710 //---------------------------------------------------------------------
17111711 FITZEXCEPTION(_getXrefString, !result)
17121712 CLOSECHECK0(_getXrefString)
1713- PyObject *_getXrefString(int xref)
1713+ PyObject *_getXrefString(int xref, int compressed=1 )
17141714 {
17151715 pdf_document *pdf = pdf_specifics(gctx, $self); // conv doc to pdf
17161716 pdf_obj *obj = NULL;
@@ -1726,7 +1726,7 @@ if links:
17261726 res = fz_new_buffer(gctx, 1024);
17271727 out = fz_new_output_with_buffer(gctx, res);
17281728 obj = pdf_load_object(gctx, pdf, xref);
1729- pdf_print_obj(gctx, out, pdf_resolve_indirect(gctx, obj), 1 );
1729+ pdf_print_obj(gctx, out, pdf_resolve_indirect(gctx, obj), compressed );
17301730 text = JM_StrFromBuffer(gctx, res);
17311731 }
17321732 fz_always(gctx)
@@ -1744,7 +1744,7 @@ if links:
17441744 //---------------------------------------------------------------------
17451745 FITZEXCEPTION(_getTrailerString, !result)
17461746 CLOSECHECK0(_getTrailerString)
1747- PyObject *_getTrailerString()
1747+ PyObject *_getTrailerString(int compressed=1 )
17481748 {
17491749 pdf_document *pdf = pdf_specifics(gctx, $self); // conv doc to pdf
17501750 if (!pdf) return NONE;
@@ -1759,7 +1759,7 @@ if links:
17591759 {
17601760 res = fz_new_buffer(gctx, 1024);
17611761 out = fz_new_output_with_buffer(gctx, res);
1762- pdf_print_obj(gctx, out, obj, 1 );
1762+ pdf_print_obj(gctx, out, obj, compressed );
17631763 text = JM_StrFromBuffer(gctx, res);
17641764 }
17651765 else text = NONE;
@@ -1863,7 +1863,7 @@ if links:
18631863 if (!new && !pdf_is_stream(gctx, obj))
18641864 THROWMSG("xref not a stream object");
18651865 res = JM_BufferFromBytes(gctx, stream);
1866- if (!res) THROWMSG("stream must be bytes or bytearray ");
1866+ if (!res) THROWMSG("bad type: ' stream ' ");
18671867 JM_update_stream(gctx, pdf, obj, res);
18681868
18691869 }
@@ -2318,7 +2318,7 @@ struct fz_page_s {
23182318 {
23192319 assert_PDF(page);
23202320 filebuf = JM_BufferFromBytes(gctx, buffer);
2321- if (!filebuf) THROWMSG(" bad ' buffer' data " );
2321+ if (!filebuf) THROWMSG(" bad type: ' buffer' " );
23222322 annot = pdf_create_annot(gctx, page, ANNOT_FILEATTACHMENT);
23232323 pdf_set_annot_rect(gctx, annot, r);
23242324 pdf_set_annot_icon_name(gctx, annot, " PushPin" );
@@ -3036,7 +3036,7 @@ fannot._erase()
30363036 //---------------------------------------------------------------------
30373037 FITZEXCEPTION(_insertImage, !result)
30383038 PyObject *_insertImage(const char *filename=NULL, struct fz_pixmap_s *pixmap=NULL, PyObject *stream=NULL, int overlay=1, PyObject *matrix=NULL,
3039- const char *_imgname=NULL)
3039+ const char *_imgname=NULL, PyObject *_imgpointer=NULL )
30403040 {
30413041 pdf_page *page = pdf_page_from_fz_page(gctx, $self);
30423042 pdf_document *pdf;
@@ -3057,16 +3057,27 @@ fannot._erase()
30573057 //-------------------------------------------------------------
30583058 // create the image
30593059 //-------------------------------------------------------------
3060- if (filename || stream)
3060+ if (filename ||
3061+ (stream && stream != NONE) ||
3062+ (_imgpointer && _imgpointer != NONE))
30613063 {
3064+
30623065 if (filename)
3066+ {
30633067 image = fz_new_image_from_file(gctx, filename);
3064- else
3068+ }
3069+
3070+ else if (stream && stream != NONE)
30653071 {
30663072 imgbuf = JM_BufferFromBytes(gctx, stream);
30673073 image = fz_new_image_from_buffer(gctx, imgbuf);
30683074 }
30693075
3076+ else // fz_image pointer has been handed in
3077+ {
3078+ image = (fz_image *)PyLong_AsVoidPtr(_imgpointer);
3079+ }
3080+
30703081 // test for alpha (which would require making an SMask)
30713082 pix = fz_get_pixmap_from_image(gctx, image, NULL, NULL, 0, 0);
30723083 if (pix->alpha == 1)
@@ -3802,7 +3813,7 @@ struct fz_pixmap_s
38023813 if (data && data_len < w * h)
38033814 THROWMSG(" not enough alpha values" );
38043815 }
3805- else THROWMSG(" bad type ' alphavalues' " );
3816+ else THROWMSG(" bad type: ' alphavalues' " );
38063817 }
38073818 int i = 0, k = 0;
38083819 while (i < balen)
@@ -5207,7 +5218,7 @@ CheckParent(self)
52075218
52085219 // file content given
52095220 res = JM_BufferFromBytes(gctx, buffer);
5210- if (buffer && !res) THROWMSG(" ' buffer ' has bad type" );
5221+ if (buffer && !res) THROWMSG(" bad type: ' buffer ' " );
52115222 if (res)
52125223 {
52135224 JM_update_stream(gctx, pdf, stream, res);
@@ -6294,9 +6305,9 @@ struct Tools
62946305 }
62956306
62966307 %feature(" autodoc" ," Determine dimension and other image data." ) image_size;
6297- PyObject *image_size(PyObject *imagedata)
6308+ PyObject *image_size(PyObject *imagedata, int keep_image=0 )
62986309 {
6299- return JM_image_size(gctx, imagedata);
6310+ return JM_image_size(gctx, imagedata, keep_image );
63006311 }
63016312
63026313 %feature(" autodoc" ," Current store size." ) store_size;
@@ -6339,8 +6350,8 @@ struct Tools
63396350 xref = JM_insert_contents(gctx, page->doc, page->obj, contbuf, overlay);
63406351 page->doc->dirty = 1;
63416352 }
6342- fz_always(gctx) fz_drop_buffer(gctx, contbuf);
6343- fz_catch(gctx) return NULL;
6353+ fz_always(gctx) { fz_drop_buffer(gctx, contbuf);}
6354+ fz_catch(gctx) { return NULL;}
63446355 return Py_BuildValue(" i" , xref);
63456356 }
63466357
0 commit comments