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 // ----------------------------------------------------------------------------
21 #pragma implementation "fontenum.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/fontenum.h"
34 #include "wx/fontmap.h"
36 #include "wx/os2/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 class wxFontEnumeratorHelper
45 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
47 // control what exactly are we enumerating
48 bool SetEncoding(wxFontEncoding encoding
);
49 void SetFixedOnly(bool fixedOnly
)
50 { m_fixedOnly
= fixedOnly
; }
52 // call to start enumeration
55 // called by our font enumeration proc
56 bool OnFont(/*const LPLOGFONT lf, const LPTEXTMETRIC tm*/) const;
59 // the object we forward calls to OnFont() to
60 wxFontEnumerator
*m_fontEnum
;
62 // if != -1, enum only fonts which have this encoding
65 // if not empty, enum only the fonts with this facename
68 // if TRUE, enum only fixed fonts
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
78 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
79 DWORD dwStyle, LONG lParam);
82 // ============================================================================
84 // ============================================================================
86 // ----------------------------------------------------------------------------
87 // wxFontEnumeratorHelper
88 // ----------------------------------------------------------------------------
90 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
92 m_fontEnum
= fontEnum
;
97 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
99 wxNativeEncodingInfo info
;
100 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
102 if ( !wxTheFontMapper
->GetAltForEncoding(encoding
, &info
) )
104 // no such encodings at all
108 m_charset
= info
.charset
;
109 m_facename
= info
.facename
;
114 #define wxFONTENUMPROC FONTENUMPROC
116 void wxFontEnumeratorHelper::DoEnumerate()
120 HDC hDC = ::GetDC(NULL);
124 lf.lfCharSet = m_charset;
125 wxStrncpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName));
126 lf.lfPitchAndFamily = 0;
127 ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc,
130 ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc,
139 ::ReleaseDC(NULL, hDC);
143 bool wxFontEnumeratorHelper::OnFont(/*const LPLOGFONT lf,
144 const LPTEXTMETRIC tm */) const
150 // check that it's a fixed pitch font (there is *no* error here, the
151 // flag name is misleading!)
152 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
154 // not a fixed pitch font
159 if ( m_charset != -1 )
161 // check that we have the right encoding
162 if ( lf->lfCharSet != m_charset )
168 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 // ----------------------------------------------------------------------------
205 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
206 DWORD dwStyle, LONG lParam)
208 // Get rid of any fonts that we don't want...
209 if ( dwStyle != TRUETYPE_FONTTYPE )
211 // continue enumeration
215 wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam;
217 return fontEnum->OnFont(lplf, lptm);
221 #endif // wxUSE_FONTMAP