@@ -592,6 +592,51 @@ FT2Font_write_bitmap(FT2FontObject *self, PyObject *args)
592592
593593}
594594
595+
596+ char FT2Font_draw_rect__doc__ [] =
597+ "draw_bbox(x0, y0, x1, y1)\n"
598+ "\n"
599+ "Draw a rect to the image. It is you responsibility to set the dimensions\n"
600+ "of the image, eg, with set_bitmap_size\n"
601+ "\n"
602+ ;
603+ static PyObject *
604+ FT2Font_draw_rect (FT2FontObject * self , PyObject * args )
605+ {
606+
607+ long x0 , y0 , x1 , y1 , i = 0 , j = 0 ;
608+ long width , height ;
609+ if (!PyArg_ParseTuple (args , "llll:draw_glyphs_to_bitmap" ,
610+ & x0 , & y0 , & x1 , & y1 ))
611+ return NULL ;
612+
613+ width = abs (x1 - x0 );
614+ height = abs (y1 - y0 );
615+
616+ if ( x0 < 0 || y0 < 0 || x1 < 0 || y1 < 0 ||
617+ x0 > self -> image .width || x1 > self -> image .width ||
618+ y0 > self -> image .height || y1 > self -> image .height ) {
619+ PyErr_SetString (PyExc_ValueError ,
620+ "rect coords outside image bounds" );
621+ return NULL ;
622+ }
623+
624+
625+ printf ("%ld, %ld, %ld, %ld\n" , x0 , x1 , y0 , y1 );
626+ for (i = x0 ; i < x1 ; ++ i ) {
627+ self -> image .buffer [i + y0 * self -> image .width ] = 255 ;
628+ self -> image .buffer [i + y1 * self -> image .width ] = 255 ;
629+ }
630+
631+ for (j = y0 ; j < y1 ; ++ j ) {
632+ self -> image .buffer [x0 + j * self -> image .width ] = 255 ;
633+ self -> image .buffer [x1 + j * self -> image .width ] = 255 ;
634+ }
635+
636+ Py_INCREF (Py_None );
637+ return Py_None ;
638+ }
639+
595640char FT2Font_draw_glyphs_to_bitmap__doc__ [] =
596641"draw_glyphs_to_bitmap()\n"
597642"\n"
@@ -736,6 +781,7 @@ FT2Font_draw_glyph_to_bitmap(FT2FontObject *self, PyObject *args)
736781static PyMethodDef FT2Font_methods [] = {
737782 {"write_bitmap" , (PyCFunction )FT2Font_write_bitmap , METH_VARARGS , FT2Font_write_bitmap__doc__ },
738783 {"set_bitmap_size" , (PyCFunction )FT2Font_set_bitmap_size , METH_VARARGS , FT2Font_load_char__doc__ },
784+ {"draw_rect" , (PyCFunction )FT2Font_draw_rect , METH_VARARGS , FT2Font_draw_rect__doc__ },
739785 {"draw_glyph_to_bitmap" , (PyCFunction )FT2Font_draw_glyph_to_bitmap , METH_VARARGS , FT2Font_draw_glyph_to_bitmap__doc__ },
740786 {"draw_glyphs_to_bitmap" , (PyCFunction )FT2Font_draw_glyphs_to_bitmap , METH_VARARGS , FT2Font_draw_glyphs_to_bitmap__doc__ },
741787 {"load_char" , (PyCFunction )FT2Font_load_char , METH_VARARGS , FT2Font_load_char__doc__ },
0 commit comments