]>
Commit | Line | Data |
---|---|---|
d8cde57b | 1 | /////////////////////////////////////////////////////////////////////////////// |
48a1108e | 2 | // Name: src/os2/fontenum.cpp |
d8cde57b DW |
3 | // Purpose: wxFontEnumerator class for Windows |
4 | // Author: Julian Smart | |
5 | // Modified by: David Webster to add support for font encodings | |
6 | // Created: 01/03/00 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
65571936 | 9 | // Licence: wxWindows licence |
d8cde57b DW |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
19193a2c KB |
23 | #if wxUSE_FONTMAP |
24 | ||
48a1108e WS |
25 | #include "wx/fontenum.h" |
26 | ||
d8cde57b | 27 | #ifndef WX_PRECOMP |
48a1108e | 28 | #include "wx/font.h" |
d8cde57b DW |
29 | #endif |
30 | ||
d8cde57b | 31 | #include "wx/fontmap.h" |
bd6685b3 | 32 | #include "wx/encinfo.h" |
d8cde57b DW |
33 | |
34 | #include "wx/os2/private.h" | |
35 | ||
36 | // ---------------------------------------------------------------------------- | |
37 | // private classes | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | class wxFontEnumeratorHelper | |
41 | { | |
42 | public: | |
43 | wxFontEnumeratorHelper(wxFontEnumerator *fontEnum); | |
44 | ||
45 | // control what exactly are we enumerating | |
46 | bool SetEncoding(wxFontEncoding encoding); | |
47 | void SetFixedOnly(bool fixedOnly) | |
48 | { m_fixedOnly = fixedOnly; } | |
49 | ||
50 | // call to start enumeration | |
51 | void DoEnumerate(); | |
52 | ||
53 | // called by our font enumeration proc | |
54 | bool OnFont(/*const LPLOGFONT lf, const LPTEXTMETRIC tm*/) const; | |
55 | ||
56 | private: | |
57 | // the object we forward calls to OnFont() to | |
58 | wxFontEnumerator *m_fontEnum; | |
59 | ||
60 | // if != -1, enum only fonts which have this encoding | |
61 | int m_charset; | |
62 | ||
63 | // if not empty, enum only the fonts with this facename | |
64 | wxString m_facename; | |
65 | ||
6670f564 | 66 | // if true, enum only fixed fonts |
d8cde57b DW |
67 | bool m_fixedOnly; |
68 | }; | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // private functions | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | // TODO: | |
75 | /* | |
76 | int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm, | |
77 | DWORD dwStyle, LONG lParam); | |
78 | */ | |
79 | ||
80 | // ============================================================================ | |
81 | // implementation | |
82 | // ============================================================================ | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // wxFontEnumeratorHelper | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum) | |
89 | { | |
90 | m_fontEnum = fontEnum; | |
91 | m_charset = -1; | |
92 | m_fixedOnly = FALSE; | |
93 | } | |
94 | ||
95 | bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding) | |
96 | { | |
97 | wxNativeEncodingInfo info; | |
98 | if ( !wxGetNativeFontEncoding(encoding, &info) ) | |
99 | { | |
142b3bc2 | 100 | if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) ) |
d8cde57b DW |
101 | { |
102 | // no such encodings at all | |
103 | return FALSE; | |
104 | } | |
105 | } | |
106 | m_charset = info.charset; | |
107 | m_facename = info.facename; | |
108 | ||
6670f564 | 109 | return true; |
d8cde57b DW |
110 | } |
111 | ||
112 | #define wxFONTENUMPROC FONTENUMPROC | |
113 | ||
114 | void wxFontEnumeratorHelper::DoEnumerate() | |
115 | { | |
116 | // TODO: | |
117 | /* | |
118 | HDC hDC = ::GetDC(NULL); | |
119 | ||
120 | #ifdef __WIN32__ | |
121 | LOGFONT lf; | |
122 | lf.lfCharSet = m_charset; | |
e408bf52 | 123 | wxStrlcpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName)); |
d8cde57b DW |
124 | lf.lfPitchAndFamily = 0; |
125 | ::EnumFontFamiliesEx(hDC, &lf, (wxFONTENUMPROC)wxFontEnumeratorProc, | |
126 | (LPARAM)this, 0) ; | |
127 | #else // Win16 | |
128 | ::EnumFonts(hDC, (LPTSTR)NULL, (FONTENUMPROC)wxFontEnumeratorProc, | |
129 | #ifdef STRICT | |
130 | (LPARAM) | |
131 | #else | |
132 | (LPSTR) | |
133 | #endif | |
134 | this); | |
135 | #endif // Win32/16 | |
136 | ||
137 | ::ReleaseDC(NULL, hDC); | |
138 | */ | |
139 | } | |
140 | ||
141 | bool wxFontEnumeratorHelper::OnFont(/*const LPLOGFONT lf, | |
142 | const LPTEXTMETRIC tm */) const | |
143 | { | |
144 | // TODO: | |
145 | /* | |
146 | if ( m_fixedOnly ) | |
147 | { | |
148 | // check that it's a fixed pitch font (there is *no* error here, the | |
149 | // flag name is misleading!) | |
150 | if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) | |
151 | { | |
152 | // not a fixed pitch font | |
6670f564 | 153 | return true; |
d8cde57b DW |
154 | } |
155 | } | |
156 | ||
157 | if ( m_charset != -1 ) | |
158 | { | |
159 | // check that we have the right encoding | |
160 | if ( lf->lfCharSet != m_charset ) | |
161 | { | |
6670f564 | 162 | return true; |
d8cde57b DW |
163 | } |
164 | } | |
165 | ||
166 | return m_fontEnum->OnFacename(lf->lfFaceName); | |
167 | */ | |
6670f564 | 168 | return true; |
d8cde57b DW |
169 | } |
170 | ||
171 | // ---------------------------------------------------------------------------- | |
172 | // wxFontEnumerator | |
173 | // ---------------------------------------------------------------------------- | |
174 | ||
175 | bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, | |
176 | bool fixedWidthOnly) | |
177 | { | |
178 | wxFontEnumeratorHelper fe(this); | |
179 | if ( fe.SetEncoding(encoding) ) | |
180 | { | |
181 | fe.SetFixedOnly(fixedWidthOnly); | |
182 | ||
183 | fe.DoEnumerate(); | |
184 | } | |
185 | // else: no such fonts, unknown encoding | |
186 | ||
6670f564 | 187 | return true; |
d8cde57b DW |
188 | } |
189 | ||
6670f564 | 190 | bool wxFontEnumerator::EnumerateEncodings(const wxString& WXUNUSED(family)) |
d8cde57b DW |
191 | { |
192 | wxFAIL_MSG(wxT("TODO")); | |
193 | ||
6670f564 | 194 | return true; |
d8cde57b DW |
195 | } |
196 | ||
197 | // ---------------------------------------------------------------------------- | |
198 | // Windows callbacks | |
199 | // ---------------------------------------------------------------------------- | |
200 | ||
201 | // TODO: | |
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 | */ | |
218 | ||
19193a2c | 219 | #endif // wxUSE_FONTMAP |