]> git.saurik.com Git - wxWidgets.git/blame - src/msw/fontutil.cpp
showing a bevel button for a multiline label (is not multline on the OS level, but...
[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"
e4ffab29 35 #include "wx/encinfo.h"
11c7d5b6
VZ
36#endif //WX_PRECOMP
37
38#include "wx/msw/private.h"
39
40#include "wx/fontutil.h"
41#include "wx/fontmap.h"
42
43#include "wx/tokenzr.h"
44
e757496e
MB
45// for MSVC5 and old w32api
46#ifndef HANGUL_CHARSET
47# define HANGUL_CHARSET 129
48#endif
49
11c7d5b6
VZ
50// ============================================================================
51// implementation
52// ============================================================================
53
54// ----------------------------------------------------------------------------
55// wxNativeEncodingInfo
56// ----------------------------------------------------------------------------
57
58// convert to/from the string representation: format is
1e1d0be1 59// encodingid;facename[;charset]
11c7d5b6
VZ
60
61bool wxNativeEncodingInfo::FromString(const wxString& s)
62{
63 wxStringTokenizer tokenizer(s, _T(";"));
64
1e1d0be1
VS
65 wxString encid = tokenizer.GetNextToken();
66 long enc;
67 if ( !encid.ToLong(&enc) )
68 return FALSE;
69 encoding = (wxFontEncoding)enc;
70
11c7d5b6 71 facename = tokenizer.GetNextToken();
11c7d5b6
VZ
72
73 wxString tmp = tokenizer.GetNextToken();
4ec6efd6 74 if ( tmp.empty() )
11c7d5b6 75 {
4ec6efd6
VZ
76 // default charset: but don't use DEFAULT_CHARSET here because it might
77 // be different from the machine on which the file we had read this
78 // encoding desc from was created
11c7d5b6
VZ
79 charset = ANSI_CHARSET;
80 }
81 else
82 {
83 if ( wxSscanf(tmp, _T("%u"), &charset) != 1 )
84 {
85 // should be a number!
86 return FALSE;
87 }
88 }
89
90 return TRUE;
91}
92
93wxString wxNativeEncodingInfo::ToString() const
94{
1e1d0be1 95 wxString s;
f6bcfd97 96
1e1d0be1 97 s << (long)encoding << _T(';') << facename;
4ec6efd6
VZ
98
99 // ANSI_CHARSET is assumed anyhow
11c7d5b6
VZ
100 if ( charset != ANSI_CHARSET )
101 {
1e1d0be1 102 s << _T(';') << charset;
11c7d5b6
VZ
103 }
104
105 return s;
106}
107
108// ----------------------------------------------------------------------------
109// helper functions
110// ----------------------------------------------------------------------------
111
112bool wxGetNativeFontEncoding(wxFontEncoding encoding,
113 wxNativeEncodingInfo *info)
114{
115 wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
116
117 if ( encoding == wxFONTENCODING_DEFAULT )
118 {
119 encoding = wxFont::GetDefaultEncoding();
120 }
121
bddd7a8d 122 extern WXDLLIMPEXP_BASE long wxEncodingToCharset(wxFontEncoding encoding);
e2478fde
VZ
123 info->charset = wxEncodingToCharset(encoding);
124 if ( info->charset == -1 )
125 return FALSE;
11c7d5b6 126
6b0eebc5 127 info->encoding = encoding;
f6bcfd97 128
11c7d5b6
VZ
129 return TRUE;
130}
131
132bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
133{
134 // try to create such font
135 LOGFONT lf;
136 wxZeroMemory(lf); // all default values
137
138 lf.lfCharSet = info.charset;
98a52819 139 wxStrncpy(lf.lfFaceName, info.facename, WXSIZEOF(lf.lfFaceName));
11c7d5b6
VZ
140
141 HFONT hfont = ::CreateFontIndirect(&lf);
142 if ( !hfont )
143 {
144 // no such font
145 return FALSE;
146 }
147
148 ::DeleteObject((HGDIOBJ)hfont);
149
150 return TRUE;
151}
152
f6bcfd97
BP
153// ----------------------------------------------------------------------------
154// wxFontEncoding <-> CHARSET_XXX
155// ----------------------------------------------------------------------------
156
157wxFontEncoding wxGetFontEncFromCharSet(int cs)
158{
159 wxFontEncoding fontEncoding;
160
161 switch ( cs )
162 {
163 default:
4ec6efd6
VZ
164 // assume the system charset
165 fontEncoding = wxFONTENCODING_SYSTEM;
166 break;
f6bcfd97
BP
167
168 case ANSI_CHARSET:
169 fontEncoding = wxFONTENCODING_CP1252;
170 break;
171
04ef50df 172#if defined(__WIN32__) && !defined(__WXMICROWIN__)
f6bcfd97
BP
173 case EASTEUROPE_CHARSET:
174 fontEncoding = wxFONTENCODING_CP1250;
175 break;
176
177 case BALTIC_CHARSET:
178 fontEncoding = wxFONTENCODING_CP1257;
179 break;
180
181 case RUSSIAN_CHARSET:
182 fontEncoding = wxFONTENCODING_CP1251;
183 break;
184
185 case ARABIC_CHARSET:
186 fontEncoding = wxFONTENCODING_CP1256;
187 break;
188
189 case GREEK_CHARSET:
190 fontEncoding = wxFONTENCODING_CP1253;
191 break;
192
193 case HEBREW_CHARSET:
194 fontEncoding = wxFONTENCODING_CP1255;
195 break;
196
197 case TURKISH_CHARSET:
198 fontEncoding = wxFONTENCODING_CP1254;
199 break;
200
201 case THAI_CHARSET:
202 fontEncoding = wxFONTENCODING_CP437;
203 break;
bc4e6fcd
VZ
204
205 case SHIFTJIS_CHARSET:
206 fontEncoding = wxFONTENCODING_CP932;
207 break;
208
209 case GB2312_CHARSET:
210 fontEncoding = wxFONTENCODING_CP936;
211 break;
212
213 case HANGUL_CHARSET:
214 fontEncoding = wxFONTENCODING_CP949;
215 break;
216
217 case CHINESEBIG5_CHARSET:
218 fontEncoding = wxFONTENCODING_CP950;
219 break;
220
f6bcfd97
BP
221#endif // Win32
222
223 case OEM_CHARSET:
224 fontEncoding = wxFONTENCODING_CP437;
225 break;
226 }
227
228 return fontEncoding;
229}
230
11c7d5b6
VZ
231// ----------------------------------------------------------------------------
232// wxFont <-> LOGFONT conversion
233// ----------------------------------------------------------------------------
234
235void wxFillLogFont(LOGFONT *logFont, const wxFont *font)
236{
3bf5a59b
VZ
237 wxNativeFontInfo fi;
238
7936354d 239 // maybe we already have LOGFONT for this font?
3bf5a59b
VZ
240 const wxNativeFontInfo *pFI = font->GetNativeFontInfo();
241 if ( !pFI )
11c7d5b6 242 {
7936354d 243 // use wxNativeFontInfo methods to build a LOGFONT for this font
3bf5a59b 244 fi.InitFromFont(*font);
11c7d5b6 245
3bf5a59b 246 pFI = &fi;
11c7d5b6
VZ
247 }
248
249 // transfer all the data to LOGFONT
3bf5a59b 250 *logFont = pFI->lf;
11c7d5b6
VZ
251}
252
253wxFont wxCreateFontFromLogFont(const LOGFONT *logFont)
254{
09fcd889 255 wxNativeFontInfo info;
11c7d5b6 256
09fcd889 257 info.lf = *logFont;
11c7d5b6 258
09fcd889 259 return wxFont(info);
11c7d5b6
VZ
260}
261