1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontEnumerator class for getting available fonts
4 // Author: Julian Smart, Vadim Zeitlin
5 // Modified by: extended to enumerate more than just font facenames and works
6 // not only on Windows now (VZ)
9 // Copyright: (c) Julian Smart, Vadim Zeitlin
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_FONTENUM_H_
14 #define _WX_FONTENUM_H_
16 #include "wx/fontenc.h"
17 #include "wx/arrstr.h"
19 // ----------------------------------------------------------------------------
20 // wxFontEnumerator enumerates all available fonts on the system or only the
21 // fonts with given attributes
22 // ----------------------------------------------------------------------------
24 class WXDLLEXPORT wxFontEnumerator
27 wxFontEnumerator() : m_Facenames(NULL
), m_Encodings(NULL
) { }
29 // start enumerating font facenames (either all of them or those which
30 // support the given encoding) - will result in OnFacename() being
31 // called for each available facename (until they are exhausted or
32 // OnFacename returns false)
33 virtual bool EnumerateFacenames
35 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
, // all
36 bool fixedWidthOnly
= false
39 // enumerate the different encodings either for given font facename or for
40 // all facenames - will result in OnFontEncoding() being called for each
41 // available (facename, encoding) couple
42 virtual bool EnumerateEncodings(const wxString
& facename
= wxEmptyString
);
44 // callbacks which are called after one of EnumerateXXX() functions from
45 // above is invoked - all of them may return false to stop enumeration or
46 // true to continue with it
48 // called by EnumerateFacenames
49 virtual bool OnFacename(const wxString
& facename
)
51 if (m_Facenames
== NULL
) m_Facenames
= new wxArrayString
;
52 m_Facenames
-> Add(facename
);
56 // called by EnumerateEncodings
57 virtual bool OnFontEncoding(const wxString
& WXUNUSED(facename
),
58 const wxString
& encoding
)
60 if (m_Encodings
== NULL
) m_Encodings
= new wxArrayString
;
61 m_Encodings
-> Add(encoding
);
65 // convenience function that returns array of facenames. Cannot be called
66 // before EnumerateFacenames.
67 wxArrayString
*GetFacenames()
68 { return m_Facenames
; }
70 // convenience function that returns array of encodings.
71 // Cannot be called before EnumerateEncodings.
72 wxArrayString
*GetEncodings()
73 { return m_Encodings
; }
75 // virtual dtor for the base class
76 virtual ~wxFontEnumerator()
78 if (m_Facenames
) delete m_Facenames
;
79 if (m_Encodings
) delete m_Encodings
;
83 wxArrayString
*m_Facenames
, *m_Encodings
;
85 DECLARE_NO_COPY_CLASS(wxFontEnumerator
)
88 #endif // _WX_FONTENUM_H_