fixes to handling of the 7 bit ASCII encoding

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13799 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-01-25 14:29:33 +00:00
parent 1c405bb510
commit cafbf6fb1f
4 changed files with 61 additions and 37 deletions

View File

@@ -143,10 +143,8 @@ public:
// the default encoding is used for creating all fonts with default // the default encoding is used for creating all fonts with default
// encoding parameter // encoding parameter
static wxFontEncoding GetDefaultEncoding() static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
{ return ms_encodingDefault; } static void SetDefaultEncoding(wxFontEncoding encoding);
static void SetDefaultEncoding(wxFontEncoding encoding)
{ ms_encodingDefault = encoding; }
protected: protected:
// get the internal data // get the internal data

View File

@@ -49,6 +49,17 @@
wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM; wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM;
/* static */
void wxFontBase::SetDefaultEncoding(wxFontEncoding encoding)
{
// GetDefaultEncoding() should return something != wxFONTENCODING_DEFAULT
// and, besides, using this value here doesn't make any sense
wxCHECK_RET( encoding != wxFONTENCODING_DEFAULT,
_T("can't set default encoding to wxFONTENCODING_DEFAULT") );
ms_encodingDefault = encoding;
}
wxFontBase::~wxFontBase() wxFontBase::~wxFontBase()
{ {
// this destructor is required for Darwin // this destructor is required for Darwin

View File

@@ -489,10 +489,7 @@ wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset,
cs.MakeUpper(); cs.MakeUpper();
// nl_langinfo() under Solaris returns 646 by default which stands for if ( cs.empty() || cs == _T("US-ASCII") )
// ISO-646, i.e. 7 bit ASCII and we should recognize it to avoid
// warnings about unrecognized encoding on each program startup
if ( cs.empty() || cs == _T("US-ASCII") || cs == _T("646") )
{ {
encoding = wxFONTENCODING_DEFAULT; encoding = wxFONTENCODING_DEFAULT;
} }

View File

@@ -858,7 +858,8 @@ public:
{ {
if (name) if (name)
enc = wxTheFontMapper->CharsetToEncoding(name, FALSE); enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
m2w.Init(enc, wxFONTENCODING_UNICODE);
m_ok = m2w.Init(enc, wxFONTENCODING_UNICODE) &&
w2m.Init(wxFONTENCODING_UNICODE, enc); w2m.Init(wxFONTENCODING_UNICODE, enc);
} }
@@ -884,12 +885,14 @@ public:
return inbuf; return inbuf;
} }
bool usable() const bool usable() const { return m_ok; }
{ return (enc!=wxFONTENCODING_SYSTEM) && (enc!=wxFONTENCODING_DEFAULT); }
public: public:
wxFontEncoding enc; wxFontEncoding enc;
wxEncodingConverter m2w, w2m; wxEncodingConverter m2w, w2m;
// were we initialized successfully?
bool m_ok;
}; };
#endif // wxUSE_FONTMAP #endif // wxUSE_FONTMAP
@@ -901,46 +904,61 @@ public:
static wxCharacterSet *wxGetCharacterSet(const wxChar *name) static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
{ {
wxCharacterSet *cset = NULL; // check for the special case of ASCII charset
if (name) #if wxUSE_FONTMAP
if ( wxTheFontMapper->CharsetToEncoding(name) == wxFONTENCODING_DEFAULT )
#else // wxUSE_FONTMAP
if ( !name )
#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
{ {
if (wxStricmp(name, wxT("UTF8")) == 0 || wxStricmp(name, wxT("UTF-8")) == 0) // don't convert at all
return NULL;
}
// the test above must have taken care of this case
wxCHECK_MSG( name, NULL, _T("NULL name must be wxFONTENCODING_DEFAULT") );
wxCharacterSet *cset;
if ( wxStricmp(name, wxT("UTF8")) == 0 || wxStricmp(name, wxT("UTF-8")) == 0)
{ {
cset = new ID_CharSet(name, &wxConvUTF8); cset = new ID_CharSet(name, &wxConvUTF8);
} }
else else
{ {
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
cset = new IC_CharSet(name); // may not take NULL cset = new IC_CharSet(name);
#endif #else // !HAVE_ICONV
} cset = NULL;
#endif // HAVE_ICONV/!HAVE_ICONV
} }
if (cset && cset->usable()) if ( cset->usable() )
return cset; return cset;
if (cset)
{
delete cset; delete cset;
cset = NULL; cset = NULL;
}
#if defined(__WIN32__) && !defined(__WXMICROWIN__) #if defined(__WIN32__) && !defined(__WXMICROWIN__)
cset = new CP_CharSet(name); // may take NULL cset = new CP_CharSet(name);
if (cset->usable()) if ( cset->usable() )
return cset; return cset;
delete cset; delete cset;
cset = NULL;
#endif // __WIN32__ #endif // __WIN32__
#if wxUSE_FONTMAP #if wxUSE_FONTMAP
cset = new EC_CharSet(name); cset = new EC_CharSet(name);
if (cset->usable()) if ( cset->usable() )
return cset; return cset;
#endif // wxUSE_FONTMAP
delete cset; delete cset;
wxLogError(_("Unknown encoding '%s'!"), name); cset = NULL;
#endif // wxUSE_FONTMAP
wxLogError(_("Cannot convert from encoding '%s'!"), name);
return NULL; return NULL;
} }