Charset GB1830

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Widgets
Super wx Problem Solver
Super wx Problem Solver
Posts: 322
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Charset GB1830

Postby Widgets » Fri Jun 22, 2018 2:58 am

Win 10, MSVC 2015, MSVC 2010 tool chain, wxWidgets 3.1.0

Just now I have run into an issue with my mail screener and the charset gb1830. An incoming message has some fields encoded in GB1830 and I am trying to use code such as

Code: Select all

wxFontEncoding text_encoding = wxFontMapper::Get()->CharsetToEncoding(char_set);
wxFontEncoding system_encoding = wxLocale::GetSystemEncoding();
wxFontEncoding fontenc = wxFontMapper::Get()->CharsetToEncoding(char_set);
if ( fontenc == wxFONTENCODING_SYSTEM )
{
     wxLogError(wxT("Charset '%s' is unsupported."), char_set.c_str());
     return str;
}
wxEncodingConverter converter;
bool can_convert = converter.Init(text_encoding, system_encoding);
if (can_convert)
{
    str_content = converter.Convert(str);
}

to check if the char set is supported.
The string char_set is "gb1830' and the call to Get()->CharsetToEncoding(char_set) returns wxFONTENCODING_ISO8859_1 instead of wxFONTENCODING_SYSTEM, implying that the character set is supported, but enum wxFontEncoding does not include any such character set and of course,the decoded string is all wrong.
What am I missing.
TIA
Environment: Win 10 64-bit & Ubuntu 16.04
MSVC Express 2010 & 2015
wxWidgets 3.1
Fight SPAM - report it with wxSR

User avatar
doublemax
Moderator
Moderator
Posts: 12614
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Charset GB1830

Postby doublemax » Fri Jun 22, 2018 8:57 am

Doing a fulltext search on the wxWidgets sources, i see no support for GB1830. But i see support for GB2312 and CP932 which - according to Wikipedia - are related. Give it a try.
Use the source, Luke!

Widgets
Super wx Problem Solver
Super wx Problem Solver
Posts: 322
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Re: Charset GB1830

Postby Widgets » Fri Jun 22, 2018 7:06 pm

My code to test for the availability of GB1830 came from the font sample.

I have meanwhile tried to follow the trail into the wxWidgets code and it is very confusing.

Code: Select all

wxFontEncoding fontenc = wxFontMapper::Get()->CharsetToEncoding(char_set);
->

Code: Select all

wxFontMapperBase::NonInteractiveCharsetToEncoding(const wxString& charset)
...
// try the ways not needing the users intervention first
int encoding = wxFontMapperBase::NonInteractiveCharsetToEncoding(charset);

because I do use a config file, it seems wxUSE_CONFIG & wxUSE_FILECONFIG are both true/defined
->

Code: Select all

bool wxFontMapperBase::ChangePath(const wxString& pathNew, wxString *pathOld)

which tries to set the path to "/wxWindows/FontMapper/Charsets"
and returns m_ok = true, but there is no such path on my system, though I suppose it expects some such path in my config file, which, of course does not exist.
Despite all of this, the call finally returns wxFONTENCODING_ISO8859_1 (0x00000001), which won't do, but leads the code to act as though everything is OK.
Conclusion: the code to check for the availability does not do what I would have expected :(

I appreciate your suggestion and will try to see what it will get me, though I suspect I will have to try a non-wxWidgets solution.
Since the input is from an external source and some of the more esoteric characters sets will no doubt be more and more widely used, I'd prefer not to have to test for or handle specific ones in special ways.

Still, I am open to suggestions
FWIW, Thunderbird handles the strings without issues, so I would expect some compatible font is available - though not being familiar with that language, I could never be sure in any case :D
Environment: Win 10 64-bit & Ubuntu 16.04
MSVC Express 2010 & 2015
wxWidgets 3.1
Fight SPAM - report it with wxSR


Return to “C++ Development”

Who is online

Users browsing this forum: Google [Bot] and 13 guests