Enumerating encodings

Manuel Martín mmartin at ceyd.es
Wed Dec 13 04:18:42 PST 2006


 >MM> How do I enumerate all the encodings that my_OS && wx can manage?
 >
 > wx doesn't support this currently. You can only try converting with >the
 >give encoding.
 >
 >MM> After digging into wx sources, I can answer myself:
 >MM> I have to:
 >MM> - Iterate through all wxFONTENCODING_xxxx
 >MM> - Use the not documented wxEncodingToCodepage (found at utils.cpp)
 >MM>    I know this is a specific WS-Windows code.
 >MM> - If this usefull function returns -1, the encoding is not avaible.
 >
 > It's indeed MS-Windows specific and wxEncodingToCodepage is a private
 >function so you're not sure to have it in future wx releases. A proper 
 >way
 >to do it would be to indeed add a way to get all encodings supported 
by >the
 >system to wx itself, I think this can be implemented relatively easily 
 >for
 >Win32 and Unix systems using iconv. For Win32 it would probably involve
 >enumerating all subkeys of HKCR\MIME\Database\Codepage (which is BTW >you
 >could do instead of using wxEncodingToCodepage too). For iconv we 
could >run
 >"iconv -l".
 >
 > Regards,
 >VZ


For Win32/CE we can also use ::EnumSystemCodePages.

Anyhow, I see a big no-no:
We can search all encodings installed on the system, which is
useful for string conversion. This must be done in a OS depending
way, as you said. The problem comes from the way wx manages encodings.
wx defines first of all the wxFONTENCODING_xxx for future use. But
these are predefined, not searched. So, some may not be installed and
there are installed encodings that wx doesn't manage.

This affects not only string conversions, but all of wxfonts world.
For example: wxFontMapper::IsEncodingAvailable calls the OS's depending
wxGetNativeFontEncoding, which (in Win32) works with a small group of
charsets, not codepages (that's why IsEncodingAvailable fails on
many wxFONTENCODING_xxxs). Making wx capable of managing _all_ system
encodings is a big work, if not backwards incompatible.

Separating all of wxMBConv from fonts and wxFONTENCODING_xxxs,
seems a smaller job, but still backwards incompatible.

Regards,
Manolo




More information about the wx-users mailing list