X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3a989c8afe4681b3ccadfc8054aff0448a6c7a94..9f4de6b2cf06f53a98b28f53640f3b9ec8cf4182:/src/common/fontmap.cpp?ds=sidebyside diff --git a/src/common/fontmap.cpp b/src/common/fontmap.cpp index c93277a60d..c976d72af6 100644 --- a/src/common/fontmap.cpp +++ b/src/common/fontmap.cpp @@ -36,6 +36,7 @@ #include "wx/intl.h" #endif // PCH +#include "wx/module.h" #include "wx/fontmap.h" #if wxUSE_CONFIG @@ -177,15 +178,6 @@ static const wxChar* gs_encodingNames[] = wxT( "utf-8" ), }; -// ---------------------------------------------------------------------------- -// global data -// ---------------------------------------------------------------------------- - -// private object -static wxFontMapper gs_fontMapper; - -// and public pointer -wxFontMapper * wxTheFontMapper = &gs_fontMapper; // ---------------------------------------------------------------------------- // private classes @@ -243,6 +235,34 @@ wxFontMapper::~wxFontMapper() #endif // wxUSE_CONFIG } +wxFontMapper *wxFontMapper::sm_instance = NULL; + +/*static*/ wxFontMapper *wxFontMapper::Get() +{ + if ( !sm_instance ) + sm_instance = new wxFontMapper; + return sm_instance; +} + +/*static*/ wxFontMapper *wxFontMapper::Set(wxFontMapper *mapper) +{ + wxFontMapper *old = sm_instance; + sm_instance = mapper; + return old; +} + +class wxFontMapperModule: public wxModule +{ +public: + wxFontMapperModule() : wxModule() {} + virtual bool OnInit() { return TRUE; } + virtual void OnExit() { delete wxFontMapper::Set(NULL); } + + DECLARE_DYNAMIC_CLASS(wxFontMapperModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule, wxModule) + // ---------------------------------------------------------------------------- // customisation // ---------------------------------------------------------------------------- @@ -479,7 +499,7 @@ wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset, cs.Trim(FALSE); // discard the optional quotes - if ( !!cs ) + if ( !cs.empty() ) { if ( cs[0u] == _T('"') && cs.Last() == _T('"') ) { @@ -489,7 +509,7 @@ wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset, cs.MakeUpper(); - if ( !cs || cs == wxT("US-ASCII") ) + if ( cs.empty() || cs == _T("US-ASCII") ) { encoding = wxFONTENCODING_DEFAULT; } @@ -743,9 +763,9 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, // message if ( encoding == wxFONTENCODING_SYSTEM ) { - wxFatalError(_("can't load any font, aborting")); + wxLogFatalError(_("can't load any font, aborting")); - // wxFatalError doesn't return + // wxLogFatalError doesn't return } wxString configEntry, @@ -810,7 +830,7 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, wxFontEncodingArray equiv = wxEncodingConverter::GetAllEquivalents(encoding); size_t count = equiv.GetCount(); bool foundEquivEncoding = FALSE; - wxFontEncoding equivEncoding; + wxFontEncoding equivEncoding = wxFONTENCODING_SYSTEM; if ( count ) { for ( size_t i = 0; i < count && !foundEquivEncoding; i++ )