@@ -1021,65 +1021,21 @@ if links:
1021
1021
return Py_BuildValue("(l, l)", objnum, objgen);
1022
1022
}
1023
1023
1024
- //---------------------------------------------------------------------
1025
- // Returns the list of images used on a page.
1026
- // Each image entry contains
1027
- // [xref, smask, width, height, bpc, colorspace, altcs, name]
1028
- //---------------------------------------------------------------------
1029
- FITZEXCEPTION(getPageImageList, !result)
1030
- CLOSECHECK(getPageImageList)
1031
- %feature("autodoc","Show the images used on a page.") getPageImageList;
1032
- %pythonappend getPageImageList %{
1033
- x = []
1034
- for v in val:
1035
- if v not in x:
1036
- x.append(v)
1037
- val = x%}
1038
- PyObject *getPageImageList(int pno)
1039
- {
1040
- pdf_document *pdf = pdf_specifics(gctx, $self);
1041
- int pageCount = fz_count_pages(gctx, $self);
1042
- pdf_obj *pageref, *rsrc;
1043
- PyObject *imagelist; // returned object
1044
- int n = pno; // pno < 0 is allowed
1045
- while (n < 0) n += pageCount;
1046
- fz_try(gctx)
1047
- {
1048
- if (n >= pageCount) THROWMSG("invalid page number(s)");
1049
- assert_PDF(pdf);
1050
- pageref = pdf_lookup_page_obj(gctx, pdf, n);
1051
- rsrc = pdf_dict_get(gctx, pageref, PDF_NAME_Resources);
1052
- if (!pageref || !rsrc) THROWMSG("cannot retrieve page info");
1053
- imagelist = PyList_New(0);
1054
- JM_imagelist(gctx, pdf, rsrc, imagelist);
1055
- }
1056
- fz_catch(gctx)
1057
- {
1058
- Py_DECREF(imagelist);
1059
- return NULL;
1060
- }
1061
- return imagelist;
1062
- }
1063
-
1064
- //---------------------------------------------------------------------
1065
- // Returns the list of fonts used on a page.
1066
- // Each font entry contains [xref, extension, type, basename, name]
1067
- //---------------------------------------------------------------------
1068
- FITZEXCEPTION(getPageFontList, !result)
1069
- CLOSECHECK(getPageFontList)
1070
- %feature("autodoc","Show the fonts used on a page.") getPageFontList;
1071
- %pythonappend getPageFontList %{
1024
+ FITZEXCEPTION(_getPageInfo, !result)
1025
+ CLOSECHECK(_getPageInfo)
1026
+ %feature("autodoc","Show fonts or images used on a page.") _getPageInfo;
1027
+ %pythonappend _getPageInfo %{
1072
1028
x = []
1073
1029
for v in val:
1074
1030
if v not in x:
1075
1031
x.append(v)
1076
1032
val = x%}
1077
- PyObject *getPageFontList (int pno)
1033
+ PyObject *_getPageInfo (int pno, int what )
1078
1034
{
1079
1035
pdf_document *pdf = pdf_specifics(gctx, $self);
1080
1036
int pageCount = fz_count_pages(gctx, $self);
1081
1037
pdf_obj *pageref, *rsrc;
1082
- PyObject *fontlist; // returned object
1038
+ PyObject *liste; // returned object
1083
1039
int n = pno; // pno < 0 is allowed
1084
1040
while (n < 0) n += pageCount;
1085
1041
fz_try(gctx)
@@ -1089,15 +1045,15 @@ if links:
1089
1045
pageref = pdf_lookup_page_obj(gctx, pdf, n);
1090
1046
rsrc = pdf_dict_get(gctx, pageref, PDF_NAME_Resources);
1091
1047
if (!pageref || !rsrc) THROWMSG("cannot retrieve page info");
1092
- fontlist = PyList_New(0);
1093
- JM_fontlist (gctx, pdf, rsrc, fontlist );
1048
+ liste = PyList_New(0);
1049
+ JM_ScanResources (gctx, pdf, rsrc, liste, what );
1094
1050
}
1095
1051
fz_catch(gctx)
1096
1052
{
1097
- Py_DECREF(fontlist );
1053
+ Py_DECREF(liste );
1098
1054
return NULL;
1099
1055
}
1100
- return fontlist ;
1056
+ return liste ;
1101
1057
}
1102
1058
1103
1059
FITZEXCEPTION(extractFont, !result)
@@ -1461,6 +1417,16 @@ if links:
1461
1417
outline = property(lambda self: self._outline)
1462
1418
_getPageXref = _getPageObjNumber
1463
1419
1420
+ def getPageFontList(self, pno):
1421
+ """Retrieve a list of fonts used on a page.
1422
+ """
1423
+ return self._getPageInfo(pno, 1)
1424
+
1425
+ def getPageImageList(self, pno):
1426
+ """Retrieve a list of images used on a page.
1427
+ """
1428
+ return self._getPageInfo(pno, 2)
1429
+
1464
1430
def saveIncr(self):
1465
1431
""" Save PDF incrementally"""
1466
1432
return self.save(self.name, incremental = True)
@@ -2933,6 +2899,8 @@ struct fz_pixmap_s
2933
2899
fz_pixmap *pm = NULL ;
2934
2900
fz_try (gctx)
2935
2901
{
2902
+ if (!fz_pixmap_colorspace (gctx, spix))
2903
+ THROWMSG (" cannot copy pixmap with NULL colorspace" );
2936
2904
pm = fz_convert_pixmap (gctx, spix, cs, NULL , NULL , NULL , alpha);
2937
2905
}
2938
2906
fz_catch (gctx) return NULL ;
@@ -2942,7 +2910,7 @@ struct fz_pixmap_s
2942
2910
// ---------------------------------------------------------------------
2943
2911
// create pixmap as scaled copy of another one
2944
2912
// ---------------------------------------------------------------------
2945
- fz_pixmap_s (fz_pixmap *spix, float w, float h, struct fz_irect_s *clip = NULL )
2913
+ fz_pixmap_s (struct fz_pixmap_s *spix, float w, float h, struct fz_irect_s *clip = NULL )
2946
2914
{
2947
2915
fz_pixmap *pm = NULL ;
2948
2916
fz_try (gctx)
@@ -3101,33 +3069,48 @@ struct fz_pixmap_s
3101
3069
// ---------------------------------------------------------------------
3102
3070
void shrink (int factor)
3103
3071
{
3104
- if (factor < 0 ) return ;
3105
- fz_try (gctx)
3072
+ if (factor < 1 )
3106
3073
{
3107
- fz_subsample_pixmap (gctx, $self, factor);
3074
+ PySys_WriteStdout (" warning: ignoring shrink factor < 1\n " );
3075
+ return ;
3108
3076
}
3109
- fz_catch (gctx) return ;
3077
+ fz_subsample_pixmap (gctx, $self, factor) ;
3110
3078
}
3111
3079
3112
3080
/* **************************/
3113
3081
/* apply gamma correction */
3114
3082
/* **************************/
3115
3083
void gammaWith (float gamma )
3116
3084
{
3085
+ if (!fz_pixmap_colorspace (gctx, $self))
3086
+ {
3087
+ PySys_WriteStdout (" warning: colorspace invalid for function\n " );
3088
+ return ;
3089
+ }
3117
3090
fz_gamma_pixmap (gctx, $self, gamma );
3118
3091
}
3119
3092
3120
3093
/* **************************/
3121
3094
/* tint pixmap with color */
3122
3095
/* **************************/
3123
3096
%pythonprepend tintWith%{
3124
- if self.colorspace .n > 3 :
3125
- raise TypeError (" CMYK colorspace cannot be tinted" )%}
3097
+ if not self.colorspace or self.colorspace .n > 3 :
3098
+ print (" warning: colorspace invalid for function" )
3099
+ return %}
3126
3100
void tintWith (int red, int green, int blue)
3127
3101
{
3128
3102
fz_tint_pixmap (gctx, $self, red, green, blue);
3129
3103
}
3130
3104
3105
+ // ----------------------------------------------------------------------
3106
+ // Pixmap.setResolution
3107
+ // ----------------------------------------------------------------------
3108
+ void setResolution (int xres, int yres)
3109
+ {
3110
+ $self->xres = xres;
3111
+ $self->yres = yres;
3112
+ }
3113
+
3131
3114
// ----------------------------------------------------------------------
3132
3115
// clear total pixmap with 0x00 */
3133
3116
// ----------------------------------------------------------------------
@@ -3155,9 +3138,17 @@ struct fz_pixmap_s
3155
3138
// ----------------------------------------------------------------------
3156
3139
// copy pixmaps
3157
3140
// ----------------------------------------------------------------------
3158
- void copyPixmap (struct fz_pixmap_s *src, const struct fz_irect_s *bbox)
3141
+ FITZEXCEPTION (copyPixmap, !result)
3142
+ PyObject *copyPixmap (struct fz_pixmap_s *src, const struct fz_irect_s *bbox)
3159
3143
{
3160
- fz_copy_pixmap_rect (gctx, $self, src, bbox, NULL );
3144
+ fz_try (gctx)
3145
+ {
3146
+ if (!fz_pixmap_colorspace (gctx, src))
3147
+ THROWMSG (" cannot copy pixmap with NULL colorspace" );
3148
+ fz_copy_pixmap_rect (gctx, $self, src, bbox, NULL );
3149
+ }
3150
+ fz_catch (gctx) return NULL ;
3151
+ return NONE;
3161
3152
}
3162
3153
3163
3154
// ----------------------------------------------------------------------
0 commit comments