1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/common/fontenumcmn.cpp 
   3 // Purpose:     wxFontEnumerator class 
   4 // Author:      Vadim Zeitlin 
   7 // Copyright:   (c) 1999-2003 Vadim Zeitlin <vadim@wxwindows.org> 
   8 // Licence:     wxWindows licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  11 // ============================================================================ 
  13 // ============================================================================ 
  15 // ---------------------------------------------------------------------------- 
  17 // ---------------------------------------------------------------------------- 
  19 // For compilers that support precompilation, includes "wx.h". 
  20 #include "wx/wxprec.h" 
  28 #include "wx/fontenum.h" 
  30 // ============================================================================ 
  32 // ============================================================================ 
  34 // A simple wxFontEnumerator which doesn't perform any filtering and 
  35 // just returns all facenames and encodings found in the system 
  36 class WXDLLEXPORT wxSimpleFontEnumerator 
: public wxFontEnumerator
 
  39     wxSimpleFontEnumerator() { } 
  41     // called by EnumerateFacenames 
  42     virtual bool OnFacename(const wxString
& facename
) 
  44         m_arrFacenames
.Add(facename
); 
  48     // called by EnumerateEncodings 
  49     virtual bool OnFontEncoding(const wxString
& WXUNUSED(facename
), 
  50                                 const wxString
& encoding
) 
  52         m_arrEncodings
.Add(encoding
); 
  57     wxArrayString m_arrFacenames
, m_arrEncodings
; 
  62 wxArrayString 
wxFontEnumerator::GetFacenames(wxFontEncoding encoding
, bool fixedWidthOnly
) 
  64     wxSimpleFontEnumerator temp
; 
  65     temp
.EnumerateFacenames(encoding
, fixedWidthOnly
); 
  66     return temp
.m_arrFacenames
; 
  70 wxArrayString 
wxFontEnumerator::GetEncodings(const wxString
& facename
) 
  72     wxSimpleFontEnumerator temp
; 
  73     temp
.EnumerateEncodings(facename
); 
  74     return temp
.m_arrEncodings
; 
  78 bool wxFontEnumerator::IsValidFacename(const wxString 
&facename
) 
  80     // we cache the result of wxFontEnumerator::GetFacenames supposing that 
  81     // the array of face names won't change in the session of this program 
  82     static wxArrayString s_arr 
= wxFontEnumerator::GetFacenames(); 
  86     //     "MS Shell Dlg is a mapping mechanism that enables 
  87     //     U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to 
  88     //     support locales that have characters that are not contained in code 
  89     //     page 1252. It is not a font but a face name for a nonexistent font." 
  90     // Thus we need to consider "Ms Shell Dlg" and "Ms Shell Dlg 2" as valid 
  91     // font face names even if they are not enumerated by wxFontEnumerator 
  92     if (facename
.IsSameAs(wxT("Ms Shell Dlg"), false) || 
  93         facename
.IsSameAs(wxT("Ms Shell Dlg 2"), false)) 
  97     // is given font face name a valid one ? 
  98     if (s_arr
.Index(facename
, false) == wxNOT_FOUND
) 
 104 #ifdef wxHAS_UTF8_FONTS 
 105 bool wxFontEnumerator::EnumerateEncodingsUTF8(const wxString
& facename
) 
 107     // name of UTF-8 encoding: no need to use wxFontMapper for it as it's 
 108     // unlikely to change 
 109     const wxString 
utf8(wxT("UTF-8")); 
 111     // all fonts are in UTF-8 only if this code is used 
 112     if ( !facename
.empty() ) 
 114         OnFontEncoding(facename
, utf8
); 
 118     // so enumerating all facenames supporting this encoding is the same as 
 119     // enumerating all facenames 
 120     const wxArrayString 
facenames(GetFacenames(wxFONTENCODING_UTF8
)); 
 121     const size_t count 
= facenames
.size(); 
 125     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 127         OnFontEncoding(facenames
[n
], utf8
); 
 132 #endif // wxHAS_UTF8_FONTS 
 134 #endif // wxUSE_FONTENUM