From: Václav Slavík <vslavik@fastmail.fm>
Date: Fri, 1 Dec 2006 10:14:28 +0000 (+0000)
Subject: implemented wxFontEnumerator for wxDFB
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4e1d79d308a7c2eda0c02ed496f1b25dad39a2c8

implemented wxFontEnumerator for wxDFB


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43727 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/include/wx/fontenum.h b/include/wx/fontenum.h
index 8544e0dc49..9a669505dd 100644
--- a/include/wx/fontenum.h
+++ b/include/wx/fontenum.h
@@ -16,6 +16,11 @@
 #include "wx/fontenc.h"
 #include "wx/arrstr.h"
 
+#if wxUSE_PANGO || defined(__WXDFB__)
+    // defined if the port uses only UTF-8 font encodings internally
+    #define wxHAS_UTF8_FONTS
+#endif
+
 // ----------------------------------------------------------------------------
 // wxFontEnumerator enumerates all available fonts on the system or only the
 // fonts with given attributes
@@ -72,6 +77,11 @@ public:
     static bool IsValidFacename(const wxString &str);
 
 private:
+#ifdef wxHAS_UTF8_FONTS
+    // helper for ports that only use UTF-8 encoding natively
+    bool EnumerateEncodingsUTF8(const wxString& facename);
+#endif
+
     DECLARE_NO_COPY_CLASS(wxFontEnumerator)
 };
 
diff --git a/src/common/fontenumcmn.cpp b/src/common/fontenumcmn.cpp
index fb57dd9104..c2ef4c8820 100644
--- a/src/common/fontenumcmn.cpp
+++ b/src/common/fontenumcmn.cpp
@@ -100,3 +100,32 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename)
     return true;
 }
 
+#ifdef wxHAS_UTF8_FONTS
+bool wxFontEnumerator::EnumerateEncodingsUTF8(const wxString& facename)
+{
+    // 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 if this code is used
+    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;
+}
+#endif // wxHAS_UTF8_FONTS
diff --git a/src/dfb/fontenum.cpp b/src/dfb/fontenum.cpp
index 4e1f9050cc..fe1e05340e 100644
--- a/src/dfb/fontenum.cpp
+++ b/src/dfb/fontenum.cpp
@@ -16,21 +16,36 @@
 #endif
 
 #include "wx/fontenum.h"
+#include "wx/private/fontmgr.h"
 
 // ----------------------------------------------------------------------------
 // wxFontEnumerator
 // ----------------------------------------------------------------------------
 
-bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding WXUNUSED(encoding),
-                                          bool WXUNUSED(fixedWidthOnly))
+bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
+                                          bool fixedWidthOnly)
 {
-    // FIXME_DFB
-    OnFacename(_T("Default"));
-    return true;
+    // we only support UTF-8 and system (which means "use any"):
+    if ( encoding != wxFONTENCODING_SYSTEM && encoding != wxFONTENCODING_UTF8 )
+        return false;
+
+    bool found = false;
+    const wxFontBundleList& list = wxFontsManager::Get()->GetBundles();
+
+    for ( wxFontBundleList::const_iterator f = list.begin(); f != list.end(); ++f )
+    {
+        if ( fixedWidthOnly && !(*f)->IsFixed() )
+            continue;
+
+        found = true;
+        if ( !OnFacename((*f)->GetName()) )
+            break; // OnFacename() requests us to stop enumeration
+    }
+
+    return found;
 }
 
-bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family))
+bool wxFontEnumerator::EnumerateEncodings(const wxString& facename)
 {
-    // FIXME_DFB
-    return false;
+    return EnumerateEncodingsUTF8(facename);
 }
diff --git a/src/unix/fontenum.cpp b/src/unix/fontenum.cpp
index 25ab081632..e09f06170e 100644
--- a/src/unix/fontenum.cpp
+++ b/src/unix/fontenum.cpp
@@ -112,31 +112,7 @@ bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
 
 bool wxFontEnumerator::EnumerateEncodings(const wxString& facename)
 {
-    // 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;
+    return EnumerateEncodingsUTF8(facename);
 }