Enumerating encodings

Manuel Martín mmartin at ceyd.es
Mon Dec 11 09:50:54 PST 2006


Hi again

 >On Mon, 11 Dec 2006 17:15:02 +0100 Manuel Martín <mmartin at ceyd.es> >wrote:
 >
 >MM> I'm doing a small applet for changing enconding for a file.
 >MM> First, I have to know OS's available encodings.
 >
 > Why exactly do you need this? If you have an encoding, just try to
 >construct wxCSConv using it.

The applet opens a file, converts it to other encoding and writes a
new file.
Not always encoding is known. I'm thinking in old MS-Dos files made
with code-pages that I can't know before I try them. Here in Spain
437 and 850 code-pages were usual, but depending on PC install.
So, trying one and seeing the result is not a bad idea for a user.
I just give choices.

 >
 >MM> I can use wxFontMapper::GetSupportedEncodingsCount()
 >MM> and then wxFontMapper::IsEncodingAvailable(i)
 >MM> but it discards encodings such as UTF-8.
 >MM> Only works for old code-pages?
 >
 > GetSupportedEncodingsCount() and related GetEncoding[Name]() functions
 >simply work with the few standard encodings wxWidgets knows about, this
 >doesn't mean at all that the underlying OS supports them or doesn't 
 >support
 >any other ones. IsEncodingAvailable() also only works for the encodings
 >wxWidgets knows about, of course.

Yes, but I can see in fmapbase.cpp several encodings I would like to use
and IsEncodingAvailable() returns false for them (such as UTF8)

 >
 >MM> I tried to use wxFontEnumerator::GetEncodings()
 >MM> but asserts (fontutil.cpp (189)) for unknown encodings on my >system.
 >MM> Is it that 'unknown = not recognized by wx' ?
 >
 > Yes.
 >
 >MM> I wonder why is wrong using encoding = wxFONTENCODING_DEFAULT.
 >
 > I don't really understand the question but I can confirm that it's >wrong
 >to use wxFONTENCODING_DEFAULT in wxCSConv ctor.

Most of the work is done using wxTextFile.
I understand I must use one wxCSConv for opening the file, and
other wxCSConv for writing it. The last one may be the default, in
the sense of wxFONTENCODING_DEFAULT, the system's one, isn't it?

 >
 >MM> It also launches error "cannot convert from the charset ..." for 
 >charsets
 >MM> Thai, Indian and EUC-JP.
 >MM> I wonder why wxCSConv ctor was able to init from a not-installed 
 >charset.
 >
 > Basically because it's implemented to only initialize itself on demand
 >(quite often conversion objects are created but not used and creating 
 >them
 >can be relatively expensive) and also because in some cases (like under
 >Win32 which you appear to use) we don't really know whether the 
 >conversion
 >is going to work before trying it. I agree that it would be useful to 
 >have
 >wxCSConv::CanConvert() or IsOk() to test for those cases.
 >
 >MM> I run out of ideas. What can I do?
 >
 > What do you need to do exactly?
 >VZ

Detailed explanation:
I have files with different encodigs: A file is an old MS-Dos file;
other file is the result of an application that writes 8-bit chars,
but I don't know which encoding it uses internally; other file is
encoded in my system's default, but I want to convert it to UTF for
mailing to other country; other is c++ code written before I began
using Unicode and now all my sources are UTF8; and so on.
So, I'm making this convert-applet.

I don't really need all of libconv. OS's capabilities are enough.
But I need to know these capabilities in order to choose the
wxCSConv objects to do conversion in wxTextFile.

Thanks
Manolo





More information about the wx-users mailing list