1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/fontcmn.cpp
3 // Purpose: implementation of wxFontBase methods
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
32 #include "wx/dcscreen.h"
34 #include "wx/gdicmn.h"
37 #if defined(__WXMSW__)
38 #include "wx/msw/private.h" // includes windows.h for LOGFONT
39 #include "wx/msw/winundef.h"
42 #include "wx/fontutil.h" // for wxNativeFontInfo
43 #include "wx/fontmap.h"
44 #include "wx/fontenum.h"
46 #include "wx/tokenzr.h"
48 // debugger helper: this function can be called from a debugger to show what
50 extern const char *wxDumpFont(const wxFont
*font
)
54 const wxFontWeight weight
= font
->GetWeight();
57 s
.Printf(wxS("%s-%s-%s-%d-%d"),
59 weight
== wxFONTWEIGHT_NORMAL
61 : weight
== wxFONTWEIGHT_BOLD
64 font
->GetStyle() == wxFONTSTYLE_NORMAL
70 wxStrlcpy(buf
, s
.mb_str(), WXSIZEOF(buf
));
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 wxBEGIN_ENUM( wxFontFamily
)
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
)
86 wxEND_ENUM( wxFontFamily
)
88 wxBEGIN_ENUM( wxFontStyle
)
89 wxENUM_MEMBER( wxFONTSTYLE_NORMAL
)
90 wxENUM_MEMBER( wxFONTSTYLE_ITALIC
)
91 wxENUM_MEMBER( wxFONTSTYLE_SLANT
)
92 wxEND_ENUM( wxFontStyle
)
94 wxBEGIN_ENUM( wxFontWeight
)
95 wxENUM_MEMBER( wxFONTWEIGHT_NORMAL
)
96 wxENUM_MEMBER( wxFONTWEIGHT_LIGHT
)
97 wxENUM_MEMBER( wxFONTWEIGHT_BOLD
)
98 wxEND_ENUM( wxFontWeight
)
100 wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
, "wx/font.h")
102 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxFont>)
104 wxBEGIN_PROPERTIES_TABLE(wxFont
)
105 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12, 0 /*flags*/, \
106 wxT("Helpstring"), wxT("group"))
107 wxPROPERTY( Family
, wxFontFamily
, SetFamily
, GetFamily
, (wxFontFamily
)wxDEFAULT
, \
108 0 /*flags*/, wxT("Helpstring"), wxT("group")) // wxFontFamily
109 wxPROPERTY( Style
, wxFontStyle
, SetStyle
, GetStyle
, (wxFontStyle
)wxNORMAL
, 0 /*flags*/, \
110 wxT("Helpstring"), wxT("group")) // wxFontStyle
111 wxPROPERTY( Weight
, wxFontWeight
, SetWeight
, GetWeight
, (wxFontWeight
)wxNORMAL
, 0 /*flags*/, \
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()
121 wxCONSTRUCTOR_6( wxFont
, int, Size
, wxFontFamily
, Family
, wxFontStyle
, Style
, wxFontWeight
, Weight
, \
122 bool, Underlined
, wxString
, Face
)
124 wxEMPTY_HANDLERS_TABLE(wxFont
)
126 // ============================================================================
128 // ============================================================================
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 static inline int flags2Style(int flags
)
136 return flags
& wxFONTFLAG_ITALIC
138 : flags
& wxFONTFLAG_SLANT
140 : wxFONTSTYLE_NORMAL
;
143 static inline int flags2Weight(int flags
)
145 return flags
& wxFONTFLAG_LIGHT
147 : flags
& wxFONTFLAG_BOLD
149 : wxFONTWEIGHT_NORMAL
;
152 static inline bool flags2Underlined(int flags
)
154 return (flags
& wxFONTFLAG_UNDERLINED
) != 0;
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 wxFontEncoding
wxFontBase::ms_encodingDefault
= wxFONTENCODING_SYSTEM
;
164 void wxFontBase::SetDefaultEncoding(wxFontEncoding encoding
)
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
,
169 wxT("can't set default encoding to wxFONTENCODING_DEFAULT") );
171 ms_encodingDefault
= encoding
;
174 wxFontBase::~wxFontBase()
176 // this destructor is required for Darwin
180 wxFont
*wxFontBase::New(int size
,
185 const wxString
& face
,
186 wxFontEncoding encoding
)
188 return new wxFont(size
, family
, style
, weight
, underlined
, face
, encoding
);
192 wxFont
*wxFontBase::New(const wxSize
& pixelSize
,
197 const wxString
& face
,
198 wxFontEncoding encoding
)
200 return new wxFont(pixelSize
, family
, style
, weight
, underlined
,
205 wxFont
*wxFontBase::New(int pointSize
,
208 const wxString
& face
,
209 wxFontEncoding encoding
)
211 return New(pointSize
, family
, flags2Style(flags
), flags2Weight(flags
),
212 flags2Underlined(flags
), face
, encoding
);
216 wxFont
*wxFontBase::New(const wxSize
& pixelSize
,
219 const wxString
& face
,
220 wxFontEncoding encoding
)
222 return New(pixelSize
, family
, flags2Style(flags
), flags2Weight(flags
),
223 flags2Underlined(flags
), face
, encoding
);
227 wxFont
*wxFontBase::New(const wxNativeFontInfo
& info
)
229 return new wxFont(info
);
233 wxFont
*wxFontBase::New(const wxString
& strNativeFontDesc
)
235 wxNativeFontInfo fontInfo
;
236 if ( !fontInfo
.FromString(strNativeFontDesc
) )
237 return new wxFont(*wxNORMAL_FONT
);
239 return New(fontInfo
);
242 bool wxFontBase::IsFixedWidth() const
244 return GetFamily() == wxFONTFAMILY_TELETYPE
;
247 wxSize
wxFontBase::GetPixelSize() const
250 dc
.SetFont(*(wxFont
*)this);
251 return wxSize(dc
.GetCharWidth(), dc
.GetCharHeight());
254 bool wxFontBase::IsUsingSizeInPixels() const
259 void wxFontBase::SetPixelSize( const wxSize
& pixelSize
)
261 wxCHECK_RET( pixelSize
.GetWidth() >= 0 && pixelSize
.GetHeight() > 0,
262 "Negative values for the pixel size or zero pixel height are not allowed" );
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.
273 bool initialGoodFound
= false;
274 bool initialBadFound
= false;
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)
281 dc
.SetFont(*static_cast<wxFont
*>(this));
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()))
290 largestGood
= currentSize
;
291 initialGoodFound
= true;
295 smallestBad
= currentSize
;
296 initialBadFound
= true;
298 if (!initialGoodFound
)
302 else if (!initialBadFound
)
308 int distance
= smallestBad
- largestGood
;
312 currentSize
= largestGood
+ distance
/ 2;
315 SetPointSize(currentSize
);
318 if (currentSize
!= largestGood
)
319 SetPointSize(largestGood
);
322 void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
324 #ifdef wxNO_NATIVE_FONTINFO
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
);
337 wxString
wxFontBase::GetNativeFontInfoDesc() const
339 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
342 const wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
345 fontDesc
= fontInfo
->ToString();
346 wxASSERT_MSG(!fontDesc
.empty(), wxT("This should be a non-empty string!"));
350 wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!"));
356 wxString
wxFontBase::GetNativeFontInfoUserDesc() const
358 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
361 const wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
364 fontDesc
= fontInfo
->ToUserString();
365 wxASSERT_MSG(!fontDesc
.empty(), wxT("This should be a non-empty string!"));
369 wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!"));
375 bool wxFontBase::SetNativeFontInfo(const wxString
& info
)
377 wxNativeFontInfo fontInfo
;
378 if ( !info
.empty() && fontInfo
.FromString(info
) )
380 SetNativeFontInfo(fontInfo
);
387 bool wxFontBase::SetNativeFontInfoUserDesc(const wxString
& info
)
389 wxNativeFontInfo fontInfo
;
390 if ( !info
.empty() && fontInfo
.FromUserString(info
) )
392 SetNativeFontInfo(fontInfo
);
399 bool wxFontBase::operator==(const wxFont
& font
) const
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
403 return IsSameAs(font
) ||
405 IsOk() == font
.IsOk() &&
406 GetPointSize() == font
.GetPointSize() &&
407 // in wxGTK1 GetPixelSize() calls GetInternalFont() which uses
408 // operator==() resulting in infinite recursion so we can't use it
410 #if !defined(__WXGTK__) || defined(__WXGTK20__)
411 GetPixelSize() == font
.GetPixelSize() &&
413 GetFamily() == font
.GetFamily() &&
414 GetStyle() == font
.GetStyle() &&
415 GetWeight() == font
.GetWeight() &&
416 GetUnderlined() == font
.GetUnderlined() &&
417 GetFaceName().IsSameAs(font
.GetFaceName(), false) &&
418 GetEncoding() == font
.GetEncoding()
422 wxFontFamily
wxFontBase::GetFamily() const
424 wxCHECK_MSG( IsOk(), wxFONTFAMILY_UNKNOWN
, wxS("invalid font") );
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();
433 return family
== wxFONTFAMILY_UNKNOWN
? wxFONTFAMILY_DEFAULT
: family
;
436 wxString
wxFontBase::GetFamilyString() const
438 wxCHECK_MSG( IsOk(), "wxFONTFAMILY_DEFAULT", "invalid font" );
440 switch ( GetFamily() )
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";
448 case wxFONTFAMILY_UNKNOWN
: return "wxFONTFAMILY_UNKNOWN";
449 default: return "wxFONTFAMILY_DEFAULT";
453 wxString
wxFontBase::GetStyleString() const
455 wxCHECK_MSG( IsOk(), "wxFONTSTYLE_DEFAULT", "invalid font" );
457 switch ( GetStyle() )
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";
466 wxString
wxFontBase::GetWeightString() const
468 wxCHECK_MSG( IsOk(), "wxFONTWEIGHT_DEFAULT", "invalid font" );
470 switch ( GetWeight() )
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";
479 bool wxFontBase::SetFaceName(const wxString
& facename
)
482 if (!wxFontEnumerator::IsValidFacename(facename
))
484 UnRef(); // make IsOk() return false
487 #else // !wxUSE_FONTENUM
488 wxUnusedVar(facename
);
489 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
494 void wxFontBase::SetSymbolicSize(wxFontSymbolicSize size
)
496 SetSymbolicSizeRelativeTo(size
, wxNORMAL_FONT
->GetPointSize());
500 int wxFontBase::AdjustToSymbolicSize(wxFontSymbolicSize size
, int base
)
502 // Using a fixed factor (1.2, from CSS2) is a bad idea as explained at
503 // http://www.w3.org/TR/CSS21/fonts.html#font-size-props so use the values
504 // from http://style.cleverchimp.com/font_size_intervals/altintervals.html
506 static const float factors
[] = { 0.60f
, 0.75f
, 0.89f
, 1.f
, 1.2f
, 1.5f
, 2.f
};
508 wxCOMPILE_TIME_ASSERT
510 WXSIZEOF(factors
) == wxFONTSIZE_XX_LARGE
- wxFONTSIZE_XX_SMALL
+ 1,
511 WrongFontSizeFactorsSize
514 return factors
[size
- wxFONTSIZE_XX_SMALL
]*base
;
517 wxFont
& wxFont::MakeBold()
519 SetWeight(wxFONTWEIGHT_BOLD
);
523 wxFont
wxFont::Bold() const
530 wxFont
& wxFont::MakeItalic()
532 SetStyle(wxFONTSTYLE_ITALIC
);
536 wxFont
wxFont::Italic() const
543 wxFont
& wxFont::MakeUnderlined()
549 wxFont
wxFont::Underlined() const
552 font
.MakeUnderlined();
556 wxFont
& wxFont::Scale(float x
)
558 SetPointSize(int(x
*GetPointSize() + 0.5));
562 wxFont
wxFont::Scaled(float x
) const
569 // ----------------------------------------------------------------------------
571 // ----------------------------------------------------------------------------
573 // Up to now, there are no native implementations of this function:
574 void wxNativeFontInfo::SetFaceName(const wxArrayString
& facenames
)
577 for (size_t i
=0; i
< facenames
.GetCount(); i
++)
579 if (wxFontEnumerator::IsValidFacename(facenames
[i
]))
581 SetFaceName(facenames
[i
]);
586 // set the first valid facename we can find on this system
587 wxString validfacename
= wxFontEnumerator::GetFacenames().Item(0);
588 wxLogTrace(wxT("font"), wxT("Falling back to '%s'"), validfacename
.c_str());
589 SetFaceName(validfacename
);
590 #else // !wxUSE_FONTENUM
591 SetFaceName(facenames
[0]);
592 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
596 #ifdef wxNO_NATIVE_FONTINFO
598 // These are the generic forms of FromString()/ToString.
600 // convert to/from the string representation: format is
601 // version;pointsize;family;style;weight;underlined;facename;encoding
603 bool wxNativeFontInfo::FromString(const wxString
& s
)
607 wxStringTokenizer
tokenizer(s
, wxT(";"));
609 wxString token
= tokenizer
.GetNextToken();
611 // Ignore the version for now
614 token
= tokenizer
.GetNextToken();
615 if ( !token
.ToLong(&l
) )
619 token
= tokenizer
.GetNextToken();
620 if ( !token
.ToLong(&l
) )
622 family
= (wxFontFamily
)l
;
624 token
= tokenizer
.GetNextToken();
625 if ( !token
.ToLong(&l
) )
627 style
= (wxFontStyle
)l
;
629 token
= tokenizer
.GetNextToken();
630 if ( !token
.ToLong(&l
) )
632 weight
= (wxFontWeight
)l
;
634 token
= tokenizer
.GetNextToken();
635 if ( !token
.ToLong(&l
) )
639 faceName
= tokenizer
.GetNextToken();
646 token
= tokenizer
.GetNextToken();
647 if ( !token
.ToLong(&l
) )
649 encoding
= (wxFontEncoding
)l
;
654 wxString
wxNativeFontInfo::ToString() const
658 s
.Printf(wxT("%d;%d;%d;%d;%d;%d;%s;%d"),
671 void wxNativeFontInfo::Init()
674 family
= wxFONTFAMILY_DEFAULT
;
675 style
= wxFONTSTYLE_NORMAL
;
676 weight
= wxFONTWEIGHT_NORMAL
;
679 encoding
= wxFONTENCODING_DEFAULT
;
682 int wxNativeFontInfo::GetPointSize() const
687 wxFontStyle
wxNativeFontInfo::GetStyle() const
692 wxFontWeight
wxNativeFontInfo::GetWeight() const
697 bool wxNativeFontInfo::GetUnderlined() const
702 wxString
wxNativeFontInfo::GetFaceName() const
707 wxFontFamily
wxNativeFontInfo::GetFamily() const
712 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
717 void wxNativeFontInfo::SetPointSize(int pointsize
)
719 pointSize
= pointsize
;
722 void wxNativeFontInfo::SetStyle(wxFontStyle style_
)
727 void wxNativeFontInfo::SetWeight(wxFontWeight weight_
)
732 void wxNativeFontInfo::SetUnderlined(bool underlined_
)
734 underlined
= underlined_
;
737 bool wxNativeFontInfo::SetFaceName(const wxString
& facename_
)
739 faceName
= facename_
;
743 void wxNativeFontInfo::SetFamily(wxFontFamily family_
)
748 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_
)
750 encoding
= encoding_
;
753 #endif // generic wxNativeFontInfo implementation
755 // conversion to/from user-readable string: this is used in the generic
756 // versions and under MSW as well because there is no standard font description
757 // format there anyhow (but there is a well-defined standard for X11 fonts used
758 // by wxGTK and wxMotif)
760 #if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) || defined(__WXOSX__)
762 wxString
wxNativeFontInfo::ToUserString() const
766 // first put the adjectives, if any - this is English-centric, of course,
767 // but what else can we do?
768 if ( GetUnderlined() )
770 desc
<< _("underlined");
773 switch ( GetWeight() )
776 wxFAIL_MSG( wxT("unknown font weight") );
779 case wxFONTWEIGHT_NORMAL
:
782 case wxFONTWEIGHT_LIGHT
:
786 case wxFONTWEIGHT_BOLD
:
791 switch ( GetStyle() )
794 wxFAIL_MSG( wxT("unknown font style") );
797 case wxFONTSTYLE_NORMAL
:
800 // we don't distinguish between the two for now anyhow...
801 case wxFONTSTYLE_ITALIC
:
802 case wxFONTSTYLE_SLANT
:
803 desc
<< _(" italic");
807 wxString face
= GetFaceName();
810 if (face
.Contains(' ') || face
.Contains(';') || face
.Contains(','))
812 face
.Replace("'", "");
813 // eventually remove quote characters: most systems do not
814 // allow them in a facename anyway so this usually does nothing
816 // make it possible for FromUserString() function to understand
817 // that the different words which compose this facename are
818 // not different adjectives or other data but rather all parts
820 desc
<< wxT(" '") << face
<< _("'");
823 desc
<< wxT(' ') << face
;
825 else // no face name specified
829 switch ( GetFamily() )
831 case wxFONTFAMILY_DECORATIVE
:
832 familyStr
= "decorative";
835 case wxFONTFAMILY_ROMAN
:
839 case wxFONTFAMILY_SCRIPT
:
840 familyStr
= "script";
843 case wxFONTFAMILY_SWISS
:
847 case wxFONTFAMILY_MODERN
:
848 familyStr
= "modern";
851 case wxFONTFAMILY_TELETYPE
:
852 familyStr
= "teletype";
855 case wxFONTFAMILY_DEFAULT
:
856 case wxFONTFAMILY_UNKNOWN
:
860 wxFAIL_MSG( "unknown font family" );
863 if ( !familyStr
.empty() )
864 desc
<< " '" << familyStr
<< " family'";
867 int size
= GetPointSize();
868 if ( size
!= wxNORMAL_FONT
->GetPointSize() )
870 desc
<< wxT(' ') << size
;
874 wxFontEncoding enc
= GetEncoding();
875 if ( enc
!= wxFONTENCODING_DEFAULT
&& enc
!= wxFONTENCODING_SYSTEM
)
877 desc
<< wxT(' ') << wxFontMapper::GetEncodingName(enc
);
879 #endif // wxUSE_FONTMAP
881 return desc
.Strip(wxString::both
).MakeLower();
884 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
886 // reset to the default state
889 // ToUserString() will quote the facename if it contains spaces, commas
890 // or semicolons: we must be able to understand that quoted text is
894 // parse a more or less free form string
895 wxStringTokenizer
tokenizer(toparse
, wxT(";, "), wxTOKEN_STRTOK
);
899 bool weightfound
= false, pointsizefound
= false;
901 bool encodingfound
= false;
903 bool insideQuotes
= false;
905 while ( tokenizer
.HasMoreTokens() )
907 wxString token
= tokenizer
.GetNextToken();
910 token
.Trim(true).Trim(false).MakeLower();
913 if (token
.StartsWith("'") ||
916 insideQuotes
= false;
918 // add this last token to the facename:
921 // normalize facename:
922 face
= face
.Trim(true).Trim(false);
923 face
.Replace("'", "");
930 if (token
.StartsWith("'"))
934 // look for the known tokens
937 // only the facename may be quoted:
941 if ( token
== wxT("underlined") || token
== _("underlined") )
945 else if ( token
== wxT("light") || token
== _("light") )
947 SetWeight(wxFONTWEIGHT_LIGHT
);
950 else if ( token
== wxT("bold") || token
== _("bold") )
952 SetWeight(wxFONTWEIGHT_BOLD
);
955 else if ( token
== wxT("italic") || token
== _("italic") )
957 SetStyle(wxFONTSTYLE_ITALIC
);
959 else if ( token
.ToULong(&size
) )
962 pointsizefound
= true;
967 // try to interpret this as an encoding
968 wxFontEncoding encoding
= wxFontMapper::Get()->CharsetToEncoding(token
, false);
969 if ( encoding
!= wxFONTENCODING_DEFAULT
&&
970 encoding
!= wxFONTENCODING_SYSTEM
) // returned when the recognition failed
972 SetEncoding(encoding
);
973 encodingfound
= true;
977 #endif // wxUSE_FONTMAP
979 // assume it is the face name
987 // skip the code which resets face below
992 #endif // wxUSE_FONTMAP
995 // if we had had the facename, we shouldn't continue appending tokens
996 // to it (i.e. "foo bold bar" shouldn't result in the facename "foo
1001 if ( face
.EndsWith(" family", &familyStr
) )
1003 // it's not a facename but rather a font family
1004 wxFontFamily family
;
1005 if ( familyStr
== "decorative" )
1006 family
= wxFONTFAMILY_DECORATIVE
;
1007 else if ( familyStr
== "roman" )
1008 family
= wxFONTFAMILY_ROMAN
;
1009 else if ( familyStr
== "script" )
1010 family
= wxFONTFAMILY_SCRIPT
;
1011 else if ( familyStr
== "swiss" )
1012 family
= wxFONTFAMILY_SWISS
;
1013 else if ( familyStr
== "modern" )
1014 family
= wxFONTFAMILY_MODERN
;
1015 else if ( familyStr
== "teletype" )
1016 family
= wxFONTFAMILY_TELETYPE
;
1022 // NB: the check on the facename is implemented in wxFontBase::SetFaceName
1023 // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely
1024 // call here wxFontEnumerator::IsValidFacename
1027 !wxFontEnumerator::IsValidFacename(face
) ||
1028 #endif // wxUSE_FONTENUM
1029 !SetFaceName(face
) )
1031 SetFaceName(wxNORMAL_FONT
->GetFaceName());
1038 // we might not have flushed it inside the loop
1039 if ( !face
.empty() )
1041 // NB: the check on the facename is implemented in wxFontBase::SetFaceName
1042 // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely
1043 // call here wxFontEnumerator::IsValidFacename
1046 !wxFontEnumerator::IsValidFacename(face
) ||
1047 #endif // wxUSE_FONTENUM
1048 !SetFaceName(face
) )
1050 SetFaceName(wxNORMAL_FONT
->GetFaceName());
1054 // set point size to default value if size was not given
1055 if ( !pointsizefound
)
1056 SetPointSize(wxNORMAL_FONT
->GetPointSize());
1058 // set font weight to default value if weight was not given
1060 SetWeight(wxFONTWEIGHT_NORMAL
);
1063 // set font encoding to default value if encoding was not given
1064 if ( !encodingfound
)
1065 SetEncoding(wxFONTENCODING_SYSTEM
);
1066 #endif // wxUSE_FONTMAP
1071 #endif // generic or wxMSW or wxOS2
1074 // wxFont <-> wxString utilities, used by wxConfig
1075 wxString
wxToString(const wxFontBase
& font
)
1077 return font
.IsOk() ? font
.GetNativeFontInfoDesc()
1081 bool wxFromString(const wxString
& str
, wxFontBase
*font
)
1083 wxCHECK_MSG( font
, false, wxT("NULL output parameter") );
1091 return font
->SetNativeFontInfo(str
);