[Bf-python] Nice smooth fonts in bpython
Campbell Barton
cbarton at metavr.com
Tue Mar 29 12:46:11 CEST 2005
Hi. I just thaught Id see if I could get BIF_GetStringWidth working, Was
very easy for the most part, now my console can display nice smoothed fonts.
but the BIF_GetStringWidth always returns 0, no idea why. it seems to
take the same parms as BIF_DrawString.
Drawing AA text works fine, getting the string width returns 0.
- Wondering if anyones interested in having a look.
- Cam
static PyObject *Method_GetStringWidth( PyObject * self, PyObject * args )
{
char *text;
char *font_str = "normal";
struct BMF_Font *font;
PyObject *width;
int smooth_font = 0;
if( !PyArg_ParseTuple( args, "s|si", &text, &font_str, &smooth_font ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected one two string arguments and
optionaly an int" );
if( !strcmp( font_str, "normal" ) )
font = ( &G )->font;
else if( !strcmp( font_str, "small" ) )
font = ( &G )->fonts;
else if( !strcmp( font_str, "tiny" ) )
font = ( &G )->fontss;
else
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"\"font\" must be: 'normal' (default), 'small'
or 'tiny'." );
if (smooth_font)
width = PyInt_FromLong( BIF_GetStringWidth( font, text, 0) );
else
width = PyInt_FromLong( BMF_GetStringWidth( font, text ) );
if( !width )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyInt" );
return width;
}
static PyObject *Method_Text( PyObject * self, PyObject * args )
{
char *text;
char *font_str = NULL;
struct BMF_Font *font;
int smooth_font;
if( !PyArg_ParseTuple( args, "s|si", &text, &font_str, &smooth_font) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected one or two string arguments and an
oprional int" );
if( !font_str )
font = ( &G )->font;
else if( !strcmp( font_str, "normal" ) )
font = ( &G )->font;
else if( !strcmp( font_str, "small" ) )
font = ( &G )->fonts;
else if( !strcmp( font_str, "tiny" ) )
font = ( &G )->fontss;
else
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"\"font\" must be: 'normal' (default), 'small'
or 'tiny'." );
if (smooth_font) {
BIF_DrawString(font, text, 0);
return PyInt_FromLong( BIF_GetStringWidth( font, text, 0) );
} else {
BMF_DrawString( font, text );
return PyInt_FromLong( BMF_GetStringWidth( font, text ) );
}
}
More information about the Bf-python
mailing list