Enumerating encodings

Manuel Martín mmartin at ceyd.es
Mon Dec 11 08:15:02 PST 2006


Hi

wx270, Unicode build
Windows XP SP2
MingW

I'm doing a small applet for changing enconding for a file.
First, I have to know OS's available encodings.

I can use wxFontMapper::GetSupportedEncodingsCount()
and then wxFontMapper::IsEncodingAvailable(i)
but it discards encodings such as UTF-8.
Only works for old code-pages?

I tried to use wxFontEnumerator::GetEncodings()
but asserts (fontutil.cpp (189)) for unknown encodings on my system.
Is it that 'unknown = not recognized by wx' ?

Then I tried to test each wx predefined encoding:

bool ConvCharDoIt::FillArrayOfEncondigs (wxArrayString* EncodArray)
{
     wxFontMapper* fomap = wxFontMapper::Get();
     if (!fomap)
         return false;

     size_t nenc = fomap->GetSupportedEncodingsCount();
     size_t i = 0;
     wxFontEncoding encoding;
     wxString foname;
     wchar_t *wstr = L"tes"; //A widechar string for testing
     size_t re = 0;
     wxCSConv* conv;
     for (i=0; i < nenc; i++)
     {   //check if this encoding can be used
         encoding = fomap->GetEncoding(i);
         conv = new wxCSConv(encoding); //Use wx predefined encodings
         re = conv->WC2MB(NULL, wstr, 4); //NULL means 'just tell me 
lenght needed'
         if(conv)
             delete conv;
         if (re != wxCONV_FAILED)
         {   foname = fomap->GetEncodingName(encoding);
             foname.Append(wxT(" : "));
             foname.Append(fomap->GetEncodingDescription(encoding));
             EncodArray->Add(foname);
         }
     }
     if (EncodArray->IsEmpty())
         return false;
     return true;
}

Now its asserts on strconv.cpp (3215) 'invalid encoding'
I wonder why is wrong using encoding = wxFONTENCODING_DEFAULT.

It also launches error "cannot convert from the charset ..." for charsets
Thai, Indian and EUC-JP.
I wonder why wxCSConv ctor was able to init from a not-installed charset.

I run out of ideas. What can I do?

Thanks in advance
Manolo





More information about the wx-users mailing list