@@ -231,7 +231,7 @@ struct fz_document_s
231
231
elif type (stream) is io.BytesIO :
232
232
self.stream = stream.getvalue ()
233
233
else :
234
- raise ValueError (" 'stream' has bad type" )
234
+ raise ValueError (" bad type: 'stream' " )
235
235
stream = self.stream
236
236
else :
237
237
self.stream = None
@@ -523,7 +523,7 @@ struct fz_document_s
523
523
if (!filespec) THROWMSG("bad PDF: /EF object not found");
524
524
525
525
res = JM_BufferFromBytes(gctx, buffer);
526
- if (buffer && !res) THROWMSG("' buffer ' has bad type");
526
+ if (buffer && !res) THROWMSG("bad type: ' buffer ' ");
527
527
if (res)
528
528
{
529
529
JM_update_stream(gctx, pdf, filespec, res);
@@ -605,7 +605,7 @@ if self.isClosed or self.isEncrypted:
605
605
{
606
606
assert_PDF(pdf);
607
607
data = JM_BufferFromBytes(gctx, buffer);
608
- if (!data) THROWMSG("bad type ' buffer' ");
608
+ if (!data) THROWMSG("bad type: ' buffer' ");
609
609
size = fz_buffer_storage(gctx, data, &buffdata);
610
610
611
611
// we do not allow duplicate names
@@ -1710,7 +1710,7 @@ if links:
1710
1710
//---------------------------------------------------------------------
1711
1711
FITZEXCEPTION(_getXrefString, !result)
1712
1712
CLOSECHECK0(_getXrefString)
1713
- PyObject *_getXrefString(int xref)
1713
+ PyObject *_getXrefString(int xref, int compressed=1 )
1714
1714
{
1715
1715
pdf_document *pdf = pdf_specifics(gctx, $self); // conv doc to pdf
1716
1716
pdf_obj *obj = NULL;
@@ -1726,7 +1726,7 @@ if links:
1726
1726
res = fz_new_buffer(gctx, 1024);
1727
1727
out = fz_new_output_with_buffer(gctx, res);
1728
1728
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 );
1730
1730
text = JM_StrFromBuffer(gctx, res);
1731
1731
}
1732
1732
fz_always(gctx)
@@ -1744,7 +1744,7 @@ if links:
1744
1744
//---------------------------------------------------------------------
1745
1745
FITZEXCEPTION(_getTrailerString, !result)
1746
1746
CLOSECHECK0(_getTrailerString)
1747
- PyObject *_getTrailerString()
1747
+ PyObject *_getTrailerString(int compressed=1 )
1748
1748
{
1749
1749
pdf_document *pdf = pdf_specifics(gctx, $self); // conv doc to pdf
1750
1750
if (!pdf) return NONE;
@@ -1759,7 +1759,7 @@ if links:
1759
1759
{
1760
1760
res = fz_new_buffer(gctx, 1024);
1761
1761
out = fz_new_output_with_buffer(gctx, res);
1762
- pdf_print_obj(gctx, out, obj, 1 );
1762
+ pdf_print_obj(gctx, out, obj, compressed );
1763
1763
text = JM_StrFromBuffer(gctx, res);
1764
1764
}
1765
1765
else text = NONE;
@@ -1863,7 +1863,7 @@ if links:
1863
1863
if (!new && !pdf_is_stream(gctx, obj))
1864
1864
THROWMSG("xref not a stream object");
1865
1865
res = JM_BufferFromBytes(gctx, stream);
1866
- if (!res) THROWMSG("stream must be bytes or bytearray ");
1866
+ if (!res) THROWMSG("bad type: ' stream ' ");
1867
1867
JM_update_stream(gctx, pdf, obj, res);
1868
1868
1869
1869
}
@@ -2318,7 +2318,7 @@ struct fz_page_s {
2318
2318
{
2319
2319
assert_PDF(page);
2320
2320
filebuf = JM_BufferFromBytes(gctx, buffer);
2321
- if (!filebuf) THROWMSG(" bad ' buffer' data " );
2321
+ if (!filebuf) THROWMSG(" bad type: ' buffer' " );
2322
2322
annot = pdf_create_annot(gctx, page, ANNOT_FILEATTACHMENT);
2323
2323
pdf_set_annot_rect(gctx, annot, r);
2324
2324
pdf_set_annot_icon_name(gctx, annot, " PushPin" );
@@ -3036,7 +3036,7 @@ fannot._erase()
3036
3036
//---------------------------------------------------------------------
3037
3037
FITZEXCEPTION(_insertImage, !result)
3038
3038
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 )
3040
3040
{
3041
3041
pdf_page *page = pdf_page_from_fz_page(gctx, $self);
3042
3042
pdf_document *pdf;
@@ -3057,16 +3057,27 @@ fannot._erase()
3057
3057
//-------------------------------------------------------------
3058
3058
// create the image
3059
3059
//-------------------------------------------------------------
3060
- if (filename || stream)
3060
+ if (filename ||
3061
+ (stream && stream != NONE) ||
3062
+ (_imgpointer && _imgpointer != NONE))
3061
3063
{
3064
+
3062
3065
if (filename)
3066
+ {
3063
3067
image = fz_new_image_from_file(gctx, filename);
3064
- else
3068
+ }
3069
+
3070
+ else if (stream && stream != NONE)
3065
3071
{
3066
3072
imgbuf = JM_BufferFromBytes(gctx, stream);
3067
3073
image = fz_new_image_from_buffer(gctx, imgbuf);
3068
3074
}
3069
3075
3076
+ else // fz_image pointer has been handed in
3077
+ {
3078
+ image = (fz_image *)PyLong_AsVoidPtr(_imgpointer);
3079
+ }
3080
+
3070
3081
// test for alpha (which would require making an SMask)
3071
3082
pix = fz_get_pixmap_from_image(gctx, image, NULL, NULL, 0, 0);
3072
3083
if (pix->alpha == 1)
@@ -3802,7 +3813,7 @@ struct fz_pixmap_s
3802
3813
if (data && data_len < w * h)
3803
3814
THROWMSG(" not enough alpha values" );
3804
3815
}
3805
- else THROWMSG(" bad type ' alphavalues' " );
3816
+ else THROWMSG(" bad type: ' alphavalues' " );
3806
3817
}
3807
3818
int i = 0, k = 0;
3808
3819
while (i < balen)
@@ -5207,7 +5218,7 @@ CheckParent(self)
5207
5218
5208
5219
// file content given
5209
5220
res = JM_BufferFromBytes(gctx, buffer);
5210
- if (buffer && !res) THROWMSG(" ' buffer ' has bad type" );
5221
+ if (buffer && !res) THROWMSG(" bad type: ' buffer ' " );
5211
5222
if (res)
5212
5223
{
5213
5224
JM_update_stream(gctx, pdf, stream, res);
@@ -6294,9 +6305,9 @@ struct Tools
6294
6305
}
6295
6306
6296
6307
%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 )
6298
6309
{
6299
- return JM_image_size(gctx, imagedata);
6310
+ return JM_image_size(gctx, imagedata, keep_image );
6300
6311
}
6301
6312
6302
6313
%feature(" autodoc" ," Current store size." ) store_size;
@@ -6339,8 +6350,8 @@ struct Tools
6339
6350
xref = JM_insert_contents(gctx, page->doc, page->obj, contbuf, overlay);
6340
6351
page->doc->dirty = 1;
6341
6352
}
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;}
6344
6355
return Py_BuildValue(" i" , xref);
6345
6356
}
6346
6357
0 commit comments