1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/fontenum.cpp
3 // Purpose: wxFontEnumerator class for Windows
4 // Author: Julian Smart
5 // Modified by: David Webster to add support for font encodings
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
24 #include "wx/fontenum.h"
30 #include "wx/fontmap.h"
31 #include "wx/encinfo.h"
33 #include "wx/os2/private.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 class wxFontEnumeratorHelper
42 wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
);
44 // control what exactly are we enumerating
45 bool SetEncoding(wxFontEncoding encoding
);
46 void SetFixedOnly(bool fixedOnly
)
47 { m_fixedOnly
= fixedOnly
; }
49 // call to start enumeration
52 // called by our font enumeration proc
53 bool OnFont(/*const LPLOGFONT lf, const LPTEXTMETRIC tm*/) const;
56 // the object we forward calls to OnFont() to
57 wxFontEnumerator
*m_fontEnum
;
59 // if != -1, enum only fonts which have this encoding
62 // if not empty, enum only the fonts with this facename
65 // if true, enum only fixed fonts
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
75 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
76 DWORD dwStyle, LONG lParam);
79 // ============================================================================
81 // ============================================================================
83 // ----------------------------------------------------------------------------
84 // wxFontEnumeratorHelper
85 // ----------------------------------------------------------------------------
87 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator
*fontEnum
)
89 m_fontEnum
= fontEnum
;
94 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding
)
96 wxNativeEncodingInfo info
;
97 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
99 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
101 // no such encodings at all
105 m_charset
= info
.charset
;
106 m_facename
= info
.facename
;
111 #define wxFONTENUMPROC FONTENUMPROC
113 void wxFontEnumeratorHelper::DoEnumerate()
117 HDC hDC = ::GetDC(NULL);
121 lf.lfCharSet = m_charset;
122 wxStrlcpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName));
123 lf.lfPitchAndFamily = 0;
124 ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc,
127 ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc,
136 ::ReleaseDC(NULL, hDC);
140 bool wxFontEnumeratorHelper::OnFont(/*const LPLOGFONT lf,
141 const LPTEXTMETRIC tm */) const
147 // check that it's a fixed pitch font (there is *no* error here, the
148 // flag name is misleading!)
149 if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
151 // not a fixed pitch font
156 if ( m_charset != -1 )
158 // check that we have the right encoding
159 if ( lf->lfCharSet != m_charset )
165 return m_fontEnum->OnFacename(lf->lfFaceName);
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding
,
177 wxFontEnumeratorHelper
fe(this);
178 if ( fe
.SetEncoding(encoding
) )
180 fe
.SetFixedOnly(fixedWidthOnly
);
184 // else: no such fonts, unknown encoding
189 bool wxFontEnumerator::EnumerateEncodings(const wxString
& WXUNUSED(family
))
191 wxFAIL_MSG(wxT("TODO"));
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
202 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
203 DWORD dwStyle, LONG lParam)
205 // Get rid of any fonts that we don't want...
206 if ( dwStyle != TRUETYPE_FONTTYPE )
208 // continue enumeration
212 wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam;
214 return fontEnum->OnFont(lplf, lptm);
218 #endif // wxUSE_FONTMAP