]> git.saurik.com Git - wxWidgets.git/blame - src/msw/fontutil.cpp
Do archive name case conversion for wxMac and wxMotif
[wxWidgets.git] / src / msw / fontutil.cpp
CommitLineData
11c7d5b6
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/fontutil.cpp
3// Purpose: font-related helper functions for wxMSW
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 05.11.99
7// RCS-ID: $Id$
8// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
6c9a19aa 9// Licence: wxWindows licence
11c7d5b6
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11c7d5b6
VZ
21 #pragma implementation "fontutil.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/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35#endif //WX_PRECOMP
36
37#include "wx/msw/private.h"
38
39#include "wx/fontutil.h"
40#include "wx/fontmap.h"
41
42#include "wx/tokenzr.h"
43
e757496e
MB
44// for MSVC5 and old w32api
45#ifndef HANGUL_CHARSET
46# define HANGUL_CHARSET 129
47#endif
48
11c7d5b6
VZ
49// ============================================================================
50// implementation
51// ============================================================================
52
53// ----------------------------------------------------------------------------
54// wxNativeEncodingInfo
55// ----------------------------------------------------------------------------
56
57// convert to/from the string representation: format is
1e1d0be1 58// encodingid;facename[;charset]
11c7d5b6
VZ
59
60bool wxNativeEncodingInfo::FromString(const wxString& s)
61{
62 wxStringTokenizer tokenizer(s, _T(";"));
63
1e1d0be1
VS
64 wxString encid = tokenizer.GetNextToken();
65 long enc;
66 if ( !encid.ToLong(&enc) )
67 return FALSE;
68 encoding = (wxFontEncoding)enc;
69
11c7d5b6 70 facename = tokenizer.GetNextToken();
11c7d5b6
VZ
71
72 wxString tmp = tokenizer.GetNextToken();
4ec6efd6 73 if ( tmp.empty() )
11c7d5b6 74 {
4ec6efd6
VZ
75 // default charset: but don't use DEFAULT_CHARSET here because it might
76 // be different from the machine on which the file we had read this
77 // encoding desc from was created
11c7d5b6
VZ
78 charset = ANSI_CHARSET;
79 }
80 else
81 {
82 if ( wxSscanf(tmp, _T("%u"), &charset) != 1 )
83 {
84 // should be a number!
85 return FALSE;
86 }
87 }
88
89 return TRUE;
90}
91
92wxString wxNativeEncodingInfo::ToString() const
93{
1e1d0be1 94 wxString s;
f6bcfd97 95
1e1d0be1 96 s << (long)encoding << _T(';') << facename;
4ec6efd6
VZ
97
98 // ANSI_CHARSET is assumed anyhow
11c7d5b6
VZ
99 if ( charset != ANSI_CHARSET )
100 {
1e1d0be1 101 s << _T(';') << charset;
11c7d5b6
VZ
102 }
103
104 return s;
105}
106
107// ----------------------------------------------------------------------------
108// helper functions
109// ----------------------------------------------------------------------------
110
111bool wxGetNativeFontEncoding(wxFontEncoding encoding,
112 wxNativeEncodingInfo *info)
113{
114 wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
115
116 if ( encoding == wxFONTENCODING_DEFAULT )
117 {
118 encoding = wxFont::GetDefaultEncoding();
119 }
120
bddd7a8d 121 extern WXDLLIMPEXP_BASE long wxEncodingToCharset(wxFontEncoding encoding);
e2478fde
VZ
122 info->charset = wxEncodingToCharset(encoding);
123 if ( info->charset == -1 )
124 return FALSE;
11c7d5b6 125
6b0eebc5 126 info->encoding = encoding;
f6bcfd97 127
11c7d5b6
VZ
128 return TRUE;
129}
130
131bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
132{
133 // try to create such font
134 LOGFONT lf;
135 wxZeroMemory(lf); // all default values
136
137 lf.lfCharSet = info.charset;
98a52819 138 wxStrncpy(lf.lfFaceName, info.facename, WXSIZEOF(lf.lfFaceName));
11c7d5b6
VZ
139
140 HFONT hfont = ::CreateFontIndirect(&lf);
141 if ( !hfont )
142 {
143 // no such font
144 return FALSE;
145 }
146
147 ::DeleteObject((HGDIOBJ)hfont);
148
149 return TRUE;
150}
151
f6bcfd97
BP
152// ----------------------------------------------------------------------------
153// wxFontEncoding <-> CHARSET_XXX
154// ----------------------------------------------------------------------------
155
156wxFontEncoding wxGetFontEncFromCharSet(int cs)
157{
158 wxFontEncoding fontEncoding;
159
160 switch ( cs )
161 {
162 default:
4ec6efd6
VZ
163 // assume the system charset
164 fontEncoding = wxFONTENCODING_SYSTEM;
165 break;
f6bcfd97
BP
166
167 case ANSI_CHARSET:
168 fontEncoding = wxFONTENCODING_CP1252;
169 break;
170
04ef50df 171#if defined(__WIN32__) && !defined(__WXMICROWIN__)
f6bcfd97
BP
172 case EASTEUROPE_CHARSET:
173 fontEncoding = wxFONTENCODING_CP1250;
174 break;
175
176 case BALTIC_CHARSET:
177 fontEncoding = wxFONTENCODING_CP1257;
178 break;
179
180 case RUSSIAN_CHARSET:
181 fontEncoding = wxFONTENCODING_CP1251;
182 break;
183
184 case ARABIC_CHARSET:
185 fontEncoding = wxFONTENCODING_CP1256;
186 break;
187
188 case GREEK_CHARSET:
189 fontEncoding = wxFONTENCODING_CP1253;
190 break;
191
192 case HEBREW_CHARSET:
193 fontEncoding = wxFONTENCODING_CP1255;
194 break;
195
196 case TURKISH_CHARSET:
197 fontEncoding = wxFONTENCODING_CP1254;
198 break;
199
200 case THAI_CHARSET:
201 fontEncoding = wxFONTENCODING_CP437;
202 break;
bc4e6fcd
VZ
203
204 case SHIFTJIS_CHARSET:
205 fontEncoding = wxFONTENCODING_CP932;
206 break;
207
208 case GB2312_CHARSET:
209 fontEncoding = wxFONTENCODING_CP936;
210 break;
211
212 case HANGUL_CHARSET:
213 fontEncoding = wxFONTENCODING_CP949;
214 break;
215
216 case CHINESEBIG5_CHARSET:
217 fontEncoding = wxFONTENCODING_CP950;
218 break;
219
f6bcfd97
BP
220#endif // Win32
221
222 case OEM_CHARSET:
223 fontEncoding = wxFONTENCODING_CP437;
224 break;
225 }
226
227 return fontEncoding;
228}
229
11c7d5b6
VZ
230// ----------------------------------------------------------------------------
231// wxFont <-> LOGFONT conversion
232// ----------------------------------------------------------------------------
233
234void wxFillLogFont(LOGFONT *logFont, const wxFont *font)
235{
7936354d
VZ
236 // maybe we already have LOGFONT for this font?
237 wxNativeFontInfo *fontinfo = font->GetNativeFontInfo();
238 if ( !fontinfo )
11c7d5b6 239 {
7936354d
VZ
240 // use wxNativeFontInfo methods to build a LOGFONT for this font
241 fontinfo = new wxNativeFontInfo;
242
243 // translate all font parameters
244 fontinfo->SetStyle((wxFontStyle)font->GetStyle());
245 fontinfo->SetWeight((wxFontWeight)font->GetWeight());
246 fontinfo->SetUnderlined(font->GetUnderlined());
247 fontinfo->SetPointSize(font->GetPointSize());
248
249 // set the family/facename
250 fontinfo->SetFamily((wxFontFamily)font->GetFamily());
251 wxString facename = font->GetFaceName();
252 if ( !facename.empty() )
11c7d5b6 253 {
7936354d 254 fontinfo->SetFaceName(facename);
11c7d5b6 255 }
11c7d5b6 256
7936354d
VZ
257 // deal with encoding now (it may override the font family and facename
258 // so do it after setting them)
259 fontinfo->SetEncoding(font->GetEncoding());
11c7d5b6
VZ
260 }
261
262 // transfer all the data to LOGFONT
7936354d
VZ
263 *logFont = fontinfo->lf;
264
265 delete fontinfo;
11c7d5b6
VZ
266}
267
268wxFont wxCreateFontFromLogFont(const LOGFONT *logFont)
269{
09fcd889 270 wxNativeFontInfo info;
11c7d5b6 271
09fcd889 272 info.lf = *logFont;
11c7d5b6 273
09fcd889 274 return wxFont(info);
11c7d5b6
VZ
275}
276