1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/fontenum.cpp
3 // Purpose: wxFontEnumerator class for Windows
4 // Author: Julian Smart
5 // Modified by: David Webster to add support for font encodings
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/fontenum.h"
28 #include "wx/fontmap.h"
30 #include "wx/os2/private.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class wxFontEnumeratorHelper
39 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
41 // control what exactly are we enumerating
42 bool SetEncoding(wxFontEncoding encoding
);
43 void SetFixedOnly(bool fixedOnly
)
44 { m_fixedOnly
= fixedOnly
; }
46 // call to start enumeration
49 // called by our font enumeration proc
50 bool OnFont(/*const LPLOGFONT lf, const LPTEXTMETRIC tm*/) const;
53 // the object we forward calls to OnFont() to
54 wxFontEnumerator
*m_fontEnum
;
56 // if != -1, enum only fonts which have this encoding
59 // if not empty, enum only the fonts with this facename
62 // if TRUE, enum only fixed fonts
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
72 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
73 DWORD dwStyle, LONG lParam);
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
81 // wxFontEnumeratorHelper
82 // ----------------------------------------------------------------------------
84 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
86 m_fontEnum
= fontEnum
;
91 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
93 wxNativeEncodingInfo info
;
94 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
96 if ( !wxTheFontMapper
->GetAltForEncoding(encoding
, &info
) )
98 // no such encodings at all
102 m_charset
= info
.charset
;
103 m_facename
= info
.facename
;
108 #define wxFONTENUMPROC FONTENUMPROC
110 void wxFontEnumeratorHelper::DoEnumerate()
114 HDC hDC = ::GetDC(NULL);
118 lf.lfCharSet = m_charset;
119 wxStrncpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName));
120 lf.lfPitchAndFamily = 0;
121 ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc,
124 ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc,
133 ::ReleaseDC(NULL, hDC);
137 bool wxFontEnumeratorHelper::OnFont(/*const LPLOGFONT lf,
138 const LPTEXTMETRIC tm */) const
144 // check that it's a fixed pitch font (there is *no* error here, the
145 // flag name is misleading!)
146 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
148 // not a fixed pitch font
153 if ( m_charset != -1 )
155 // check that we have the right encoding
156 if ( lf->lfCharSet != m_charset )
162 return m_fontEnum->OnFacename(lf->lfFaceName);
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
174 wxFontEnumeratorHelper
fe(this);
175 if ( fe
.SetEncoding(encoding
) )
177 fe
.SetFixedOnly(fixedWidthOnly
);
181 // else: no such fonts, unknown encoding
186 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
188 wxFAIL_MSG(wxT("TODO"));
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
199 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
200 DWORD dwStyle, LONG lParam)
202 // Get rid of any fonts that we don't want...
203 if ( dwStyle != TRUETYPE_FONTTYPE )
205 // continue enumeration
209 wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam;
211 return fontEnum->OnFont(lplf, lptm);