@@ -5,7 +5,7 @@ static PyObject *ErrorObject;
55extern PyTypeObject FT2Font_Type ;
66extern PyTypeObject Glyph_Type ;
77static int FT2Font_setattr (FT2FontObject * self , char * name , PyObject * v );
8-
8+ static PyObject * FT2Font_clear ( FT2FontObject * self );
99// set_error from paint; see LICENSE_PAINT that ships with matplotlib
1010void set_error (PyObject * err , char * fmt , ...)
1111{
@@ -171,16 +171,9 @@ newFT2FontObject(PyObject *args)
171171 FT2FontObject * self ;
172172 self = PyObject_New (FT2FontObject , & FT2Font_Type );
173173 self -> image .buffer = NULL ;
174- self -> image .width = 0 ;
175- self -> image .height = 0 ;
176174 self -> text = NULL ;
177- self -> angle = 0.0 ;
178- self -> num_chars = 0 ;
179175 self -> num_glyphs = 0 ;
180- self -> pen .x = 0 ;
181- self -> pen .y = 0 ;
182-
183-
176+ FT2Font_clear (self );
184177 error = FT_New_Face ( _ft2Library , facefile , 0 , & self -> face );
185178 if (error == FT_Err_Unknown_File_Format ) {
186179
@@ -216,6 +209,7 @@ newFT2FontObject(PyObject *args)
216209 }
217210
218211
212+
219213 if (self == NULL )
220214 return NULL ;
221215 self -> x_attr = NULL ;
@@ -295,6 +289,7 @@ FT2Font_set_bitmap_size(FT2FontObject *self, PyObject *args)
295289
296290/* FT2Font methods */
297291
292+
298293static void
299294FT2Font_dealloc (FT2FontObject * self )
300295{
@@ -304,7 +299,6 @@ FT2Font_dealloc(FT2FontObject *self)
304299 //todo: how to free the library, ie, when all fonts are done
305300 //FT_Done_FreeType( _ft2Library );
306301
307- //todo: how to free buffer - this seqfaults
308302 free (self -> image .buffer );
309303 self -> image .buffer = NULL ;
310304
@@ -314,6 +308,36 @@ FT2Font_dealloc(FT2FontObject *self)
314308
315309}
316310
311+ char FT2Font_clear__doc__ [] =
312+ "clear()\n"
313+ "\n"
314+ "Clear all the glyphs, reset for a new set_text"
315+ ;
316+ static PyObject *
317+ FT2Font_clear (FT2FontObject * self )
318+ {
319+ size_t i ;
320+ //printf("start\n");
321+ for (i = 0 ; i < self -> num_glyphs ; i ++ ) {
322+ Py_XDECREF (self -> gms [i ]);
323+ self -> gms [i ] = NULL ;
324+ }
325+ //printf("1\n");
326+ free (self -> image .buffer );
327+ self -> image .buffer = NULL ;
328+ self -> image .width = 0 ;
329+ self -> image .height = 0 ;
330+ self -> text = NULL ;
331+ self -> angle = 0.0 ;
332+ self -> num_chars = 0 ;
333+ self -> num_glyphs = 0 ;
334+ self -> pen .x = 0 ;
335+ self -> pen .y = 0 ;
336+ Py_INCREF (Py_None );
337+ return Py_None ;
338+ //printf("end\n");
339+ }
340+
317341char FT2Font_set_size__doc__ [] =
318342"set_size(ptsize, dpi)\n"
319343"\n"
@@ -934,6 +958,8 @@ FT2Font_get_sfnt_name(FT2FontObject *self, PyObject *args)
934958}
935959
936960static PyMethodDef FT2Font_methods [] = {
961+ {"clear" , (PyCFunction )FT2Font_clear ,
962+ METH_VARARGS , FT2Font_clear__doc__ },
937963 {"write_bitmap" , (PyCFunction )FT2Font_write_bitmap ,
938964 METH_VARARGS , FT2Font_write_bitmap__doc__ },
939965 {"set_bitmap_size" , (PyCFunction )FT2Font_set_bitmap_size ,
0 commit comments