]> git.saurik.com Git - wxWidgets.git/blob - src/msw/fontenum.cpp
Added def files for making OpenGL DLLs (Mingw32); added comment to wxHTML format
[wxWidgets.git] / src / msw / fontenum.cpp
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
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "fontenum.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/font.h"
33 #endif
34
35 #include "wx/fontenum.h"
36 #include "wx/fontmap.h"
37
38 #include "wx/msw/private.h"
39
40 // ----------------------------------------------------------------------------
41 // private classes
42 // ----------------------------------------------------------------------------
43
44 class wxFontEnumeratorHelper
45 {
46 public:
47 wxFontEnumeratorHelper(wxFontEnumerator *fontEnum);
48
49 // control what exactly are we enumerating
50 bool SetEncoding(wxFontEncoding encoding);
51 void SetFixedOnly(bool fixedOnly)
52 { m_fixedOnly = fixedOnly; }
53
54 // call to start enumeration
55 void DoEnumerate();
56
57 // called by our font enumeration proc
58 bool OnFont(const LPLOGFONT lf, const LPTEXTMETRIC tm) const;
59
60 private:
61 // the object we forward calls to OnFont() to
62 wxFontEnumerator *m_fontEnum;
63
64 // if != -1, enum only fonts which have this encoding
65 int m_charset;
66
67 // if not empty, enum only the fonts with this facename
68 wxString m_facename;
69
70 // if TRUE, enum only fixed fonts
71 bool m_fixedOnly;
72 };
73
74 // ----------------------------------------------------------------------------
75 // private functions
76 // ----------------------------------------------------------------------------
77
78 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
79 DWORD dwStyle, LONG lParam);
80
81 // ============================================================================
82 // implementation
83 // ============================================================================
84
85 // ----------------------------------------------------------------------------
86 // wxFontEnumeratorHelper
87 // ----------------------------------------------------------------------------
88
89 wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
90 {
91 m_fontEnum = fontEnum;
92 m_charset = -1;
93 m_fixedOnly = FALSE;
94 }
95
96 bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
97 {
98 wxNativeEncodingInfo info;
99 if ( !wxGetNativeFontEncoding(encoding, &info) )
100 {
101 if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
102 {
103 // no such encodings at all
104 return FALSE;
105 }
106 }
107 m_charset = info.charset;
108 m_facename = info.facename;
109
110 return TRUE;
111 }
112
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)
116 #else
117 #define wxFONTENUMPROC int(*)(ENUMLOGFONTEX *, NEWTEXTMETRICEX*, int, LPARAM)
118 #endif
119 #else
120 #define wxFONTENUMPROC FONTENUMPROC
121 #endif
122
123 void wxFontEnumeratorHelper::DoEnumerate()
124 {
125 HDC hDC = ::GetDC(NULL);
126
127 #ifdef __WIN32__
128 LOGFONT lf;
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 */) ;
134 #else // Win16
135 ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc,
136 #ifdef STRICT
137 (LPARAM)
138 #else
139 (LPSTR)
140 #endif
141 this);
142 #endif // Win32/16
143
144 ::ReleaseDC(NULL, hDC);
145 }
146
147 bool wxFontEnumeratorHelper::OnFont(const LPLOGFONT lf,
148 const LPTEXTMETRIC tm) const
149 {
150 if ( m_fixedOnly )
151 {
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 )
155 {
156 // not a fixed pitch font
157 return TRUE;
158 }
159 }
160
161 if ( m_charset != -1 )
162 {
163 // check that we have the right encoding
164 if ( lf->lfCharSet != m_charset )
165 {
166 return TRUE;
167 }
168 }
169
170 return m_fontEnum->OnFacename(lf->lfFaceName);
171 }
172
173 // ----------------------------------------------------------------------------
174 // wxFontEnumerator
175 // ----------------------------------------------------------------------------
176
177 bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
178 bool fixedWidthOnly)
179 {
180 wxFontEnumeratorHelper fe(this);
181 if ( fe.SetEncoding(encoding) )
182 {
183 fe.SetFixedOnly(fixedWidthOnly);
184
185 fe.DoEnumerate();
186 }
187 // else: no such fonts, unknown encoding
188
189 return TRUE;
190 }
191
192 bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
193 {
194 wxFAIL_MSG(wxT("TODO"));
195
196 return TRUE;
197 }
198
199 // ----------------------------------------------------------------------------
200 // Windows callbacks
201 // ----------------------------------------------------------------------------
202
203 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
204 DWORD dwStyle, LONG lParam)
205 {
206 // Get rid of any fonts that we don't want...
207 if ( dwStyle != TRUETYPE_FONTTYPE )
208 {
209 // continue enumeration
210 return TRUE;
211 }
212
213 wxFontEnumeratorHelper *fontEnum = (wxFontEnumeratorHelper *)lParam;
214
215 return fontEnum->OnFont(lplf, lptm);
216 }
217