@@ -652,6 +652,92 @@ font_size(PyObject *self, PyObject *text)
652652 return Py_BuildValue ("(ii)" , w , h );
653653}
654654
655+ static PyObject *
656+ font_getter_point_size (PyFontObject * self , void * closure )
657+ {
658+ #if SDL_TTF_VERSION_ATLEAST (2 , 0 , 18 )
659+ return PyLong_FromLong (self -> ptsize );
660+ #else
661+ PyErr_SetString (pgExc_SDLError ,
662+ "Incorrect SDL_TTF version (requires 2.0.18)" );
663+ return NULL ;
664+ #endif
665+ }
666+
667+ static int
668+ font_setter_point_size (PyFontObject * self , PyObject * value , void * closure )
669+ {
670+ #if SDL_TTF_VERSION_ATLEAST (2 , 0 , 18 )
671+ TTF_Font * font = PyFont_AsFont (self );
672+ int val = PyLong_AsLong (value );
673+
674+ if (PyErr_Occurred () && val == -1 ) {
675+ return -1 ;
676+ }
677+
678+ if (val <= 0 ) {
679+ PyErr_SetString (PyExc_ValueError ,
680+ "point_size cannot be equal to, or less than 0" );
681+ return -1 ;
682+ }
683+
684+ if (TTF_SetFontSize (font , val ) == -1 ) {
685+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
686+ return -1 ;
687+ }
688+ self -> ptsize = val ;
689+
690+ return 0 ;
691+ #else
692+ PyErr_SetString (pgExc_SDLError ,
693+ "Incorrect SDL_TTF version (requires 2.0.18)" );
694+ return -1 ;
695+ #endif
696+ }
697+
698+ static PyObject *
699+ font_get_ptsize (PyObject * self , PyObject * args )
700+ {
701+ #if SDL_TTF_VERSION_ATLEAST (2 , 0 , 18 )
702+ return PyLong_FromLong (((PyFontObject * )self )-> ptsize );
703+ #else
704+ PyErr_SetString (pgExc_SDLError ,
705+ "Incorrect SDL_TTF version (requires 2.0.18)" );
706+ return NULL ;
707+ #endif
708+ }
709+
710+ static PyObject *
711+ font_set_ptsize (PyObject * self , PyObject * arg )
712+ {
713+ #if SDL_TTF_VERSION_ATLEAST (2 , 0 , 18 )
714+ TTF_Font * font = PyFont_AsFont (self );
715+ int val = PyLong_AsLong (arg );
716+
717+ if (PyErr_Occurred () && val == -1 ) {
718+ return NULL ;
719+ }
720+
721+ if (val <= 0 ) {
722+ PyErr_SetString (PyExc_ValueError ,
723+ "point_size cannot be equal to, or less than 0" );
724+ return NULL ;
725+ }
726+
727+ if (TTF_SetFontSize (font , val ) == -1 ) {
728+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
729+ return NULL ;
730+ }
731+ ((PyFontObject * )self )-> ptsize = val ;
732+
733+ Py_RETURN_NONE ;
734+ #else
735+ PyErr_SetString (pgExc_SDLError ,
736+ "Incorrect SDL_TTF version (requires 2.0.18)" );
737+ return NULL ;
738+ #endif
739+ }
740+
655741static PyObject *
656742font_getter_name (PyObject * self , void * closure )
657743{
@@ -892,6 +978,8 @@ static PyGetSetDef font_getsets[] = {
892978 (setter )font_setter_strikethrough , DOC_FONT_FONT_STRIKETHROUGH , NULL },
893979 {"align" , (getter )font_getter_align , (setter )font_setter_align ,
894980 DOC_FONT_FONT_ALIGN , NULL },
981+ {"point_size" , (getter )font_getter_point_size ,
982+ (setter )font_setter_point_size , DOC_FONT_FONT_POINTSIZE , NULL },
895983 {NULL , NULL , NULL , NULL , NULL }};
896984
897985static PyMethodDef font_methods [] = {
@@ -911,6 +999,9 @@ static PyMethodDef font_methods[] = {
911999 DOC_FONT_FONT_GETSTRIKETHROUGH },
9121000 {"set_strikethrough" , font_set_strikethrough , METH_O ,
9131001 DOC_FONT_FONT_SETSTRIKETHROUGH },
1002+ {"get_point_size" , font_get_ptsize , METH_NOARGS ,
1003+ DOC_FONT_FONT_GETPOINTSIZE },
1004+ {"set_point_size" , font_set_ptsize , METH_O , DOC_FONT_FONT_SETPOINTSIZE },
9141005 {"metrics" , font_metrics , METH_O , DOC_FONT_FONT_METRICS },
9151006 {"render" , (PyCFunction )font_render , METH_VARARGS | METH_KEYWORDS ,
9161007 DOC_FONT_FONT_RENDER },
@@ -1024,6 +1115,7 @@ font_init(PyFontObject *self, PyObject *args, PyObject *kwds)
10241115
10251116 Py_DECREF (obj );
10261117 self -> font = font ;
1118+ self -> ptsize = fontsize ;
10271119 self -> ttf_init_generation = current_ttf_generation ;
10281120
10291121 return 0 ;
0 commit comments