From ed655bfcde61f6d0c2e2eb9d4967a2889e76c730 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 13 Nov 2017 21:13:20 +0100 Subject: [PATCH] Add wxFontEnumerator::InvalidateCache() This is necessary to recognize new fonts, for example those added using AddPrivateFont(), as being valid: otherwise they were not found in the cache and couldn't be used in wxGTK. --- include/wx/fontenum.h | 5 +++++ interface/wx/fontenum.h | 11 +++++++++++ src/common/fontenumcmn.cpp | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/include/wx/fontenum.h b/include/wx/fontenum.h index 782dc7fd9e..fcdb31f9c1 100644 --- a/include/wx/fontenum.h +++ b/include/wx/fontenum.h @@ -74,6 +74,11 @@ public: // in the user's system static bool IsValidFacename(const wxString &str); + // Invalidate cache used by some of the methods of this class internally. + // This should be called if the list of the fonts available on the system + // changes, for whatever reason. + static void InvalidateCache(); + private: #ifdef wxHAS_UTF8_FONTS // helper for ports that only use UTF-8 encoding natively diff --git a/interface/wx/fontenum.h b/interface/wx/fontenum.h index ba5cfa8cf2..c0da82258f 100644 --- a/interface/wx/fontenum.h +++ b/interface/wx/fontenum.h @@ -73,6 +73,17 @@ public: */ static bool IsValidFacename(const wxString& facename); + /** + Invalidate cache used by some of the methods of this class internally. + + This method should be called if the list of the fonts available on the + system changes, for whatever reason. In particular, it is called + automatically by wxFont::AddPrivateFont(). + + @since 3.1.1 + */ + static void InvalidateCache(); + /** Called by EnumerateFacenames() for each match. diff --git a/src/common/fontenumcmn.cpp b/src/common/fontenumcmn.cpp index a1a1bbf771..183e241287 100644 --- a/src/common/fontenumcmn.cpp +++ b/src/common/fontenumcmn.cpp @@ -127,6 +127,12 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename) return true; } +/* static */ +void wxFontEnumerator::InvalidateCache() +{ + gs_allFacenames.clear(); +} + #ifdef wxHAS_UTF8_FONTS bool wxFontEnumerator::EnumerateEncodingsUTF8(const wxString& facename) {