[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Strange (uncommon) behaviour of Font.render()
Thanks for your enlightening reply. (I had the suspicion that something
like this could be the cause)
Am 09.01.2011 23:46, schrieb Saul Spatz:
The first 3 arguments are positional. If this were in pure python,
then background=None would have the same effect as just passing None.
The font module is programed in C. If you look at font.c you'll find
font_render (PyObject* self, PyObject* args)
{
<snip>
...
So one had to consider this to be a bug in the C-Code. Do you think one
could fix this, by introducing an extra check
if bg_rgba_obj is the Python None obj here:
if (bg_rgba_obj) *AND IT IS NOT None*
{
if (!RGBAFromColorObj (bg_rgba_obj, rgba))
return RAISE (PyExc_TypeError, "Invalid background RGBA
argument");
backg.r = rgba[0];
backg.g = rgba[1];
backg.b = rgba[2];
backg.unused = 0;
}
else
{
backg.r = 0;
backg.g = 0;
backg.b = 0;
backg.unused = 0;
}
<snip>
While I haven't traced through all the code, it seems clear that if
you pass a parameter for the background, the function will check if
it's a valid RGBA argument, and raise a TypeError if it isn't.
So, as it is, the only possible workaround for the before mentioned
usecase is like this. Right?
def text_line(surface, font, text, x, y, color, bg=None):
...
if bg is None:
label = font.render(text, 1, color)
else:
label = font.render(text, 1, color, bg)
...
Not very elegant :-(
At least, I think, the docs for Font.render() should be fixed.
Best regards,
Gregor
I have found similar things in pygame before, although I can't recall
the details.
In any event, if you don't want a background apramter, leave it out;
None won't work whatever you do.
Saul