X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad9835c97c10c0d7de345e3a7a7c0fc2776eb2cb..ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf:/src/unix/fontenum.cpp diff --git a/src/unix/fontenum.cpp b/src/unix/fontenum.cpp index 3f4f7ae079..25ab081632 100644 --- a/src/unix/fontenum.cpp +++ b/src/unix/fontenum.cpp @@ -20,16 +20,17 @@ // for compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#include "wx/fontenum.h" + #ifndef WX_PRECOMP #include "wx/dynarray.h" + #include "wx/string.h" + #include "wx/app.h" + #include "wx/utils.h" #endif -#include "wx/string.h" #include "wx/regex.h" -#include "wx/utils.h" -#include "wx/app.h" #include "wx/fontmap.h" -#include "wx/fontenum.h" #include "wx/fontutil.h" #include "wx/encinfo.h" @@ -55,20 +56,26 @@ wxCompareFamilies (const void *a, const void *b) return g_utf8_collate (a_name, b_name); } -// I admit I don't yet understand encodings with Pango bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, bool fixedWidthOnly) { + if ( encoding != wxFONTENCODING_SYSTEM && encoding != wxFONTENCODING_UTF8 ) + { + // Pango supports only UTF-8 encoding (and system means any, so we + // accept it too) + return false; + } + #if defined(__WXGTK20__) || !defined(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE) if ( fixedWidthOnly #if defined(__WXGTK24__) && (gtk_check_version(2,4,0) != NULL) #endif ) -{ + { OnFacename( wxT("monospace") ); } - else + else // !fixedWidthOnly #endif // __WXGTK20__ || !HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE { PangoFontFamily **families = NULL; @@ -103,14 +110,37 @@ bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, return true; } -bool wxFontEnumerator::EnumerateEncodings(const wxString& family) +bool wxFontEnumerator::EnumerateEncodings(const wxString& facename) { - return false; + // name of UTF-8 encoding: no need to use wxFontMapper for it as it's + // unlikely to change + const wxString utf8(_T("UTF-8")); + + + // all fonts are in UTF-8 only when using Pango + if ( !facename.empty() ) + { + OnFontEncoding(facename, utf8); + return true; + } + + // so enumerating all facenames supporting this encoding is the same as + // enumerating all facenames + const wxArrayString facenames(GetFacenames(wxFONTENCODING_UTF8)); + const size_t count = facenames.size(); + if ( !count ) + return false; + + for ( size_t n = 0; n < count; n++ ) + { + OnFontEncoding(facenames[n], utf8); + } + + return true; } -#else - // Pango +#else // !wxUSE_PANGO #ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++ // The resulting warnings are switched off here @@ -197,6 +227,7 @@ static bool ProcessFamiliesFromFontList(wxFontEnumerator *This, continue; } + // coverity[returned_null] char *dash = strchr(font + 1, '-'); char *family = dash + 1; dash = strchr(family, '-');