[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pygame] unicode bug at font.c



Title: RE: [pygame] unicode bug at font.c

I don't think there's any particular things on Korean fonts.
But if you look at the fonc.c of pygame there exist clear bugs.

in font_render() function, it use TT_RenderUTF8_... () function to render a unicode characters..
To do that, string must be encoded to utf8 encoding. But if you loot at the code it doesn't use utf8 encoded strings.

       if(PyUnicode_Check(text))
        {
                PyObject* strob = PyEval_CallMethod(text, "encode", "(s)", "utf-8");
                char *string = PyString_AsString(text); // <-- 'text' is not utf8 encoded characters.
                if(aa)
                {
                        if(!bg_rgba_obj)
                                surf = TTF_RenderUTF8_Blended(font, string, foreg);
                        else
                                surf = TTF_RenderUTF8_Shaded(font, string, foreg, backg);
                }
                else
                        surf = TTF_RenderUTF8_Solid(font, string, foreg);


font_size() function have similar but more severe bug. if you call font.size() for unicode characters, it generated SEGV because it mistakenly free 'text' object.

        if(PyUnicode_Check(text))
        {
                PyObject* strob = PyEval_CallMethod(text, "encode", "(s)", "utf-8");
                char *string = PyString_AsString(text); // <-- 'text' is not utf8 encoded characters.

                TTF_SizeUTF8(font, string, &w, &h);

                Py_DECREF(text); // <-- 'text' must be preserved. instead 'strob' must be freeed


I don't understand how you can display japanese characters without problem.
Does these bug exist only in the cvs version?

-
HeeChul Yun,         
Embedded S/W Team at ETRI
e-mail: hcyun@etri.re.kr
phone: +82-42-860-1673



> -----Original Message-----
> From: Guillaume Proux [mailto:gproux@acesoliton.com]
> Sent: Friday, November 15, 2002 10:58 AM
> To: pygame-users@seul.org
> Subject: Re: [pygame] unicode bug at font.c
>
>
> Hi,
>
> Just wanted to say that I never had any trouble to display
> Japanese in pygame (since more than one year!)... Is there
> something that is particular
> to Korean fonts?
>
> cheers,
>
> Guillaume
>
> hcyun@etri.re.kr wrote:
> >
> > Well, I just wanted other (asian) guys not wasting their
> time trying to
> > see unicode characters with pygame.
> > However, our team have plan to use SDL and probably pygame
> for the new
> > projet. I hope to contribute this project if possible.
> >
> > Thanks for your great job.
>
> ____________________________________
> pygame mailing list
> pygame-users@seul.org
> http://pygame.seul.org
>