1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/fontenum.cpp
3 // Purpose: wxFontEnumerator class for Windows
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin to add support for font encodings
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontenum.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/fontenum.h"
36 #include "wx/fontmap.h"
38 #include "wx/msw/private.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 class wxFontEnumeratorHelper
47 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
49 // control what exactly are we enumerating
50 bool SetEncoding(wxFontEncoding encoding
);
51 void SetFixedOnly(bool fixedOnly
)
52 { m_fixedOnly
= fixedOnly
; }
54 // call to start enumeration
57 // called by our font enumeration proc
58 bool OnFont(const LPLOGFONT lf
, const LPTEXTMETRIC tm
) const;
61 // the object we forward calls to OnFont() to
62 wxFontEnumerator
*m_fontEnum
;
64 // if != -1, enum only fonts which have this encoding
67 // if not empty, enum only the fonts with this facename
70 // if TRUE, enum only fixed fonts
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 int CALLBACK
wxFontEnumeratorProc(LPLOGFONT lplf
, LPTEXTMETRIC lptm
,
79 DWORD dwStyle
, LONG lParam
);
81 // ============================================================================
83 // ============================================================================
85 // ----------------------------------------------------------------------------
86 // wxFontEnumeratorHelper
87 // ----------------------------------------------------------------------------
89 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
91 m_fontEnum
= fontEnum
;
96 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
98 wxNativeEncodingInfo info
;
99 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
101 if ( !wxTheFontMapper
->GetAltForEncoding(encoding
, &info
) )
103 // no such encodings at all
107 m_charset
= info
.charset
;
108 m_facename
= info
.facename
;
113 #if defined(__GNUWIN32__)
114 #if defined(__MINGW32__) && ((__GNUC__>2) ||((__GNUC__==2) && (__GNUC_MINOR__>=95)))
115 #define wxFONTENUMPROC int(*)(const LOGFONTA *, const TEXTMETRICA *, long unsigned int, LPARAM)
117 #define wxFONTENUMPROC int(*)(ENUMLOGFONTEX *, NEWTEXTMETRICEX*, int, LPARAM)
120 #define wxFONTENUMPROC FONTENUMPROC
123 void wxFontEnumeratorHelper::DoEnumerate()
125 HDC hDC
= ::GetDC(NULL
);
129 lf
.lfCharSet
= m_charset
;
130 wxStrncpy(lf
.lfFaceName
, m_facename
, WXSIZEOF(lf
.lfFaceName
));
131 lf
.lfPitchAndFamily
= 0;
132 ::EnumFontFamiliesEx(hDC
, &lf
, (wxFONTENUMPROC
)wxFontEnumeratorProc
,
133 (LPARAM
)this, 0 /* reserved */) ;
135 ::EnumFonts(hDC
, (LPTSTR
)NULL
, (FONTENUMPROC
)wxFontEnumeratorProc
,
144 ::ReleaseDC(NULL
, hDC
);
147 bool wxFontEnumeratorHelper::OnFont(const LPLOGFONT lf
,
148 const LPTEXTMETRIC tm
) const
152 // check that it's a fixed pitch font (there is *no* error here, the
153 // flag name is misleading!)
154 if ( tm
->tmPitchAndFamily
& TMPF_FIXED_PITCH
)
156 // not a fixed pitch font
161 if ( m_charset
!= -1 )
163 // check that we have the right encoding
164 if ( lf
->lfCharSet
!= m_charset
)
170 return m_fontEnum
->OnFacename(lf
->lfFaceName
);
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
180 wxFontEnumeratorHelper
fe(this);
181 if ( fe
.SetEncoding(encoding
) )
183 fe
.SetFixedOnly(fixedWidthOnly
);
187 // else: no such fonts, unknown encoding
192 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
194 wxFAIL_MSG(wxT("TODO"));
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 int CALLBACK
wxFontEnumeratorProc(LPLOGFONT lplf
, LPTEXTMETRIC lptm
,
204 DWORD dwStyle
, LONG lParam
)
206 // Get rid of any fonts that we don't want...
207 if ( dwStyle
!= TRUETYPE_FONTTYPE
)
209 // continue enumeration
213 wxFontEnumeratorHelper
*fontEnum
= (wxFontEnumeratorHelper
*)lParam
;
215 return fontEnum
->OnFont(lplf
, lptm
);