diff --git a/src/common/fontenumcmn.cpp b/src/common/fontenumcmn.cpp index d0df597226..a1a1bbf771 100644 --- a/src/common/fontenumcmn.cpp +++ b/src/common/fontenumcmn.cpp @@ -26,6 +26,31 @@ #if wxUSE_FONTENUM #include "wx/fontenum.h" +#include "wx/module.h" + +namespace +{ + +// Cached result of GetFacenames(). +wxArrayString gs_allFacenames; + +// Module used to ensure the cache is cleared on library shutdown and so is not +// reused if it re-initialized again later. +class wxFontEnumCacheCleanupModule : public wxModule +{ +public: + wxFontEnumCacheCleanupModule() { } + + bool OnInit() wxOVERRIDE { return true; } + void OnExit() wxOVERRIDE { gs_allFacenames.clear(); } + +private: + wxDECLARE_DYNAMIC_CLASS(wxFontEnumCacheCleanupModule); +}; + +wxIMPLEMENT_DYNAMIC_CLASS(wxFontEnumCacheCleanupModule, wxModule); + +} // anonymous namespace // ============================================================================ // implementation @@ -79,7 +104,8 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename) { // we cache the result of wxFontEnumerator::GetFacenames supposing that // the array of face names won't change in the session of this program - static wxArrayString s_arr = wxFontEnumerator::GetFacenames(); + if ( gs_allFacenames.empty() ) + gs_allFacenames = wxFontEnumerator::GetFacenames(); #ifdef __WXMSW__ // Quoting the MSDN: @@ -95,7 +121,7 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename) #endif // is given font face name a valid one ? - if (s_arr.Index(facename, false) == wxNOT_FOUND) + if (gs_allFacenames.Index(facename, false) == wxNOT_FOUND) return false; return true;