git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13799
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// the default encoding is used for creating all fonts with default
// encoding parameter
// the default encoding is used for creating all fonts with default
// encoding parameter
- static wxFontEncoding GetDefaultEncoding()
- { return ms_encodingDefault; }
- static void SetDefaultEncoding(wxFontEncoding encoding)
- { ms_encodingDefault = encoding; }
+ static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
+ static void SetDefaultEncoding(wxFontEncoding encoding);
protected:
// get the internal data
protected:
// get the internal data
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()
{
// this destructor is required for Darwin
wxFontBase::~wxFontBase()
{
// this destructor is required for Darwin
- // nl_langinfo() under Solaris returns 646 by default which stands for
- // 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") )
+ if ( cs.empty() || cs == _T("US-ASCII") )
{
encoding = wxFONTENCODING_DEFAULT;
}
{
encoding = wxFONTENCODING_DEFAULT;
}
{
if (name)
enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
{
if (name)
enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
- m2w.Init(enc, wxFONTENCODING_UNICODE);
- w2m.Init(wxFONTENCODING_UNICODE, enc);
+
+ m_ok = m2w.Init(enc, wxFONTENCODING_UNICODE) &&
+ w2m.Init(wxFONTENCODING_UNICODE, enc);
}
size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
}
size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
- bool usable() const
- { return (enc!=wxFONTENCODING_SYSTEM) && (enc!=wxFONTENCODING_DEFAULT); }
+ bool usable() const { return m_ok; }
public:
wxFontEncoding enc;
wxEncodingConverter m2w, w2m;
public:
wxFontEncoding enc;
wxEncodingConverter m2w, w2m;
+
+ // were we initialized successfully?
+ bool m_ok;
};
#endif // wxUSE_FONTMAP
};
#endif // wxUSE_FONTMAP
static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
{
static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
{
- wxCharacterSet *cset = NULL;
- if (name)
+ // check for the special case of ASCII charset
+#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)
- {
- cset = new ID_CharSet(name, &wxConvUTF8);
- }
- else
- {
-#ifdef HAVE_ICONV
- cset = new IC_CharSet(name); // may not take NULL
-#endif
- }
+ // don't convert at all
+ return NULL;
- if (cset && cset->usable())
- return cset;
+ // 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);
+ }
+ else
+#ifdef HAVE_ICONV
+ cset = new IC_CharSet(name);
+#else // !HAVE_ICONV
+#endif // HAVE_ICONV/!HAVE_ICONV
+ if ( cset->usable() )
+ return cset;
+
+ delete cset;
+ cset = NULL;
+
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
- cset = new CP_CharSet(name); // may take NULL
- if (cset->usable())
+ cset = new CP_CharSet(name);
+ if ( cset->usable() )
return cset;
delete cset;
return cset;
delete cset;
#endif // __WIN32__
#if wxUSE_FONTMAP
cset = new EC_CharSet(name);
#endif // __WIN32__
#if wxUSE_FONTMAP
cset = new EC_CharSet(name);
- wxLogError(_("Unknown encoding '%s'!"), name);
+ cset = NULL;
+#endif // wxUSE_FONTMAP
+
+ wxLogError(_("Cannot convert from encoding '%s'!"), name);
+