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 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "fontutil.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
35 #include "wx/encinfo.h"
38 #include "wx/msw/private.h"
40 #include "wx/fontutil.h"
41 #include "wx/fontmap.h"
43 #include "wx/tokenzr.h"
45 // for MSVC5 and old w32api
46 #ifndef HANGUL_CHARSET
47 # define HANGUL_CHARSET 129
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
55 // wxNativeEncodingInfo
56 // ----------------------------------------------------------------------------
58 // convert to/from the string representation: format is
59 // encodingid;facename[;charset]
61 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
63 wxStringTokenizer
tokenizer(s
, _T(";"));
65 wxString encid
= tokenizer
.GetNextToken();
67 if ( !encid
.ToLong(&enc
) )
69 encoding
= (wxFontEncoding
)enc
;
71 facename
= tokenizer
.GetNextToken();
73 wxString tmp
= tokenizer
.GetNextToken();
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
79 charset
= ANSI_CHARSET
;
83 if ( wxSscanf(tmp
, _T("%u"), &charset
) != 1 )
85 // should be a number!
93 wxString
wxNativeEncodingInfo::ToString() const
97 s
<< (long)encoding
<< _T(';') << facename
;
99 // ANSI_CHARSET is assumed anyhow
100 if ( charset
!= ANSI_CHARSET
)
102 s
<< _T(';') << charset
;
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
113 wxNativeEncodingInfo
*info
)
115 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
117 if ( encoding
== wxFONTENCODING_DEFAULT
)
119 encoding
= wxFont::GetDefaultEncoding();
122 extern WXDLLIMPEXP_BASE
long wxEncodingToCharset(wxFontEncoding encoding
);
123 info
->charset
= wxEncodingToCharset(encoding
);
124 if ( info
->charset
== -1 )
127 info
->encoding
= encoding
;
132 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
134 // try to create such font
136 wxZeroMemory(lf
); // all default values
138 lf
.lfCharSet
= info
.charset
;
139 wxStrncpy(lf
.lfFaceName
, info
.facename
, WXSIZEOF(lf
.lfFaceName
));
141 HFONT hfont
= ::CreateFontIndirect(&lf
);
148 ::DeleteObject((HGDIOBJ
)hfont
);
153 // ----------------------------------------------------------------------------
154 // wxFontEncoding <-> CHARSET_XXX
155 // ----------------------------------------------------------------------------
157 wxFontEncoding
wxGetFontEncFromCharSet(int cs
)
159 wxFontEncoding fontEncoding
;
164 // assume the system charset
165 fontEncoding
= wxFONTENCODING_SYSTEM
;
169 fontEncoding
= wxFONTENCODING_CP1252
;
172 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
173 case EASTEUROPE_CHARSET
:
174 fontEncoding
= wxFONTENCODING_CP1250
;
178 fontEncoding
= wxFONTENCODING_CP1257
;
181 case RUSSIAN_CHARSET
:
182 fontEncoding
= wxFONTENCODING_CP1251
;
186 fontEncoding
= wxFONTENCODING_CP1256
;
190 fontEncoding
= wxFONTENCODING_CP1253
;
194 fontEncoding
= wxFONTENCODING_CP1255
;
197 case TURKISH_CHARSET
:
198 fontEncoding
= wxFONTENCODING_CP1254
;
202 fontEncoding
= wxFONTENCODING_CP437
;
205 case SHIFTJIS_CHARSET
:
206 fontEncoding
= wxFONTENCODING_CP932
;
210 fontEncoding
= wxFONTENCODING_CP936
;
214 fontEncoding
= wxFONTENCODING_CP949
;
217 case CHINESEBIG5_CHARSET
:
218 fontEncoding
= wxFONTENCODING_CP950
;
224 fontEncoding
= wxFONTENCODING_CP437
;
231 // ----------------------------------------------------------------------------
232 // wxFont <-> LOGFONT conversion
233 // ----------------------------------------------------------------------------
235 void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
)
237 // maybe we already have LOGFONT for this font?
238 wxNativeFontInfo
*fontinfo
= font
->GetNativeFontInfo();
241 // use wxNativeFontInfo methods to build a LOGFONT for this font
242 fontinfo
= new wxNativeFontInfo
;
244 // translate all font parameters
245 fontinfo
->SetStyle((wxFontStyle
)font
->GetStyle());
246 fontinfo
->SetWeight((wxFontWeight
)font
->GetWeight());
247 fontinfo
->SetUnderlined(font
->GetUnderlined());
248 fontinfo
->SetPointSize(font
->GetPointSize());
250 // set the family/facename
251 fontinfo
->SetFamily((wxFontFamily
)font
->GetFamily());
252 wxString facename
= font
->GetFaceName();
253 if ( !facename
.empty() )
255 fontinfo
->SetFaceName(facename
);
258 // deal with encoding now (it may override the font family and facename
259 // so do it after setting them)
260 fontinfo
->SetEncoding(font
->GetEncoding());
263 // transfer all the data to LOGFONT
264 *logFont
= fontinfo
->lf
;
269 wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
)
271 wxNativeFontInfo info
;