@@ -41,7 +41,7 @@ fz_throw(gctx, FZ_ERROR_GENERIC, msg)
4141%enddef
4242// =============================================================================
4343
44- // SWIG macro: check whether document type is PDF
44+ // SWIG macro: ensure that document type is PDF
4545%define assert_PDF(cond)
4646if (!cond) THROWMSG(" not a PDF" )
4747%enddef
@@ -116,7 +116,7 @@ struct fz_document_s
116116 fprintf (stderr, " done!\n " );
117117#endif
118118 }
119- FITZEXCEPTION (fz_document_s, result== NULL )
119+ FITZEXCEPTION (fz_document_s, ! result)
120120 %pythonprepend fz_document_s %{
121121 if not filename or type (filename) == str:
122122 pass
@@ -133,9 +133,8 @@ struct fz_document_s
133133 self.metadata = None
134134 self.openErrCode = 0
135135 self.openErrMsg = ' '
136- self._page_refs = weakref.WeakValueDictionary ()
137-
138- %}
136+ self.FontInfos = []
137+ self._page_refs = weakref.WeakValueDictionary ()%}
139138 %pythonappend fz_document_s %{
140139 if this :
141140 self.openErrCode = self._getGCTXerrcode ()
@@ -151,7 +150,7 @@ struct fz_document_s
151150 {
152151 struct fz_document_s *doc = NULL;
153152 fz_stream *data = NULL;
154- char *streamdata;
153+ char *streamdata = NULL ;
155154 size_t streamlen = 0;
156155 if (PyBytes_Check(stream))
157156 {
@@ -180,8 +179,7 @@ struct fz_document_s
180179 doc = (fz_document *) pdf_create_document(gctx);
181180 }
182181 }
183- fz_catch(gctx)
184- return NULL;
182+ fz_catch(gctx) return NULL;
185183 return doc;
186184 }
187185
@@ -1198,7 +1196,8 @@ if sa < 0:
11981196 fontdict = pdf_dict_get_val(gctx, dict, i);
11991197 if (!pdf_is_dict(gctx, fontdict))
12001198 continue; // not a valid font
1201- long xref = (long) pdf_to_num(gctx, fontdict);
1199+ int xref = pdf_to_num(gctx, fontdict);
1200+ char *ext = fontextension(gctx, pdf, xref);
12021201 long gen = (long) pdf_to_gen(gctx, fontdict);
12031202 subtype = pdf_dict_get(gctx, fontdict, PDF_NAME_Subtype);
12041203 basefont = pdf_dict_get(gctx, fontdict, PDF_NAME_BaseFont);
@@ -1207,7 +1206,7 @@ if sa < 0:
12071206 else
12081207 bname = basefont;
12091208 name = pdf_dict_get_key(gctx, dict, i);
1210- PyList_Append(fontlist, Py_BuildValue("(i,i ,s,s,s)", xref, gen ,
1209+ PyList_Append(fontlist, Py_BuildValue("(i,s ,s,s,s)", xref, ext ,
12111210 pdf_to_name(gctx, subtype),
12121211 pdf_to_name(gctx, bname),
12131212 pdf_to_name(gctx, name)));
@@ -2046,7 +2045,7 @@ fannot._erase()
20462045 // ---------------------------------------------------------------------
20472046 // insert font
20482047 // ---------------------------------------------------------------------
2049- FITZEXCEPTION (insertFont, result< 0 )
2048+ FITZEXCEPTION (insertFont, ! result)
20502049 %pythonprepend insertFont %{
20512050 if not self.parent :
20522051 raise RuntimeError (" orphaned object: parent is None" )
@@ -2147,7 +2146,7 @@ fannot._erase()
21472146 pdf_dict_puts (gctx, fonts, fontname, font_obj);
21482147 pdf_dict_put (gctx, resources, PDF_NAME_Font, fonts);
21492148 }
2150- fz_catch (gctx) return - 1 ;
2149+ fz_catch (gctx) return NULL ;
21512150 return Py_BuildValue (" (i, O)" , xref, info);
21522151 }
21532152
@@ -2845,6 +2844,11 @@ struct fz_pixmap_s
28452844#endif
28462845 }
28472846 FITZEXCEPTION (fz_pixmap_s, !result)
2847+ %pythonappend fz_pixmap_s %{
2848+ if this :
2849+ self.thisown = True
2850+ else :
2851+ self.thisown = False%}
28482852 // ---------------------------------------------------------------------
28492853 // create empty pixmap with colorspace and IRect
28502854 // ---------------------------------------------------------------------
@@ -3011,6 +3015,8 @@ struct fz_pixmap_s
30113015 type = pdf_dict_get (gctx, ref, PDF_NAME_Subtype);
30123016 if (!pdf_name_eq (gctx, type, PDF_NAME_Image))
30133017 THROWMSG (" xref not an image" );
3018+ if (!pdf_is_stream (gctx, ref))
3019+ THROWMSG (" broken PDF: xref is not a stream" );
30143020 img = pdf_load_image (gctx, pdf, ref);
30153021 pdf_drop_obj (gctx, ref);
30163022 pix = fz_get_pixmap_from_image (gctx, img, NULL , NULL , NULL , NULL );
@@ -3260,12 +3266,9 @@ struct fz_pixmap_s
32603266 return " fitz.Pixmap(%s, %s, %s)" % (' None' , self.irect , self.alpha )%}
32613267 %pythoncode %{
32623268 def __del__ (self):
3263- if getattr (self, " thisown" , True):
3264- try :
3265- self.__swig_destroy__ (self)
3266- except:
3267- pass
3269+ if hasattr (self, " this" ) and self.thisown :
32683270 self.thisown = False
3271+ self.__swig_destroy__ (self)
32693272 %}
32703273 }
32713274};
0 commit comments