1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/fontenumcmn.cpp
3 // Purpose: wxFontEnumerator class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999-2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/fontenum.h"
31 // ============================================================================
33 // ============================================================================
35 // A simple wxFontEnumerator which doesn't perform any filtering and
36 // just returns all facenames and encodings found in the system
37 class WXDLLEXPORT wxSimpleFontEnumerator
: public wxFontEnumerator
40 wxSimpleFontEnumerator() { }
42 // called by EnumerateFacenames
43 virtual bool OnFacename(const wxString
& facename
)
45 m_arrFacenames
.Add(facename
);
49 // called by EnumerateEncodings
50 virtual bool OnFontEncoding(const wxString
& WXUNUSED(facename
),
51 const wxString
& encoding
)
53 m_arrEncodings
.Add(encoding
);
58 wxArrayString m_arrFacenames
, m_arrEncodings
;
63 wxArrayString
wxFontEnumerator::GetFacenames(wxFontEncoding encoding
, bool fixedWidthOnly
)
65 wxSimpleFontEnumerator temp
;
66 temp
.EnumerateFacenames(encoding
, fixedWidthOnly
);
67 return temp
.m_arrFacenames
;
71 wxArrayString
wxFontEnumerator::GetEncodings(const wxString
& facename
)
73 wxSimpleFontEnumerator temp
;
74 temp
.EnumerateEncodings(facename
);
75 return temp
.m_arrEncodings
;
79 bool wxFontEnumerator::IsValidFacename(const wxString
&facename
)
81 // we cache the result of wxFontEnumerator::GetFacenames supposing that
82 // the array of face names won't change in the session of this program
83 static wxArrayString s_arr
= wxFontEnumerator::GetFacenames();
87 // "MS Shell Dlg is a mapping mechanism that enables
88 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
89 // support locales that have characters that are not contained in code
90 // page 1252. It is not a font but a face name for a nonexistent font."
91 // Thus we need to consider "Ms Shell Dlg" and "Ms Shell Dlg 2" as valid
92 // font face names even if they are not enumerated by wxFontEnumerator
93 if (facename
.IsSameAs(wxT("Ms Shell Dlg"), false) ||
94 facename
.IsSameAs(wxT("Ms Shell Dlg 2"), false))
98 // is given font face name a valid one ?
99 if (s_arr
.Index(facename
, false) == wxNOT_FOUND
)
105 #ifdef wxHAS_UTF8_FONTS
106 bool wxFontEnumerator::EnumerateEncodingsUTF8(const wxString
& facename
)
108 // name of UTF-8 encoding: no need to use wxFontMapper for it as it's
109 // unlikely to change
110 const wxString
utf8(_T("UTF-8"));
112 // all fonts are in UTF-8 only if this code is used
113 if ( !facename
.empty() )
115 OnFontEncoding(facename
, utf8
);
119 // so enumerating all facenames supporting this encoding is the same as
120 // enumerating all facenames
121 const wxArrayString
facenames(GetFacenames(wxFONTENCODING_UTF8
));
122 const size_t count
= facenames
.size();
126 for ( size_t n
= 0; n
< count
; n
++ )
128 OnFontEncoding(facenames
[n
], utf8
);
133 #endif // wxHAS_UTF8_FONTS
135 #endif // wxUSE_FONTENUM