[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Tentative patch for "metrics" font method



Hi Lenard,

Thank you for helping.

I have NO knowledge of programming for Python/C interface. I tried
just to copy paste from above methods....
I guess I should try to learn a bit before writing patches. I also
need to set up a dev system.

On my Linux box, I had problem with non appearing characters (garbage)
when trying to display english characters using the Kochi font. I
don't know how it would work if one would try this in Windows. This
would be the only way to trigger the "character is not in the font" as
per the SDL_TTF doc.

Regarding the exception, I don't have strong opinions, I tend to be
conservative with raising exceptions and maybe one should raise an
exception when the string passed as parameter is empty but... I am not
convinced. But I will let official maintainers make the best choice.

Regards,

 Guillaume


On 1/19/07, Lenard Lindstrom <len-l@xxxxxxxxx> wrote:
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>