1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/fontutil.cpp
3 // Purpose: font-related helper functions for wxMSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontutil.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
37 #include "wx/msw/private.h"
39 #include "wx/fontutil.h"
40 #include "wx/fontmap.h"
42 #include "wx/tokenzr.h"
44 // for MSVC5 and old w32api
45 #ifndef HANGUL_CHARSET
46 # define HANGUL_CHARSET 129
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
54 // wxNativeEncodingInfo
55 // ----------------------------------------------------------------------------
57 // convert to/from the string representation: format is
58 // encodingid;facename[;charset]
60 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
62 wxStringTokenizer
tokenizer(s
, _T(";"));
64 wxString encid
= tokenizer
.GetNextToken();
66 if ( !encid
.ToLong(&enc
) )
68 encoding
= (wxFontEncoding
)enc
;
70 facename
= tokenizer
.GetNextToken();
72 wxString tmp
= tokenizer
.GetNextToken();
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
78 charset
= ANSI_CHARSET
;
82 if ( wxSscanf(tmp
, _T("%u"), &charset
) != 1 )
84 // should be a number!
92 wxString
wxNativeEncodingInfo::ToString() const
96 s
<< (long)encoding
<< _T(';') << facename
;
98 // ANSI_CHARSET is assumed anyhow
99 if ( charset
!= ANSI_CHARSET
)
101 s
<< _T(';') << charset
;
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
112 wxNativeEncodingInfo
*info
)
114 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
116 if ( encoding
== wxFONTENCODING_DEFAULT
)
118 encoding
= wxFont::GetDefaultEncoding();
121 extern long wxEncodingToCharset(wxFontEncoding encoding
);
122 info
->charset
= wxEncodingToCharset(encoding
);
123 if ( info
->charset
== -1 )
126 info
->encoding
= encoding
;
131 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
133 // try to create such font
135 wxZeroMemory(lf
); // all default values
137 lf
.lfCharSet
= info
.charset
;
138 wxStrncpy(lf
.lfFaceName
, info
.facename
, WXSIZEOF(lf
.lfFaceName
));
140 HFONT hfont
= ::CreateFontIndirect(&lf
);
147 ::DeleteObject((HGDIOBJ
)hfont
);
152 // ----------------------------------------------------------------------------
153 // wxFontEncoding <-> CHARSET_XXX
154 // ----------------------------------------------------------------------------
156 wxFontEncoding
wxGetFontEncFromCharSet(int cs
)
158 wxFontEncoding fontEncoding
;
163 // assume the system charset
164 fontEncoding
= wxFONTENCODING_SYSTEM
;
168 fontEncoding
= wxFONTENCODING_CP1252
;
171 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
172 case EASTEUROPE_CHARSET
:
173 fontEncoding
= wxFONTENCODING_CP1250
;
177 fontEncoding
= wxFONTENCODING_CP1257
;
180 case RUSSIAN_CHARSET
:
181 fontEncoding
= wxFONTENCODING_CP1251
;
185 fontEncoding
= wxFONTENCODING_CP1256
;
189 fontEncoding
= wxFONTENCODING_CP1253
;
193 fontEncoding
= wxFONTENCODING_CP1255
;
196 case TURKISH_CHARSET
:
197 fontEncoding
= wxFONTENCODING_CP1254
;
201 fontEncoding
= wxFONTENCODING_CP437
;
204 case SHIFTJIS_CHARSET
:
205 fontEncoding
= wxFONTENCODING_CP932
;
209 fontEncoding
= wxFONTENCODING_CP936
;
213 fontEncoding
= wxFONTENCODING_CP949
;
216 case CHINESEBIG5_CHARSET
:
217 fontEncoding
= wxFONTENCODING_CP950
;
223 fontEncoding
= wxFONTENCODING_CP437
;
230 // ----------------------------------------------------------------------------
231 // wxFont <-> LOGFONT conversion
232 // ----------------------------------------------------------------------------
234 void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
)
236 // maybe we already have LOGFONT for this font?
237 wxNativeFontInfo
*fontinfo
= font
->GetNativeFontInfo();
240 // use wxNativeFontInfo methods to build a LOGFONT for this font
241 fontinfo
= new wxNativeFontInfo
;
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());
249 // set the family/facename
250 fontinfo
->SetFamily((wxFontFamily
)font
->GetFamily());
251 wxString facename
= font
->GetFaceName();
252 if ( !facename
.empty() )
254 fontinfo
->SetFaceName(facename
);
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());
262 // transfer all the data to LOGFONT
263 *logFont
= fontinfo
->lf
;
268 wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
)
270 wxNativeFontInfo info
;