wxGTK and UTF-8

Olly Betts olly at survex.com
Sun Jul 2 19:06:50 PDT 2006


On 2006-07-03, Vadim Zeitlin wrote:
> On Sun, 2 Jul 2006 16:52:28 +0000 (UTC) Olly Betts wrote:
>
> OB> I've been investigating using UTF-8 with an ANSI build of wx, using
> OB> wxGtk and CVS HEAD so far.  Everything seems to work well - I've been
> OB> testing with Chinese characters and they work everywhere I've tested
> OB> so far.
>
>  I guess this is a side effect of my changes to allow using encodings in
> ANSI build of wxGTK (introduction of wxConvertToGTK() &c) because I
> certainly remember that it did not work before. In fact it still shouldn't
> work with 2.6 AFAICS. But even with the current HEAD, don't you need to
> explicitly set wxFONTENCODING_UTF8 for all the fonts you use? Or is it used
> automatically if the locale is correctly set somehow?

I just call this early on in my app initialisation (before anything else
related to wx, except perhaps for static object initialisation):

    wxFont::SetDefaultEncoding(wxFONTENCODING_UTF8);

I've just tried it with 2.6.3 and it seems to work with that too.

> OB> However there's some suspect code in src/common/intl.cpp with a
> OB> comment which claims that an ANSI build of wxGTK doesn't support
> OB> UTF8 "at all".
>
>  This code is definitely suspicious. I do remember some problems with UTF-8
> locale and wxGTK but it's not impossible that, as often, the real problem
> had been fixed elsewhere since then and so this hack is not needed any more. 
> Have you tested that it indeed works without it? Ideally with both wxGTK1
> and wxGTK2.

My app works without that code with wx CVS HEAD and GTK2, but it also
works with it.  I noticed this code while trying to figure out if I
could get UTF8 working, and thought I should bring up the matter since
at least the comment is now clearly wrong.

But perhaps I'm just not using anything affected by this though.  A
quick grep for GetSystemEncoding in the wx sources suggests shows
numerous uses.

Is there any chance at all of this working with GTK1?  I thought GTK1
didn't have UTF-8 support, so I don't really see how it could.  I'd have
to rebuild wx with GTK1 to try it and I don't have the spare disk space
right now so I'd have to delete the build I'm using which would be
rather disruptive...

> Of course, ideally someone would review all code using
> wxFONTENCODING_DEFAULT and replace the relevant occurrences of it with
> wxFONTENCODING_ASCII, if you have time to do this it would be much
> appreciated.

I've just had a quick look, and there are just over 100 occurrences in
CVS HEAD, so realistically I don't think I have time.

Cheers,
    Olly





More information about the wx-dev mailing list