]>
Commit | Line | Data |
---|---|---|
8f7fa6f8 | 1 | ///////////////////////////////////////////////////////////////////////////// |
da80ae71 | 2 | // Name: src/common/fontcmn.cpp |
0c5d3e1c VZ |
3 | // Purpose: implementation of wxFontBase methods |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 20.09.99 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
0c5d3e1c VZ |
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 | ||
23 | #ifdef __BORLANDC__ | |
da80ae71 | 24 | #pragma hdrstop |
0c5d3e1c VZ |
25 | #endif |
26 | ||
da80ae71 WS |
27 | #include "wx/font.h" |
28 | ||
0c5d3e1c | 29 | #ifndef WX_PRECOMP |
452aa069 | 30 | #include "wx/dc.h" |
9342fdbe VZ |
31 | #include "wx/intl.h" |
32 | #include "wx/dcscreen.h" | |
8d3ba63b | 33 | #include "wx/log.h" |
dd05139a | 34 | #include "wx/gdicmn.h" |
0c5d3e1c VZ |
35 | #endif // WX_PRECOMP |
36 | ||
82ef81ed | 37 | #if defined(__WXMSW__) |
7bd236e6 WS |
38 | #include "wx/msw/private.h" // includes windows.h for LOGFONT |
39 | #include "wx/msw/winundef.h" | |
1c193821 JS |
40 | #endif |
41 | ||
76e23cdb | 42 | #include "wx/fontutil.h" // for wxNativeFontInfo |
ab5fe833 | 43 | #include "wx/fontmap.h" |
85ab460e | 44 | #include "wx/fontenum.h" |
76e23cdb | 45 | |
30764ab5 VZ |
46 | #include "wx/tokenzr.h" |
47 | ||
4b6a582b VZ |
48 | // debugger helper: this function can be called from a debugger to show what |
49 | // the date really is | |
50 | extern const char *wxDumpFont(const wxFont *font) | |
51 | { | |
52 | static char buf[256]; | |
53 | ||
54 | const wxFontWeight weight = font->GetWeight(); | |
55 | ||
56 | wxString s; | |
57 | s.Printf(wxS("%s-%s-%s-%d-%d"), | |
58 | font->GetFaceName(), | |
59 | weight == wxFONTWEIGHT_NORMAL | |
9a83f860 | 60 | ? wxT("normal") |
4b6a582b | 61 | : weight == wxFONTWEIGHT_BOLD |
9a83f860 VZ |
62 | ? wxT("bold") |
63 | : wxT("light"), | |
4b6a582b | 64 | font->GetStyle() == wxFONTSTYLE_NORMAL |
9a83f860 VZ |
65 | ? wxT("regular") |
66 | : wxT("italic"), | |
4b6a582b VZ |
67 | font->GetPointSize(), |
68 | font->GetEncoding()); | |
69 | ||
61f24aea | 70 | wxStrlcpy(buf, s.mb_str(), WXSIZEOF(buf)); |
4b6a582b VZ |
71 | return buf; |
72 | } | |
73 | ||
28953245 SC |
74 | // ---------------------------------------------------------------------------- |
75 | // XTI | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | wxBEGIN_ENUM( wxFontFamily ) | |
e765d7ee SC |
79 | wxENUM_MEMBER( wxFONTFAMILY_DEFAULT ) |
80 | wxENUM_MEMBER( wxFONTFAMILY_DECORATIVE ) | |
81 | wxENUM_MEMBER( wxFONTFAMILY_ROMAN ) | |
82 | wxENUM_MEMBER( wxFONTFAMILY_SCRIPT ) | |
83 | wxENUM_MEMBER( wxFONTFAMILY_SWISS ) | |
84 | wxENUM_MEMBER( wxFONTFAMILY_MODERN ) | |
85 | wxENUM_MEMBER( wxFONTFAMILY_TELETYPE ) | |
28953245 SC |
86 | wxEND_ENUM( wxFontFamily ) |
87 | ||
88 | wxBEGIN_ENUM( wxFontStyle ) | |
e765d7ee SC |
89 | wxENUM_MEMBER( wxFONTSTYLE_NORMAL ) |
90 | wxENUM_MEMBER( wxFONTSTYLE_ITALIC ) | |
91 | wxENUM_MEMBER( wxFONTSTYLE_SLANT ) | |
28953245 SC |
92 | wxEND_ENUM( wxFontStyle ) |
93 | ||
94 | wxBEGIN_ENUM( wxFontWeight ) | |
e765d7ee SC |
95 | wxENUM_MEMBER( wxFONTWEIGHT_NORMAL ) |
96 | wxENUM_MEMBER( wxFONTWEIGHT_LIGHT ) | |
97 | wxENUM_MEMBER( wxFONTWEIGHT_BOLD ) | |
28953245 SC |
98 | wxEND_ENUM( wxFontWeight ) |
99 | ||
100 | wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont, wxGDIObject, "wx/font.h") | |
101 | ||
e765d7ee SC |
102 | //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxFont>) |
103 | ||
28953245 SC |
104 | wxBEGIN_PROPERTIES_TABLE(wxFont) |
105 | wxPROPERTY( Size,int, SetPointSize, GetPointSize, 12, 0 /*flags*/, \ | |
106 | wxT("Helpstring"), wxT("group")) | |
e765d7ee | 107 | wxPROPERTY( Family, wxFontFamily , SetFamily, GetFamily, (wxFontFamily)wxDEFAULT, \ |
28953245 | 108 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) // wxFontFamily |
e765d7ee | 109 | wxPROPERTY( Style, wxFontStyle, SetStyle, GetStyle, (wxFontStyle)wxNORMAL, 0 /*flags*/, \ |
28953245 | 110 | wxT("Helpstring"), wxT("group")) // wxFontStyle |
e765d7ee | 111 | wxPROPERTY( Weight, wxFontWeight, SetWeight, GetWeight, (wxFontWeight)wxNORMAL, 0 /*flags*/, \ |
28953245 SC |
112 | wxT("Helpstring"), wxT("group")) // wxFontWeight |
113 | wxPROPERTY( Underlined, bool, SetUnderlined, GetUnderlined, false, 0 /*flags*/, \ | |
114 | wxT("Helpstring"), wxT("group")) | |
115 | wxPROPERTY( Face, wxString, SetFaceName, GetFaceName, wxEMPTY_PARAMETER_VALUE, \ | |
116 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
117 | wxPROPERTY( Encoding, wxFontEncoding, SetEncoding, GetEncoding, \ | |
118 | wxFONTENCODING_DEFAULT, 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
119 | wxEND_PROPERTIES_TABLE() | |
120 | ||
e765d7ee | 121 | wxCONSTRUCTOR_6( wxFont, int, Size, wxFontFamily, Family, wxFontStyle, Style, wxFontWeight, Weight, \ |
28953245 SC |
122 | bool, Underlined, wxString, Face ) |
123 | ||
124 | wxEMPTY_HANDLERS_TABLE(wxFont) | |
125 | ||
0c5d3e1c VZ |
126 | // ============================================================================ |
127 | // implementation | |
128 | // ============================================================================ | |
129 | ||
544229d1 VZ |
130 | // ---------------------------------------------------------------------------- |
131 | // helper functions | |
132 | // ---------------------------------------------------------------------------- | |
133 | ||
b5791cc7 | 134 | static inline int flags2Style(int flags) |
544229d1 | 135 | { |
b5791cc7 FM |
136 | return flags & wxFONTFLAG_ITALIC |
137 | ? wxFONTSTYLE_ITALIC | |
138 | : flags & wxFONTFLAG_SLANT | |
139 | ? wxFONTSTYLE_SLANT | |
140 | : wxFONTSTYLE_NORMAL; | |
141 | } | |
544229d1 | 142 | |
b5791cc7 FM |
143 | static inline int flags2Weight(int flags) |
144 | { | |
145 | return flags & wxFONTFLAG_LIGHT | |
146 | ? wxFONTWEIGHT_LIGHT | |
147 | : flags & wxFONTFLAG_BOLD | |
148 | ? wxFONTWEIGHT_BOLD | |
149 | : wxFONTWEIGHT_NORMAL; | |
150 | } | |
544229d1 | 151 | |
b5791cc7 FM |
152 | static inline bool flags2Underlined(int flags) |
153 | { | |
154 | return (flags & wxFONTFLAG_UNDERLINED) != 0; | |
544229d1 VZ |
155 | } |
156 | ||
0c5d3e1c VZ |
157 | // ---------------------------------------------------------------------------- |
158 | // wxFontBase | |
159 | // ---------------------------------------------------------------------------- | |
160 | ||
161 | wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM; | |
162 | ||
cafbf6fb VZ |
163 | /* static */ |
164 | void wxFontBase::SetDefaultEncoding(wxFontEncoding encoding) | |
165 | { | |
166 | // GetDefaultEncoding() should return something != wxFONTENCODING_DEFAULT | |
167 | // and, besides, using this value here doesn't make any sense | |
168 | wxCHECK_RET( encoding != wxFONTENCODING_DEFAULT, | |
9a83f860 | 169 | wxT("can't set default encoding to wxFONTENCODING_DEFAULT") ); |
cafbf6fb VZ |
170 | |
171 | ms_encodingDefault = encoding; | |
172 | } | |
173 | ||
799ea011 GD |
174 | wxFontBase::~wxFontBase() |
175 | { | |
176 | // this destructor is required for Darwin | |
177 | } | |
178 | ||
7beba2fc | 179 | /* static */ |
0c5d3e1c | 180 | wxFont *wxFontBase::New(int size, |
0c14b6c3 FM |
181 | wxFontFamily family, |
182 | wxFontStyle style, | |
183 | wxFontWeight weight, | |
0c5d3e1c VZ |
184 | bool underlined, |
185 | const wxString& face, | |
186 | wxFontEncoding encoding) | |
187 | { | |
188 | return new wxFont(size, family, style, weight, underlined, face, encoding); | |
189 | } | |
190 | ||
b5791cc7 FM |
191 | /* static */ |
192 | wxFont *wxFontBase::New(const wxSize& pixelSize, | |
193 | wxFontFamily family, | |
194 | wxFontStyle style, | |
195 | wxFontWeight weight, | |
196 | bool underlined, | |
197 | const wxString& face, | |
198 | wxFontEncoding encoding) | |
544229d1 | 199 | { |
b5791cc7 FM |
200 | return new wxFont(pixelSize, family, style, weight, underlined, |
201 | face, encoding); | |
544229d1 VZ |
202 | } |
203 | ||
204 | /* static */ | |
205 | wxFont *wxFontBase::New(int pointSize, | |
206 | wxFontFamily family, | |
207 | int flags, | |
208 | const wxString& face, | |
209 | wxFontEncoding encoding) | |
210 | { | |
211 | return New(pointSize, family, flags2Style(flags), flags2Weight(flags), | |
212 | flags2Underlined(flags), face, encoding); | |
213 | } | |
214 | ||
215 | /* static */ | |
216 | wxFont *wxFontBase::New(const wxSize& pixelSize, | |
0c14b6c3 | 217 | wxFontFamily family, |
b5791cc7 | 218 | int flags, |
544229d1 VZ |
219 | const wxString& face, |
220 | wxFontEncoding encoding) | |
221 | { | |
b5791cc7 FM |
222 | return New(pixelSize, family, flags2Style(flags), flags2Weight(flags), |
223 | flags2Underlined(flags), face, encoding); | |
544229d1 VZ |
224 | } |
225 | ||
226 | /* static */ | |
b5791cc7 | 227 | wxFont *wxFontBase::New(const wxNativeFontInfo& info) |
544229d1 | 228 | { |
b5791cc7 FM |
229 | return new wxFont(info); |
230 | } | |
231 | ||
232 | /* static */ | |
233 | wxFont *wxFontBase::New(const wxString& strNativeFontDesc) | |
234 | { | |
235 | wxNativeFontInfo fontInfo; | |
236 | if ( !fontInfo.FromString(strNativeFontDesc) ) | |
237 | return new wxFont(*wxNORMAL_FONT); | |
238 | ||
239 | return New(fontInfo); | |
240 | } | |
241 | ||
242 | bool wxFontBase::IsFixedWidth() const | |
243 | { | |
244 | return GetFamily() == wxFONTFAMILY_TELETYPE; | |
544229d1 VZ |
245 | } |
246 | ||
247 | wxSize wxFontBase::GetPixelSize() const | |
248 | { | |
249 | wxScreenDC dc; | |
250 | dc.SetFont(*(wxFont *)this); | |
251 | return wxSize(dc.GetCharWidth(), dc.GetCharHeight()); | |
252 | } | |
253 | ||
254 | bool wxFontBase::IsUsingSizeInPixels() const | |
255 | { | |
256 | return false; | |
257 | } | |
258 | ||
259 | void wxFontBase::SetPixelSize( const wxSize& pixelSize ) | |
260 | { | |
b5791cc7 FM |
261 | wxCHECK_RET( pixelSize.GetWidth() >= 0 && pixelSize.GetHeight() > 0, |
262 | "Negative values for the pixel size or zero pixel height are not allowed" ); | |
263 | ||
544229d1 | 264 | wxScreenDC dc; |
01cb1c26 | 265 | |
b5791cc7 FM |
266 | // NOTE: this algorithm for adjusting the font size is used by all |
267 | // implementations of wxFont except under wxMSW and wxGTK where | |
268 | // native support to font creation using pixel-size is provided. | |
03647350 | 269 | |
b5791cc7 FM |
270 | int largestGood = 0; |
271 | int smallestBad = 0; | |
30764ab5 | 272 | |
b5791cc7 FM |
273 | bool initialGoodFound = false; |
274 | bool initialBadFound = false; | |
7826e2dd | 275 | |
b5791cc7 FM |
276 | // NB: this assignment was separated from the variable definition |
277 | // in order to fix a gcc v3.3.3 compiler crash | |
278 | int currentSize = GetPointSize(); | |
279 | while (currentSize > 0) | |
280 | { | |
281 | dc.SetFont(*static_cast<wxFont*>(this)); | |
7826e2dd | 282 | |
b5791cc7 FM |
283 | // if currentSize (in points) results in a font that is smaller |
284 | // than required by pixelSize it is considered a good size | |
285 | // NOTE: the pixel size width may be zero | |
286 | if (dc.GetCharHeight() <= pixelSize.GetHeight() && | |
287 | (pixelSize.GetWidth() == 0 || | |
288 | dc.GetCharWidth() <= pixelSize.GetWidth())) | |
289 | { | |
290 | largestGood = currentSize; | |
291 | initialGoodFound = true; | |
292 | } | |
293 | else | |
294 | { | |
295 | smallestBad = currentSize; | |
296 | initialBadFound = true; | |
297 | } | |
298 | if (!initialGoodFound) | |
299 | { | |
300 | currentSize /= 2; | |
301 | } | |
302 | else if (!initialBadFound) | |
303 | { | |
304 | currentSize *= 2; | |
305 | } | |
306 | else | |
307 | { | |
308 | int distance = smallestBad - largestGood; | |
309 | if (distance == 1) | |
310 | break; | |
311 | ||
312 | currentSize = largestGood + distance / 2; | |
313 | } | |
314 | ||
315 | SetPointSize(currentSize); | |
316 | } | |
317 | ||
318 | if (currentSize != largestGood) | |
319 | SetPointSize(largestGood); | |
53f6aab7 VZ |
320 | } |
321 | ||
9045ad9d | 322 | void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info) |
30764ab5 | 323 | { |
ab5fe833 | 324 | #ifdef wxNO_NATIVE_FONTINFO |
30764ab5 VZ |
325 | SetPointSize(info.pointSize); |
326 | SetFamily(info.family); | |
327 | SetStyle(info.style); | |
328 | SetWeight(info.weight); | |
329 | SetUnderlined(info.underlined); | |
330 | SetFaceName(info.faceName); | |
331 | SetEncoding(info.encoding); | |
33ac7e6f | 332 | #else |
1e6feb95 | 333 | (void)info; |
30764ab5 VZ |
334 | #endif |
335 | } | |
336 | ||
7826e2dd VZ |
337 | wxString wxFontBase::GetNativeFontInfoDesc() const |
338 | { | |
64932e41 VZ |
339 | wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); |
340 | ||
7826e2dd | 341 | wxString fontDesc; |
3bf5a59b | 342 | const wxNativeFontInfo *fontInfo = GetNativeFontInfo(); |
7826e2dd VZ |
343 | if ( fontInfo ) |
344 | { | |
345 | fontDesc = fontInfo->ToString(); | |
dd05139a | 346 | wxASSERT_MSG(!fontDesc.empty(), wxT("This should be a non-empty string!")); |
85ab460e VZ |
347 | } |
348 | else | |
349 | { | |
7bd236e6 | 350 | wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!")); |
7826e2dd VZ |
351 | } |
352 | ||
353 | return fontDesc; | |
354 | } | |
355 | ||
ab5fe833 VZ |
356 | wxString wxFontBase::GetNativeFontInfoUserDesc() const |
357 | { | |
64932e41 VZ |
358 | wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); |
359 | ||
ab5fe833 | 360 | wxString fontDesc; |
3bf5a59b | 361 | const wxNativeFontInfo *fontInfo = GetNativeFontInfo(); |
ab5fe833 VZ |
362 | if ( fontInfo ) |
363 | { | |
364 | fontDesc = fontInfo->ToUserString(); | |
dd05139a | 365 | wxASSERT_MSG(!fontDesc.empty(), wxT("This should be a non-empty string!")); |
85ab460e VZ |
366 | } |
367 | else | |
368 | { | |
7456f382 | 369 | wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!")); |
ab5fe833 VZ |
370 | } |
371 | ||
372 | return fontDesc; | |
373 | } | |
374 | ||
85ab460e | 375 | bool wxFontBase::SetNativeFontInfo(const wxString& info) |
31d1b66e VZ |
376 | { |
377 | wxNativeFontInfo fontInfo; | |
378 | if ( !info.empty() && fontInfo.FromString(info) ) | |
379 | { | |
380 | SetNativeFontInfo(fontInfo); | |
85ab460e | 381 | return true; |
31d1b66e | 382 | } |
85ab460e | 383 | |
85ab460e | 384 | return false; |
31d1b66e VZ |
385 | } |
386 | ||
85ab460e | 387 | bool wxFontBase::SetNativeFontInfoUserDesc(const wxString& info) |
ab5fe833 VZ |
388 | { |
389 | wxNativeFontInfo fontInfo; | |
390 | if ( !info.empty() && fontInfo.FromUserString(info) ) | |
391 | { | |
392 | SetNativeFontInfo(fontInfo); | |
85ab460e | 393 | return true; |
ab5fe833 | 394 | } |
85ab460e | 395 | |
85ab460e | 396 | return false; |
ab5fe833 VZ |
397 | } |
398 | ||
0c5d3e1c VZ |
399 | bool wxFontBase::operator==(const wxFont& font) const |
400 | { | |
8bf30fe9 VZ |
401 | // either it is the same font, i.e. they share the same common data or they |
402 | // have different ref datas but still describe the same font | |
a38cd629 | 403 | return IsSameAs(font) || |
8bf30fe9 | 404 | ( |
70f70818 | 405 | IsOk() == font.IsOk() && |
8bf30fe9 | 406 | GetPointSize() == font.GetPointSize() && |
82d0e7fe VZ |
407 | // in wxGTK1 GetPixelSize() calls GetInternalFont() which uses |
408 | // operator==() resulting in infinite recursion so we can't use it | |
409 | // in that port | |
410 | #if !defined(__WXGTK__) || defined(__WXGTK20__) | |
cc3de8a3 | 411 | GetPixelSize() == font.GetPixelSize() && |
82d0e7fe | 412 | #endif |
8bf30fe9 VZ |
413 | GetFamily() == font.GetFamily() && |
414 | GetStyle() == font.GetStyle() && | |
e6adf058 | 415 | GetWeight() == font.GetWeight() && |
8bf30fe9 | 416 | GetUnderlined() == font.GetUnderlined() && |
85ab460e | 417 | GetFaceName().IsSameAs(font.GetFaceName(), false) && |
8bf30fe9 VZ |
418 | GetEncoding() == font.GetEncoding() |
419 | ); | |
0c5d3e1c VZ |
420 | } |
421 | ||
59b7da02 VZ |
422 | wxFontFamily wxFontBase::GetFamily() const |
423 | { | |
424 | wxCHECK_MSG( IsOk(), wxFONTFAMILY_UNKNOWN, wxS("invalid font") ); | |
425 | ||
426 | // Don't return wxFONTFAMILY_UNKNOWN from here because it prevents the code | |
427 | // like wxFont(size, wxNORMAL_FONT->GetFamily(), ...) from working (see | |
428 | // #12330). This is really just a hack but it allows to keep compatibility | |
429 | // and doesn't really have any bad drawbacks so do this until someone comes | |
430 | // up with a better idea. | |
431 | const wxFontFamily family = DoGetFamily(); | |
432 | ||
433 | return family == wxFONTFAMILY_UNKNOWN ? wxFONTFAMILY_DEFAULT : family; | |
434 | } | |
435 | ||
0c5d3e1c VZ |
436 | wxString wxFontBase::GetFamilyString() const |
437 | { | |
70f70818 | 438 | wxCHECK_MSG( IsOk(), "wxFONTFAMILY_DEFAULT", "invalid font" ); |
0c5d3e1c VZ |
439 | |
440 | switch ( GetFamily() ) | |
441 | { | |
70f70818 FM |
442 | case wxFONTFAMILY_DECORATIVE: return "wxFONTFAMILY_DECORATIVE"; |
443 | case wxFONTFAMILY_ROMAN: return "wxFONTFAMILY_ROMAN"; | |
444 | case wxFONTFAMILY_SCRIPT: return "wxFONTFAMILY_SCRIPT"; | |
445 | case wxFONTFAMILY_SWISS: return "wxFONTFAMILY_SWISS"; | |
446 | case wxFONTFAMILY_MODERN: return "wxFONTFAMILY_MODERN"; | |
447 | case wxFONTFAMILY_TELETYPE: return "wxFONTFAMILY_TELETYPE"; | |
f2c1b903 | 448 | case wxFONTFAMILY_UNKNOWN: return "wxFONTFAMILY_UNKNOWN"; |
70f70818 | 449 | default: return "wxFONTFAMILY_DEFAULT"; |
0c5d3e1c VZ |
450 | } |
451 | } | |
452 | ||
453 | wxString wxFontBase::GetStyleString() const | |
454 | { | |
70f70818 | 455 | wxCHECK_MSG( IsOk(), "wxFONTSTYLE_DEFAULT", "invalid font" ); |
0c5d3e1c VZ |
456 | |
457 | switch ( GetStyle() ) | |
458 | { | |
70f70818 FM |
459 | case wxFONTSTYLE_NORMAL: return "wxFONTSTYLE_NORMAL"; |
460 | case wxFONTSTYLE_SLANT: return "wxFONTSTYLE_SLANT"; | |
461 | case wxFONTSTYLE_ITALIC: return "wxFONTSTYLE_ITALIC"; | |
462 | default: return "wxFONTSTYLE_DEFAULT"; | |
0c5d3e1c VZ |
463 | } |
464 | } | |
465 | ||
466 | wxString wxFontBase::GetWeightString() const | |
467 | { | |
70f70818 | 468 | wxCHECK_MSG( IsOk(), "wxFONTWEIGHT_DEFAULT", "invalid font" ); |
0c5d3e1c VZ |
469 | |
470 | switch ( GetWeight() ) | |
471 | { | |
70f70818 FM |
472 | case wxFONTWEIGHT_NORMAL: return "wxFONTWEIGHT_NORMAL"; |
473 | case wxFONTWEIGHT_BOLD: return "wxFONTWEIGHT_BOLD"; | |
474 | case wxFONTWEIGHT_LIGHT: return "wxFONTWEIGHT_LIGHT"; | |
475 | default: return "wxFONTWEIGHT_DEFAULT"; | |
0c5d3e1c VZ |
476 | } |
477 | } | |
478 | ||
ff427585 | 479 | bool wxFontBase::SetFaceName(const wxString& facename) |
85ab460e | 480 | { |
ff427585 | 481 | #if wxUSE_FONTENUM |
85ab460e VZ |
482 | if (!wxFontEnumerator::IsValidFacename(facename)) |
483 | { | |
70f70818 | 484 | UnRef(); // make IsOk() return false |
85ab460e VZ |
485 | return false; |
486 | } | |
ff427585 VZ |
487 | #else // !wxUSE_FONTENUM |
488 | wxUnusedVar(facename); | |
489 | #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM | |
85ab460e VZ |
490 | |
491 | return true; | |
492 | } | |
493 | ||
6e7d2550 VZ |
494 | wxFont& wxFont::MakeBold() |
495 | { | |
496 | SetWeight(wxFONTWEIGHT_BOLD); | |
497 | return *this; | |
498 | } | |
499 | ||
500 | wxFont wxFont::Bold() const | |
f76c0758 VZ |
501 | { |
502 | wxFont font(*this); | |
6e7d2550 | 503 | font.MakeBold(); |
f76c0758 VZ |
504 | return font; |
505 | } | |
506 | ||
6e7d2550 VZ |
507 | wxFont& wxFont::MakeItalic() |
508 | { | |
509 | SetStyle(wxFONTSTYLE_ITALIC); | |
510 | return *this; | |
511 | } | |
512 | ||
513 | wxFont wxFont::Italic() const | |
f76c0758 VZ |
514 | { |
515 | wxFont font(*this); | |
516 | font.SetStyle(wxFONTSTYLE_ITALIC); | |
517 | return font; | |
518 | } | |
519 | ||
6e7d2550 VZ |
520 | wxFont& wxFont::Scale(float x) |
521 | { | |
522 | SetPointSize(int(x*GetPointSize() + 0.5)); | |
523 | return *this; | |
524 | } | |
525 | ||
526 | wxFont wxFont::Scaled(float x) const | |
f76c0758 VZ |
527 | { |
528 | wxFont font(*this); | |
6e7d2550 | 529 | font.Scale(x); |
f76c0758 VZ |
530 | return font; |
531 | } | |
85ab460e | 532 | |
30764ab5 VZ |
533 | // ---------------------------------------------------------------------------- |
534 | // wxNativeFontInfo | |
535 | // ---------------------------------------------------------------------------- | |
536 | ||
85ab460e | 537 | // Up to now, there are no native implementations of this function: |
ff427585 | 538 | void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames) |
85ab460e | 539 | { |
ff427585 | 540 | #if wxUSE_FONTENUM |
85ab460e VZ |
541 | for (size_t i=0; i < facenames.GetCount(); i++) |
542 | { | |
543 | if (wxFontEnumerator::IsValidFacename(facenames[i])) | |
544 | { | |
545 | SetFaceName(facenames[i]); | |
546 | return; | |
547 | } | |
548 | } | |
549 | ||
550 | // set the first valid facename we can find on this system | |
551 | wxString validfacename = wxFontEnumerator::GetFacenames().Item(0); | |
552 | wxLogTrace(wxT("font"), wxT("Falling back to '%s'"), validfacename.c_str()); | |
553 | SetFaceName(validfacename); | |
ff427585 VZ |
554 | #else // !wxUSE_FONTENUM |
555 | SetFaceName(facenames[0]); | |
556 | #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM | |
85ab460e VZ |
557 | } |
558 | ||
559 | ||
ab5fe833 VZ |
560 | #ifdef wxNO_NATIVE_FONTINFO |
561 | ||
30764ab5 VZ |
562 | // These are the generic forms of FromString()/ToString. |
563 | // | |
564 | // convert to/from the string representation: format is | |
09fcd889 | 565 | // version;pointsize;family;style;weight;underlined;facename;encoding |
30764ab5 VZ |
566 | |
567 | bool wxNativeFontInfo::FromString(const wxString& s) | |
568 | { | |
569 | long l; | |
570 | ||
9a83f860 | 571 | wxStringTokenizer tokenizer(s, wxT(";")); |
30764ab5 VZ |
572 | |
573 | wxString token = tokenizer.GetNextToken(); | |
09fcd889 VZ |
574 | // |
575 | // Ignore the version for now | |
576 | // | |
33ac7e6f | 577 | |
09fcd889 | 578 | token = tokenizer.GetNextToken(); |
30764ab5 | 579 | if ( !token.ToLong(&l) ) |
a62848fd | 580 | return false; |
30764ab5 VZ |
581 | pointSize = (int)l; |
582 | ||
583 | token = tokenizer.GetNextToken(); | |
584 | if ( !token.ToLong(&l) ) | |
a62848fd | 585 | return false; |
f7b301fa | 586 | family = (wxFontFamily)l; |
30764ab5 VZ |
587 | |
588 | token = tokenizer.GetNextToken(); | |
589 | if ( !token.ToLong(&l) ) | |
a62848fd | 590 | return false; |
ab5fe833 | 591 | style = (wxFontStyle)l; |
30764ab5 VZ |
592 | |
593 | token = tokenizer.GetNextToken(); | |
594 | if ( !token.ToLong(&l) ) | |
a62848fd | 595 | return false; |
ab5fe833 | 596 | weight = (wxFontWeight)l; |
30764ab5 VZ |
597 | |
598 | token = tokenizer.GetNextToken(); | |
599 | if ( !token.ToLong(&l) ) | |
a62848fd | 600 | return false; |
189e08b4 | 601 | underlined = l != 0; |
30764ab5 VZ |
602 | |
603 | faceName = tokenizer.GetNextToken(); | |
0a9f0ef7 JS |
604 | |
605 | #ifndef __WXMAC__ | |
30764ab5 | 606 | if( !faceName ) |
a62848fd | 607 | return false; |
0a9f0ef7 | 608 | #endif |
30764ab5 VZ |
609 | |
610 | token = tokenizer.GetNextToken(); | |
611 | if ( !token.ToLong(&l) ) | |
a62848fd | 612 | return false; |
30764ab5 VZ |
613 | encoding = (wxFontEncoding)l; |
614 | ||
a62848fd | 615 | return true; |
30764ab5 VZ |
616 | } |
617 | ||
618 | wxString wxNativeFontInfo::ToString() const | |
619 | { | |
620 | wxString s; | |
621 | ||
9a83f860 | 622 | s.Printf(wxT("%d;%d;%d;%d;%d;%d;%s;%d"), |
09fcd889 | 623 | 0, // version |
30764ab5 VZ |
624 | pointSize, |
625 | family, | |
ab5fe833 VZ |
626 | (int)style, |
627 | (int)weight, | |
30764ab5 VZ |
628 | underlined, |
629 | faceName.GetData(), | |
630 | (int)encoding); | |
631 | ||
632 | return s; | |
633 | } | |
634 | ||
ab5fe833 VZ |
635 | void wxNativeFontInfo::Init() |
636 | { | |
3bf5a59b | 637 | pointSize = 0; |
ab5fe833 VZ |
638 | family = wxFONTFAMILY_DEFAULT; |
639 | style = wxFONTSTYLE_NORMAL; | |
640 | weight = wxFONTWEIGHT_NORMAL; | |
a62848fd | 641 | underlined = false; |
ab5fe833 VZ |
642 | faceName.clear(); |
643 | encoding = wxFONTENCODING_DEFAULT; | |
644 | } | |
645 | ||
646 | int wxNativeFontInfo::GetPointSize() const | |
647 | { | |
648 | return pointSize; | |
649 | } | |
650 | ||
651 | wxFontStyle wxNativeFontInfo::GetStyle() const | |
652 | { | |
653 | return style; | |
654 | } | |
655 | ||
656 | wxFontWeight wxNativeFontInfo::GetWeight() const | |
657 | { | |
658 | return weight; | |
659 | } | |
660 | ||
661 | bool wxNativeFontInfo::GetUnderlined() const | |
662 | { | |
663 | return underlined; | |
664 | } | |
665 | ||
666 | wxString wxNativeFontInfo::GetFaceName() const | |
667 | { | |
668 | return faceName; | |
669 | } | |
670 | ||
7936354d VZ |
671 | wxFontFamily wxNativeFontInfo::GetFamily() const |
672 | { | |
673 | return family; | |
674 | } | |
675 | ||
ab5fe833 VZ |
676 | wxFontEncoding wxNativeFontInfo::GetEncoding() const |
677 | { | |
678 | return encoding; | |
679 | } | |
680 | ||
681 | void wxNativeFontInfo::SetPointSize(int pointsize) | |
682 | { | |
683 | pointSize = pointsize; | |
684 | } | |
685 | ||
686 | void wxNativeFontInfo::SetStyle(wxFontStyle style_) | |
687 | { | |
688 | style = style_; | |
689 | } | |
690 | ||
691 | void wxNativeFontInfo::SetWeight(wxFontWeight weight_) | |
692 | { | |
693 | weight = weight_; | |
694 | } | |
695 | ||
696 | void wxNativeFontInfo::SetUnderlined(bool underlined_) | |
697 | { | |
698 | underlined = underlined_; | |
699 | } | |
700 | ||
85ab460e | 701 | bool wxNativeFontInfo::SetFaceName(const wxString& facename_) |
ab5fe833 | 702 | { |
f7b301fa | 703 | faceName = facename_; |
85ab460e | 704 | return true; |
ab5fe833 VZ |
705 | } |
706 | ||
3f1d1373 | 707 | void wxNativeFontInfo::SetFamily(wxFontFamily family_) |
7936354d VZ |
708 | { |
709 | family = family_; | |
710 | } | |
711 | ||
ab5fe833 VZ |
712 | void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_) |
713 | { | |
714 | encoding = encoding_; | |
715 | } | |
716 | ||
7826e2dd | 717 | #endif // generic wxNativeFontInfo implementation |
30764ab5 | 718 | |
ab5fe833 VZ |
719 | // conversion to/from user-readable string: this is used in the generic |
720 | // versions and under MSW as well because there is no standard font description | |
721 | // format there anyhow (but there is a well-defined standard for X11 fonts used | |
722 | // by wxGTK and wxMotif) | |
723 | ||
f1c40652 | 724 | #if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) || defined(__WXOSX__) |
ab5fe833 VZ |
725 | |
726 | wxString wxNativeFontInfo::ToUserString() const | |
727 | { | |
728 | wxString desc; | |
729 | ||
730 | // first put the adjectives, if any - this is English-centric, of course, | |
731 | // but what else can we do? | |
732 | if ( GetUnderlined() ) | |
733 | { | |
85ab460e | 734 | desc << _("underlined"); |
ab5fe833 VZ |
735 | } |
736 | ||
737 | switch ( GetWeight() ) | |
738 | { | |
739 | default: | |
9a83f860 | 740 | wxFAIL_MSG( wxT("unknown font weight") ); |
ab5fe833 VZ |
741 | // fall through |
742 | ||
743 | case wxFONTWEIGHT_NORMAL: | |
744 | break; | |
745 | ||
746 | case wxFONTWEIGHT_LIGHT: | |
85ab460e | 747 | desc << _(" light"); |
ab5fe833 VZ |
748 | break; |
749 | ||
750 | case wxFONTWEIGHT_BOLD: | |
85ab460e | 751 | desc << _(" bold"); |
ab5fe833 VZ |
752 | break; |
753 | } | |
754 | ||
755 | switch ( GetStyle() ) | |
756 | { | |
757 | default: | |
9a83f860 | 758 | wxFAIL_MSG( wxT("unknown font style") ); |
ab5fe833 VZ |
759 | // fall through |
760 | ||
761 | case wxFONTSTYLE_NORMAL: | |
762 | break; | |
763 | ||
764 | // we don't distinguish between the two for now anyhow... | |
765 | case wxFONTSTYLE_ITALIC: | |
766 | case wxFONTSTYLE_SLANT: | |
85ab460e | 767 | desc << _(" italic"); |
ab5fe833 VZ |
768 | break; |
769 | } | |
770 | ||
a9249b2e VZ |
771 | wxString face = GetFaceName(); |
772 | if ( !face.empty() ) | |
ab5fe833 | 773 | { |
c1ab2be0 FM |
774 | if (face.Contains(' ') || face.Contains(';') || face.Contains(',')) |
775 | { | |
776 | face.Replace("'", ""); | |
777 | // eventually remove quote characters: most systems do not | |
778 | // allow them in a facename anyway so this usually does nothing | |
779 | ||
780 | // make it possible for FromUserString() function to understand | |
781 | // that the different words which compose this facename are | |
782 | // not different adjectives or other data but rather all parts | |
783 | // of the facename | |
9a83f860 | 784 | desc << wxT(" '") << face << _("'"); |
c1ab2be0 FM |
785 | } |
786 | else | |
9a83f860 | 787 | desc << wxT(' ') << face; |
ab5fe833 | 788 | } |
1a2ca1d6 VZ |
789 | else // no face name specified |
790 | { | |
791 | // use the family | |
792 | wxString familyStr; | |
793 | switch ( GetFamily() ) | |
794 | { | |
795 | case wxFONTFAMILY_DECORATIVE: | |
796 | familyStr = "decorative"; | |
797 | break; | |
798 | ||
799 | case wxFONTFAMILY_ROMAN: | |
800 | familyStr = "roman"; | |
801 | break; | |
802 | ||
803 | case wxFONTFAMILY_SCRIPT: | |
804 | familyStr = "script"; | |
805 | break; | |
806 | ||
807 | case wxFONTFAMILY_SWISS: | |
808 | familyStr = "swiss"; | |
809 | break; | |
810 | ||
811 | case wxFONTFAMILY_MODERN: | |
812 | familyStr = "modern"; | |
813 | break; | |
814 | ||
815 | case wxFONTFAMILY_TELETYPE: | |
816 | familyStr = "teletype"; | |
817 | break; | |
818 | ||
819 | case wxFONTFAMILY_DEFAULT: | |
820 | case wxFONTFAMILY_UNKNOWN: | |
821 | break; | |
822 | ||
823 | default: | |
824 | wxFAIL_MSG( "unknown font family" ); | |
825 | } | |
826 | ||
827 | if ( !familyStr.empty() ) | |
828 | desc << " '" << familyStr << " family'"; | |
829 | } | |
ab5fe833 | 830 | |
a9249b2e VZ |
831 | int size = GetPointSize(); |
832 | if ( size != wxNORMAL_FONT->GetPointSize() ) | |
ab5fe833 | 833 | { |
9a83f860 | 834 | desc << wxT(' ') << size; |
ab5fe833 | 835 | } |
a9249b2e | 836 | |
e7e52b6d | 837 | #if wxUSE_FONTMAP |
a9249b2e VZ |
838 | wxFontEncoding enc = GetEncoding(); |
839 | if ( enc != wxFONTENCODING_DEFAULT && enc != wxFONTENCODING_SYSTEM ) | |
840 | { | |
9a83f860 | 841 | desc << wxT(' ') << wxFontMapper::GetEncodingName(enc); |
a9249b2e | 842 | } |
e7e52b6d | 843 | #endif // wxUSE_FONTMAP |
a9249b2e | 844 | |
85ab460e | 845 | return desc.Strip(wxString::both).MakeLower(); |
ab5fe833 VZ |
846 | } |
847 | ||
848 | bool wxNativeFontInfo::FromUserString(const wxString& s) | |
849 | { | |
850 | // reset to the default state | |
851 | Init(); | |
852 | ||
c1ab2be0 FM |
853 | // ToUserString() will quote the facename if it contains spaces, commas |
854 | // or semicolons: we must be able to understand that quoted text is | |
855 | // a single token: | |
856 | wxString toparse(s); | |
c1ab2be0 | 857 | |
ab5fe833 | 858 | // parse a more or less free form string |
9a83f860 | 859 | wxStringTokenizer tokenizer(toparse, wxT(";, "), wxTOKEN_STRTOK); |
ab5fe833 VZ |
860 | |
861 | wxString face; | |
862 | unsigned long size; | |
77f15ffe VS |
863 | bool weightfound = false, pointsizefound = false; |
864 | #if wxUSE_FONTMAP | |
865 | bool encodingfound = false; | |
866 | #endif | |
c1ab2be0 | 867 | bool insideQuotes = false; |
ab5fe833 VZ |
868 | |
869 | while ( tokenizer.HasMoreTokens() ) | |
870 | { | |
871 | wxString token = tokenizer.GetNextToken(); | |
872 | ||
873 | // normalize it | |
a62848fd | 874 | token.Trim(true).Trim(false).MakeLower(); |
c1ab2be0 FM |
875 | if (insideQuotes) |
876 | { | |
03647350 | 877 | if (token.StartsWith("'") || |
c1ab2be0 FM |
878 | token.EndsWith("'")) |
879 | { | |
880 | insideQuotes = false; | |
881 | ||
882 | // add this last token to the facename: | |
883 | face += " " + token; | |
884 | ||
885 | // normalize facename: | |
886 | face = face.Trim(true).Trim(false); | |
887 | face.Replace("'", ""); | |
888 | ||
889 | continue; | |
890 | } | |
891 | } | |
892 | else | |
893 | { | |
894 | if (token.StartsWith("'")) | |
895 | insideQuotes = true; | |
896 | } | |
ab5fe833 VZ |
897 | |
898 | // look for the known tokens | |
c1ab2be0 FM |
899 | if ( insideQuotes ) |
900 | { | |
901 | // only the facename may be quoted: | |
902 | face += " " + token; | |
903 | continue; | |
904 | } | |
9a83f860 | 905 | if ( token == wxT("underlined") || token == _("underlined") ) |
ab5fe833 | 906 | { |
a62848fd | 907 | SetUnderlined(true); |
ab5fe833 | 908 | } |
9a83f860 | 909 | else if ( token == wxT("light") || token == _("light") ) |
ab5fe833 VZ |
910 | { |
911 | SetWeight(wxFONTWEIGHT_LIGHT); | |
85ab460e | 912 | weightfound = true; |
ab5fe833 | 913 | } |
9a83f860 | 914 | else if ( token == wxT("bold") || token == _("bold") ) |
ab5fe833 VZ |
915 | { |
916 | SetWeight(wxFONTWEIGHT_BOLD); | |
85ab460e | 917 | weightfound = true; |
ab5fe833 | 918 | } |
9a83f860 | 919 | else if ( token == wxT("italic") || token == _("italic") ) |
ab5fe833 VZ |
920 | { |
921 | SetStyle(wxFONTSTYLE_ITALIC); | |
922 | } | |
923 | else if ( token.ToULong(&size) ) | |
924 | { | |
a9249b2e | 925 | SetPointSize(size); |
85ab460e | 926 | pointsizefound = true; |
ab5fe833 | 927 | } |
85ab460e VZ |
928 | else |
929 | { | |
e7e52b6d | 930 | #if wxUSE_FONTMAP |
85ab460e VZ |
931 | // try to interpret this as an encoding |
932 | wxFontEncoding encoding = wxFontMapper::Get()->CharsetToEncoding(token, false); | |
933 | if ( encoding != wxFONTENCODING_DEFAULT && | |
934 | encoding != wxFONTENCODING_SYSTEM ) // returned when the recognition failed | |
ab5fe833 VZ |
935 | { |
936 | SetEncoding(encoding); | |
85ab460e | 937 | encodingfound = true; |
ab5fe833 | 938 | } |
85ab460e | 939 | else |
ab5fe833 | 940 | { |
85ab460e VZ |
941 | #endif // wxUSE_FONTMAP |
942 | ||
943 | // assume it is the face name | |
ab5fe833 VZ |
944 | if ( !face.empty() ) |
945 | { | |
9a83f860 | 946 | face += wxT(' '); |
ab5fe833 VZ |
947 | } |
948 | ||
949 | face += token; | |
950 | ||
951 | // skip the code which resets face below | |
952 | continue; | |
85ab460e VZ |
953 | |
954 | #if wxUSE_FONTMAP | |
955 | } | |
956 | #endif // wxUSE_FONTMAP | |
ab5fe833 VZ |
957 | } |
958 | ||
959 | // if we had had the facename, we shouldn't continue appending tokens | |
960 | // to it (i.e. "foo bold bar" shouldn't result in the facename "foo | |
961 | // bar") | |
962 | if ( !face.empty() ) | |
963 | { | |
1a2ca1d6 VZ |
964 | wxString familyStr; |
965 | if ( face.EndsWith(" family", &familyStr) ) | |
966 | { | |
967 | // it's not a facename but rather a font family | |
968 | wxFontFamily family; | |
969 | if ( familyStr == "decorative" ) | |
970 | family = wxFONTFAMILY_DECORATIVE; | |
971 | else if ( familyStr == "roman" ) | |
972 | family = wxFONTFAMILY_ROMAN; | |
973 | else if ( familyStr == "script" ) | |
974 | family = wxFONTFAMILY_SCRIPT; | |
975 | else if ( familyStr == "swiss" ) | |
976 | family = wxFONTFAMILY_SWISS; | |
977 | else if ( familyStr == "modern" ) | |
978 | family = wxFONTFAMILY_MODERN; | |
979 | else if ( familyStr == "teletype" ) | |
980 | family = wxFONTFAMILY_TELETYPE; | |
981 | else | |
982 | return false; | |
03647350 | 983 | |
1a2ca1d6 VZ |
984 | SetFamily(family); |
985 | } | |
85ab460e VZ |
986 | // NB: the check on the facename is implemented in wxFontBase::SetFaceName |
987 | // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely | |
988 | // call here wxFontEnumerator::IsValidFacename | |
1a2ca1d6 | 989 | else if ( |
ff427585 VZ |
990 | #if wxUSE_FONTENUM |
991 | !wxFontEnumerator::IsValidFacename(face) || | |
992 | #endif // wxUSE_FONTENUM | |
993 | !SetFaceName(face) ) | |
994 | { | |
85ab460e | 995 | SetFaceName(wxNORMAL_FONT->GetFaceName()); |
ff427585 VZ |
996 | } |
997 | ||
ab5fe833 VZ |
998 | face.clear(); |
999 | } | |
1000 | } | |
1001 | ||
1002 | // we might not have flushed it inside the loop | |
1003 | if ( !face.empty() ) | |
1004 | { | |
85ab460e VZ |
1005 | // NB: the check on the facename is implemented in wxFontBase::SetFaceName |
1006 | // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely | |
1007 | // call here wxFontEnumerator::IsValidFacename | |
ff427585 VZ |
1008 | if ( |
1009 | #if wxUSE_FONTENUM | |
1010 | !wxFontEnumerator::IsValidFacename(face) || | |
1011 | #endif // wxUSE_FONTENUM | |
1012 | !SetFaceName(face) ) | |
1013 | { | |
1014 | SetFaceName(wxNORMAL_FONT->GetFaceName()); | |
1015 | } | |
ab5fe833 VZ |
1016 | } |
1017 | ||
85ab460e VZ |
1018 | // set point size to default value if size was not given |
1019 | if ( !pointsizefound ) | |
1020 | SetPointSize(wxNORMAL_FONT->GetPointSize()); | |
1021 | ||
1022 | // set font weight to default value if weight was not given | |
1023 | if ( !weightfound ) | |
1024 | SetWeight(wxFONTWEIGHT_NORMAL); | |
1025 | ||
1026 | #if wxUSE_FONTMAP | |
1027 | // set font encoding to default value if encoding was not given | |
1028 | if ( !encodingfound ) | |
1029 | SetEncoding(wxFONTENCODING_SYSTEM); | |
1030 | #endif // wxUSE_FONTMAP | |
1031 | ||
a62848fd | 1032 | return true; |
ab5fe833 VZ |
1033 | } |
1034 | ||
0eb529d9 | 1035 | #endif // generic or wxMSW or wxOS2 |
fc9361e3 VZ |
1036 | |
1037 | ||
1038 | // wxFont <-> wxString utilities, used by wxConfig | |
1039 | wxString wxToString(const wxFontBase& font) | |
1040 | { | |
1041 | return font.IsOk() ? font.GetNativeFontInfoDesc() | |
1042 | : wxString(); | |
1043 | } | |
1044 | ||
1045 | bool wxFromString(const wxString& str, wxFontBase *font) | |
1046 | { | |
9a83f860 | 1047 | wxCHECK_MSG( font, false, wxT("NULL output parameter") ); |
fc9361e3 VZ |
1048 | |
1049 | if ( str.empty() ) | |
1050 | { | |
1051 | *font = wxNullFont; | |
1052 | return true; | |
1053 | } | |
1054 | ||
1055 | return font->SetNativeFontInfo(str); | |
1056 | } | |
1057 | ||
1058 |