Guillaume Proux wrote:
> Hi,
>
> I just started using Freevo (based on pygame) and I have some issues
> with fonts.
> Apparently if one tries to render a string where not all chars are in
> the font, there is no error and we get garbage out.
>
> There is ONE function in SDL_TTF that can tell if a character is in
> the font or not. This is GlyphMetrics. So I made a tentative patch (i
> don't have a dev env ready therefore I haven't even compiled it so I
> would appreciate if somebody could try it out) to add the metrics
> method to fonts.
>
> If a call to this method returns None, then it will mean that this
> character cannot be rendered, which is what I will need in Freevo to
> decide to switch to a different font.
>
> Please let me know if this actually compiles and if it works!
I compiled it on Windows with Mingw. The line:
int minx, int maxx, int miny, int maxy, int advance;
is incorrect. I removed the additional int's. I also saw that
font_metrics returned NULL on the last line. I assumed this it returns
None in this case:
Py_INCREF(Py_None);
return Py_None;
With these changes it compiled and ran. It would be nice if a test case
were included. I could not get it to return None. It always returned a
tuple.
Some other concerns. In several checks font_metrics returns NULL when
string[0] is 0 without raising an exception. Also, raising an exception
instead of returning None might be more Pythonic when a character is not
in the font. But I can't think of a good exception in this case as
ValueError should be raised for an empty string.
--
Lenard Lindstrom
<len-l@xxxxxxxxx>