@@ -434,6 +434,41 @@ FT2Font_set_text(FT2FontObject *self, PyObject *args)
434434
435435}
436436
437+ char FT2Font_get_glyph__doc__ [] =
438+ "get_glyph(num)\n"
439+ "\n"
440+ "Return the glyph object with num num\n"
441+ ;
442+ GlyphObject * FT2Font_get_glyph (FT2FontObject * self , PyObject * args ){
443+ int num ;
444+ if (!PyArg_ParseTuple (args , "i:get_glyph" , & num ))
445+ return NULL ;
446+
447+ if ( num >= self -> num_glyphs ) {
448+ PyErr_SetString (PyExc_ValueError ,
449+ "Glyph index out of range" );
450+ return NULL ;
451+
452+ }
453+ GlyphObject * gm = self -> gms [num ];
454+ Py_INCREF (gm );
455+ return gm ;
456+ }
457+
458+ char FT2Font_get_num_glyphs__doc__ [] =
459+ "get_num_glyphs()\n"
460+ "\n"
461+ "Return the number of loaded glyphs\n"
462+ ;
463+ PyObject * FT2Font_get_num_glyphs (FT2FontObject * self , PyObject * args ){
464+
465+ if (!PyArg_ParseTuple (args , ":get_num_glyph" ))
466+ return NULL ;
467+
468+ return Py_BuildValue ("l" , self -> num_glyphs );
469+
470+ }
471+
437472char FT2Font_load_char__doc__ [] =
438473"load_char(charcode)\n"
439474"\n"
@@ -453,6 +488,7 @@ static GlyphObject *
453488FT2Font_load_char (FT2FontObject * self , PyObject * args )
454489{
455490 //load a char using the unsigned long charcode
491+ GlyphObject * gm ;
456492 long charcode ;
457493 int error ;
458494 if (!PyArg_ParseTuple (args , "l:load_char" , & charcode ))
@@ -473,10 +509,7 @@ FT2Font_load_char(FT2FontObject *self, PyObject *args)
473509 return NULL ;
474510 }
475511
476-
477-
478512
479- GlyphObject * gm ;
480513 gm = PyObject_New (GlyphObject , & Glyph_Type );
481514
482515
@@ -490,8 +523,6 @@ FT2Font_load_char(FT2FontObject *self, PyObject *args)
490523 FT_BBox bbox ;
491524 FT_Glyph_Get_CBox ( self -> glyphs [self -> num_glyphs ], ft_glyph_bbox_subpixels , & bbox );
492525
493- gm -> glyph_num = self -> num_glyphs ++ ;
494-
495526 gm -> x_attr = NULL ;
496527
497528 SETATTR (gm , Glyph_setattr , "width" , PyInt_FromLong , self -> face -> glyph -> metrics .width );
@@ -508,12 +539,18 @@ FT2Font_load_char(FT2FontObject *self, PyObject *args)
508539 ("(llll)" ,
509540 bbox .xMin , bbox .yMin , bbox .xMax , bbox .yMax );
510541 SETATTR_PYOBJ (gm , Glyph_setattr , "bbox" , pbbox );
542+ gm -> glyph_num = self -> num_glyphs ;
511543
512-
513-
544+ Py_INCREF (gm ); //incref to store in list
545+ self -> gms [self -> num_glyphs ] = gm ;
546+ self -> num_glyphs ++ ;
514547 return gm ;
548+
515549}
516550
551+
552+
553+
517554char FT2Font_get_width_height__doc__ [] =
518555"w, h = get_width_height()\n"
519556"\n"
@@ -801,6 +838,8 @@ static PyMethodDef FT2Font_methods[] = {
801838 {"draw_rect" , (PyCFunction )FT2Font_draw_rect , METH_VARARGS , FT2Font_draw_rect__doc__ },
802839 {"draw_glyph_to_bitmap" , (PyCFunction )FT2Font_draw_glyph_to_bitmap , METH_VARARGS , FT2Font_draw_glyph_to_bitmap__doc__ },
803840 {"draw_glyphs_to_bitmap" , (PyCFunction )FT2Font_draw_glyphs_to_bitmap , METH_VARARGS , FT2Font_draw_glyphs_to_bitmap__doc__ },
841+ {"get_glyph" , (PyCFunction )FT2Font_get_glyph , METH_VARARGS , FT2Font_get_glyph__doc__ },
842+ {"get_num_glyphs" , (PyCFunction )FT2Font_get_num_glyphs , METH_VARARGS , FT2Font_get_num_glyphs__doc__ },
804843 {"image_as_str" , (PyCFunction )FT2Font_image_as_str , METH_VARARGS , FT2Font_image_as_str__doc__ },
805844 {"load_char" , (PyCFunction )FT2Font_load_char , METH_VARARGS , FT2Font_load_char__doc__ },
806845 {"set_text" , (PyCFunction )FT2Font_set_text , METH_VARARGS , FT2Font_set_text__doc__ },
0 commit comments