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"
33 #include "wx/dcscreen.h"
35 #include "wx/gdicmn.h"
38 #if defined(__WXMSW__)
39 #include "wx/msw/private.h" // includes windows.h for LOGFONT
40 #include "wx/msw/winundef.h"
43 #include "wx/fontutil.h" // for wxNativeFontInfo
44 #include "wx/fontmap.h"
45 #include "wx/fontenum.h"
47 #include "wx/tokenzr.h"
49 // debugger helper: this function can be called from a debugger to show what
51 extern const char *wxDumpFont(const wxFont
*font
)
55 const wxFontWeight weight
= font
->GetWeight();
58 s
.Printf(wxS("%s-%s-%s-%d-%d"),
60 weight
== wxFONTWEIGHT_NORMAL
62 : weight
== wxFONTWEIGHT_BOLD
65 font
->GetStyle() == wxFONTSTYLE_NORMAL
71 wxStrlcpy(buf
, s
.mb_str(), WXSIZEOF(buf
));
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 wxBEGIN_ENUM( wxFontFamily
)
80 wxENUM_MEMBER( wxFONTFAMILY_DEFAULT
)
81 wxENUM_MEMBER( wxFONTFAMILY_DECORATIVE
)
82 wxENUM_MEMBER( wxFONTFAMILY_ROMAN
)
83 wxENUM_MEMBER( wxFONTFAMILY_SCRIPT
)
84 wxENUM_MEMBER( wxFONTFAMILY_SWISS
)
85 wxENUM_MEMBER( wxFONTFAMILY_MODERN
)
86 wxENUM_MEMBER( wxFONTFAMILY_TELETYPE
)
87 wxEND_ENUM( wxFontFamily
)
89 wxBEGIN_ENUM( wxFontStyle
)
90 wxENUM_MEMBER( wxFONTSTYLE_NORMAL
)
91 wxENUM_MEMBER( wxFONTSTYLE_ITALIC
)
92 wxENUM_MEMBER( wxFONTSTYLE_SLANT
)
93 wxEND_ENUM( wxFontStyle
)
95 wxBEGIN_ENUM( wxFontWeight
)
96 wxENUM_MEMBER( wxFONTWEIGHT_NORMAL
)
97 wxENUM_MEMBER( wxFONTWEIGHT_LIGHT
)
98 wxENUM_MEMBER( wxFONTWEIGHT_BOLD
)
99 wxEND_ENUM( wxFontWeight
)
101 wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
, "wx/font.h")
103 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxFont>)
105 wxBEGIN_PROPERTIES_TABLE(wxFont
)
106 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12, 0 /*flags*/, \
107 wxT("Helpstring"), wxT("group"))
108 wxPROPERTY( Family
, wxFontFamily
, SetFamily
, GetFamily
, (wxFontFamily
)wxDEFAULT
, \
109 0 /*flags*/, wxT("Helpstring"), wxT("group")) // wxFontFamily
110 wxPROPERTY( Style
, wxFontStyle
, SetStyle
, GetStyle
, (wxFontStyle
)wxNORMAL
, 0 /*flags*/, \
111 wxT("Helpstring"), wxT("group")) // wxFontStyle
112 wxPROPERTY( Weight
, wxFontWeight
, SetWeight
, GetWeight
, (wxFontWeight
)wxNORMAL
, 0 /*flags*/, \
113 wxT("Helpstring"), wxT("group")) // wxFontWeight
114 wxPROPERTY( Underlined
, bool, SetUnderlined
, GetUnderlined
, false, 0 /*flags*/, \
115 wxT("Helpstring"), wxT("group"))
116 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, wxEMPTY_PARAMETER_VALUE
, \
117 0 /*flags*/, wxT("Helpstring"), wxT("group"))
118 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, \
119 wxFONTENCODING_DEFAULT
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
120 wxEND_PROPERTIES_TABLE()
122 wxCONSTRUCTOR_6( wxFont
, int, Size
, wxFontFamily
, Family
, wxFontStyle
, Style
, wxFontWeight
, Weight
, \
123 bool, Underlined
, wxString
, Face
)
125 wxEMPTY_HANDLERS_TABLE(wxFont
)
127 // ============================================================================
129 // ============================================================================
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 wxFontEncoding wxFontBase
::ms_encodingDefault
= wxFONTENCODING_SYSTEM
;
138 void wxFontBase
::SetDefaultEncoding(wxFontEncoding encoding
)
140 // GetDefaultEncoding() should return something != wxFONTENCODING_DEFAULT
141 // and, besides, using this value here doesn't make any sense
142 wxCHECK_RET( encoding
!= wxFONTENCODING_DEFAULT
,
143 wxT("can't set default encoding to wxFONTENCODING_DEFAULT") );
145 ms_encodingDefault
= encoding
;
148 wxFontBase
::~wxFontBase()
150 // this destructor is required for Darwin
154 wxFont
*wxFontBase
::New(int size
,
159 const wxString
& face
,
160 wxFontEncoding encoding
)
162 return new wxFont(size
, family
, style
, weight
, underlined
, face
, encoding
);
166 wxFont
*wxFontBase
::New(const wxSize
& pixelSize
,
171 const wxString
& face
,
172 wxFontEncoding encoding
)
174 return new wxFont(pixelSize
, family
, style
, weight
, underlined
,
179 wxFont
*wxFontBase
::New(int pointSize
,
182 const wxString
& face
,
183 wxFontEncoding encoding
)
185 return New(pointSize
, family
,
186 GetStyleFromFlags(flags
),
187 GetWeightFromFlags(flags
),
188 GetUnderlinedFromFlags(flags
),
193 wxFont
*wxFontBase
::New(const wxSize
& pixelSize
,
196 const wxString
& face
,
197 wxFontEncoding encoding
)
199 return New(pixelSize
, family
,
200 GetStyleFromFlags(flags
),
201 GetWeightFromFlags(flags
),
202 GetUnderlinedFromFlags(flags
),
207 wxFont
*wxFontBase
::New(const wxNativeFontInfo
& info
)
209 return new wxFont(info
);
213 wxFont
*wxFontBase
::New(const wxString
& strNativeFontDesc
)
215 wxNativeFontInfo fontInfo
;
216 if ( !fontInfo
.FromString(strNativeFontDesc
) )
217 return new wxFont(*wxNORMAL_FONT
);
219 return New(fontInfo
);
222 bool wxFontBase
::IsFixedWidth() const
224 return GetFamily() == wxFONTFAMILY_TELETYPE
;
227 wxSize wxFontBase
::GetPixelSize() const
230 dc
.SetFont(*(wxFont
*)this);
231 return wxSize(dc
.GetCharWidth(), dc
.GetCharHeight());
234 bool wxFontBase
::IsUsingSizeInPixels() const
239 void wxFontBase
::SetPixelSize( const wxSize
& pixelSize
)
241 wxCHECK_RET( pixelSize
.GetWidth() >= 0 && pixelSize
.GetHeight() > 0,
242 "Negative values for the pixel size or zero pixel height are not allowed" );
246 // NOTE: this algorithm for adjusting the font size is used by all
247 // implementations of wxFont except under wxMSW and wxGTK where
248 // native support to font creation using pixel-size is provided.
253 bool initialGoodFound
= false;
254 bool initialBadFound
= false;
256 // NB: this assignment was separated from the variable definition
257 // in order to fix a gcc v3.3.3 compiler crash
258 int currentSize
= GetPointSize();
259 while (currentSize
> 0)
261 dc
.SetFont(*static_cast<wxFont
*>(this));
263 // if currentSize (in points) results in a font that is smaller
264 // than required by pixelSize it is considered a good size
265 // NOTE: the pixel size width may be zero
266 if (dc
.GetCharHeight() <= pixelSize
.GetHeight() &&
267 (pixelSize
.GetWidth() == 0 ||
268 dc
.GetCharWidth() <= pixelSize
.GetWidth()))
270 largestGood
= currentSize
;
271 initialGoodFound
= true;
275 smallestBad
= currentSize
;
276 initialBadFound
= true;
278 if (!initialGoodFound
)
282 else if (!initialBadFound
)
288 int distance
= smallestBad
- largestGood
;
292 currentSize
= largestGood
+ distance
/ 2;
295 SetPointSize(currentSize
);
298 if (currentSize
!= largestGood
)
299 SetPointSize(largestGood
);
302 void wxFontBase
::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
304 #ifdef wxNO_NATIVE_FONTINFO
305 SetPointSize(info
.pointSize
);
306 SetFamily(info
.family
);
307 SetStyle(info
.style
);
308 SetWeight(info
.weight
);
309 SetUnderlined(info
.underlined
);
310 SetFaceName(info
.faceName
);
311 SetEncoding(info
.encoding
);
317 wxString wxFontBase
::GetNativeFontInfoDesc() const
319 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
322 const wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
325 fontDesc
= fontInfo
->ToString();
326 wxASSERT_MSG(!fontDesc
.empty(), wxT("This should be a non-empty string!"));
330 wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!"));
336 wxString wxFontBase
::GetNativeFontInfoUserDesc() const
338 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
341 const wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
344 fontDesc
= fontInfo
->ToUserString();
345 wxASSERT_MSG(!fontDesc
.empty(), wxT("This should be a non-empty string!"));
349 wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!"));
355 bool wxFontBase
::SetNativeFontInfo(const wxString
& info
)
357 wxNativeFontInfo fontInfo
;
358 if ( !info
.empty() && fontInfo
.FromString(info
) )
360 SetNativeFontInfo(fontInfo
);
367 bool wxFontBase
::SetNativeFontInfoUserDesc(const wxString
& info
)
369 wxNativeFontInfo fontInfo
;
370 if ( !info
.empty() && fontInfo
.FromUserString(info
) )
372 SetNativeFontInfo(fontInfo
);
379 bool wxFontBase
::operator==(const wxFont
& font
) const
381 // either it is the same font, i.e. they share the same common data or they
382 // have different ref datas but still describe the same font
383 return IsSameAs(font
) ||
385 IsOk() == font
.IsOk() &&
386 GetPointSize() == font
.GetPointSize() &&
387 // in wxGTK1 GetPixelSize() calls GetInternalFont() which uses
388 // operator==() resulting in infinite recursion so we can't use it
390 #if !defined(__WXGTK__) || defined(__WXGTK20__)
391 GetPixelSize() == font
.GetPixelSize() &&
393 GetFamily() == font
.GetFamily() &&
394 GetStyle() == font
.GetStyle() &&
395 GetWeight() == font
.GetWeight() &&
396 GetUnderlined() == font
.GetUnderlined() &&
397 GetFaceName().IsSameAs(font
.GetFaceName(), false) &&
398 GetEncoding() == font
.GetEncoding()
402 wxFontFamily wxFontBase
::GetFamily() const
404 wxCHECK_MSG( IsOk(), wxFONTFAMILY_UNKNOWN
, wxS("invalid font") );
406 // Don't return wxFONTFAMILY_UNKNOWN from here because it prevents the code
407 // like wxFont(size, wxNORMAL_FONT->GetFamily(), ...) from working (see
408 // #12330). This is really just a hack but it allows to keep compatibility
409 // and doesn't really have any bad drawbacks so do this until someone comes
410 // up with a better idea.
411 const wxFontFamily family
= DoGetFamily();
413 return family
== wxFONTFAMILY_UNKNOWN ? wxFONTFAMILY_DEFAULT
: family
;
416 wxString wxFontBase
::GetFamilyString() const
418 wxCHECK_MSG( IsOk(), "wxFONTFAMILY_DEFAULT", "invalid font" );
420 switch ( GetFamily() )
422 case wxFONTFAMILY_DECORATIVE
: return "wxFONTFAMILY_DECORATIVE";
423 case wxFONTFAMILY_ROMAN
: return "wxFONTFAMILY_ROMAN";
424 case wxFONTFAMILY_SCRIPT
: return "wxFONTFAMILY_SCRIPT";
425 case wxFONTFAMILY_SWISS
: return "wxFONTFAMILY_SWISS";
426 case wxFONTFAMILY_MODERN
: return "wxFONTFAMILY_MODERN";
427 case wxFONTFAMILY_TELETYPE
: return "wxFONTFAMILY_TELETYPE";
428 case wxFONTFAMILY_UNKNOWN
: return "wxFONTFAMILY_UNKNOWN";
429 default: return "wxFONTFAMILY_DEFAULT";
433 wxString wxFontBase
::GetStyleString() const
435 wxCHECK_MSG( IsOk(), "wxFONTSTYLE_DEFAULT", "invalid font" );
437 switch ( GetStyle() )
439 case wxFONTSTYLE_NORMAL
: return "wxFONTSTYLE_NORMAL";
440 case wxFONTSTYLE_SLANT
: return "wxFONTSTYLE_SLANT";
441 case wxFONTSTYLE_ITALIC
: return "wxFONTSTYLE_ITALIC";
442 default: return "wxFONTSTYLE_DEFAULT";
446 wxString wxFontBase
::GetWeightString() const
448 wxCHECK_MSG( IsOk(), "wxFONTWEIGHT_DEFAULT", "invalid font" );
450 switch ( GetWeight() )
452 case wxFONTWEIGHT_NORMAL
: return "wxFONTWEIGHT_NORMAL";
453 case wxFONTWEIGHT_BOLD
: return "wxFONTWEIGHT_BOLD";
454 case wxFONTWEIGHT_LIGHT
: return "wxFONTWEIGHT_LIGHT";
455 default: return "wxFONTWEIGHT_DEFAULT";
459 bool wxFontBase
::SetFaceName(const wxString
& facename
)
462 if (!wxFontEnumerator
::IsValidFacename(facename
))
464 UnRef(); // make IsOk() return false
467 #else // !wxUSE_FONTENUM
468 wxUnusedVar(facename
);
469 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
474 void wxFontBase
::SetSymbolicSize(wxFontSymbolicSize size
)
476 SetSymbolicSizeRelativeTo(size
, wxNORMAL_FONT
->GetPointSize());
480 int wxFontBase
::AdjustToSymbolicSize(wxFontSymbolicSize size
, int base
)
482 // Using a fixed factor (1.2, from CSS2) is a bad idea as explained at
483 // http://www.w3.org/TR/CSS21/fonts.html#font-size-props so use the values
484 // from http://style.cleverchimp.com/font_size_intervals/altintervals.html
486 static const float factors
[] = { 0.60f
, 0.75f
, 0.89f
, 1.f
, 1.2f
, 1.5f
, 2.f
};
488 wxCOMPILE_TIME_ASSERT
490 WXSIZEOF(factors
) == wxFONTSIZE_XX_LARGE
- wxFONTSIZE_XX_SMALL
+ 1,
491 WrongFontSizeFactorsSize
494 return wxRound(factors
[size
- wxFONTSIZE_XX_SMALL
]*base
);
497 wxFont
& wxFont
::MakeBold()
499 SetWeight(wxFONTWEIGHT_BOLD
);
503 wxFont wxFont
::Bold() const
510 wxFont
& wxFont
::MakeItalic()
512 SetStyle(wxFONTSTYLE_ITALIC
);
516 wxFont wxFont
::Italic() const
523 wxFont
& wxFont
::MakeUnderlined()
529 wxFont wxFont
::Underlined() const
532 font
.MakeUnderlined();
536 wxFont
& wxFont
::Scale(float x
)
538 SetPointSize(int(x
*GetPointSize() + 0.5));
542 wxFont wxFont
::Scaled(float x
) const
549 // ----------------------------------------------------------------------------
551 // ----------------------------------------------------------------------------
553 // Up to now, there are no native implementations of this function:
554 void wxNativeFontInfo
::SetFaceName(const wxArrayString
& facenames
)
557 for (size_t i
=0; i
< facenames
.GetCount(); i
++)
559 if (wxFontEnumerator
::IsValidFacename(facenames
[i
]))
561 SetFaceName(facenames
[i
]);
566 // set the first valid facename we can find on this system
567 wxString validfacename
= wxFontEnumerator
::GetFacenames().Item(0);
568 wxLogTrace(wxT("font"), wxT("Falling back to '%s'"), validfacename
.c_str());
569 SetFaceName(validfacename
);
570 #else // !wxUSE_FONTENUM
571 SetFaceName(facenames
[0]);
572 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
576 #ifdef wxNO_NATIVE_FONTINFO
578 // These are the generic forms of FromString()/ToString.
580 // convert to/from the string representation: format is
581 // version;pointsize;family;style;weight;underlined;facename;encoding
583 bool wxNativeFontInfo
::FromString(const wxString
& s
)
587 wxStringTokenizer
tokenizer(s
, wxT(";"));
589 wxString token
= tokenizer
.GetNextToken();
591 // Ignore the version for now
594 token
= tokenizer
.GetNextToken();
595 if ( !token
.ToLong(&l
) )
599 token
= tokenizer
.GetNextToken();
600 if ( !token
.ToLong(&l
) )
602 family
= (wxFontFamily
)l
;
604 token
= tokenizer
.GetNextToken();
605 if ( !token
.ToLong(&l
) )
607 style
= (wxFontStyle
)l
;
609 token
= tokenizer
.GetNextToken();
610 if ( !token
.ToLong(&l
) )
612 weight
= (wxFontWeight
)l
;
614 token
= tokenizer
.GetNextToken();
615 if ( !token
.ToLong(&l
) )
619 faceName
= tokenizer
.GetNextToken();
626 token
= tokenizer
.GetNextToken();
627 if ( !token
.ToLong(&l
) )
629 encoding
= (wxFontEncoding
)l
;
634 wxString wxNativeFontInfo
::ToString() const
638 s
.Printf(wxT("%d;%d;%d;%d;%d;%d;%s;%d"),
651 void wxNativeFontInfo
::Init()
654 family
= wxFONTFAMILY_DEFAULT
;
655 style
= wxFONTSTYLE_NORMAL
;
656 weight
= wxFONTWEIGHT_NORMAL
;
659 encoding
= wxFONTENCODING_DEFAULT
;
662 int wxNativeFontInfo
::GetPointSize() const
667 wxFontStyle wxNativeFontInfo
::GetStyle() const
672 wxFontWeight wxNativeFontInfo
::GetWeight() const
677 bool wxNativeFontInfo
::GetUnderlined() const
682 wxString wxNativeFontInfo
::GetFaceName() const
687 wxFontFamily wxNativeFontInfo
::GetFamily() const
692 wxFontEncoding wxNativeFontInfo
::GetEncoding() const
697 void wxNativeFontInfo
::SetPointSize(int pointsize
)
699 pointSize
= pointsize
;
702 void wxNativeFontInfo
::SetStyle(wxFontStyle style_
)
707 void wxNativeFontInfo
::SetWeight(wxFontWeight weight_
)
712 void wxNativeFontInfo
::SetUnderlined(bool underlined_
)
714 underlined
= underlined_
;
717 bool wxNativeFontInfo
::SetFaceName(const wxString
& facename_
)
719 faceName
= facename_
;
723 void wxNativeFontInfo
::SetFamily(wxFontFamily family_
)
728 void wxNativeFontInfo
::SetEncoding(wxFontEncoding encoding_
)
730 encoding
= encoding_
;
733 #endif // generic wxNativeFontInfo implementation
735 // conversion to/from user-readable string: this is used in the generic
736 // versions and under MSW as well because there is no standard font description
737 // format there anyhow (but there is a well-defined standard for X11 fonts used
738 // by wxGTK and wxMotif)
740 #if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) || defined(__WXOSX__)
742 wxString wxNativeFontInfo
::ToUserString() const
746 // first put the adjectives, if any - this is English-centric, of course,
747 // but what else can we do?
748 if ( GetUnderlined() )
750 desc
<< _("underlined");
753 switch ( GetWeight() )
756 wxFAIL_MSG( wxT("unknown font weight") );
759 case wxFONTWEIGHT_NORMAL
:
762 case wxFONTWEIGHT_LIGHT
:
766 case wxFONTWEIGHT_BOLD
:
771 switch ( GetStyle() )
774 wxFAIL_MSG( wxT("unknown font style") );
777 case wxFONTSTYLE_NORMAL
:
780 // we don't distinguish between the two for now anyhow...
781 case wxFONTSTYLE_ITALIC
:
782 case wxFONTSTYLE_SLANT
:
783 desc
<< _(" italic");
787 wxString face
= GetFaceName();
790 if (face
.Contains(' ') || face
.Contains(';') || face
.Contains(','))
792 face
.Replace("'", "");
793 // eventually remove quote characters: most systems do not
794 // allow them in a facename anyway so this usually does nothing
796 // make it possible for FromUserString() function to understand
797 // that the different words which compose this facename are
798 // not different adjectives or other data but rather all parts
800 desc
<< wxT(" '") << face
<< _("'");
803 desc
<< wxT(' ') << face
;
805 else // no face name specified
809 switch ( GetFamily() )
811 case wxFONTFAMILY_DECORATIVE
:
812 familyStr
= "decorative";
815 case wxFONTFAMILY_ROMAN
:
819 case wxFONTFAMILY_SCRIPT
:
820 familyStr
= "script";
823 case wxFONTFAMILY_SWISS
:
827 case wxFONTFAMILY_MODERN
:
828 familyStr
= "modern";
831 case wxFONTFAMILY_TELETYPE
:
832 familyStr
= "teletype";
835 case wxFONTFAMILY_DEFAULT
:
836 case wxFONTFAMILY_UNKNOWN
:
840 wxFAIL_MSG( "unknown font family" );
843 if ( !familyStr
.empty() )
844 desc
<< " '" << familyStr
<< " family'";
847 int size
= GetPointSize();
848 if ( size
!= wxNORMAL_FONT
->GetPointSize() )
850 desc
<< wxT(' ') << size
;
854 wxFontEncoding enc
= GetEncoding();
855 if ( enc
!= wxFONTENCODING_DEFAULT
&& enc
!= wxFONTENCODING_SYSTEM
)
857 desc
<< wxT(' ') << wxFontMapper
::GetEncodingName(enc
);
859 #endif // wxUSE_FONTMAP
861 return desc
.Strip(wxString
::both
).MakeLower();
864 bool wxNativeFontInfo
::FromUserString(const wxString
& s
)
866 // reset to the default state
869 // ToUserString() will quote the facename if it contains spaces, commas
870 // or semicolons: we must be able to understand that quoted text is
874 // parse a more or less free form string
875 wxStringTokenizer
tokenizer(toparse
, wxT(";, "), wxTOKEN_STRTOK
);
879 bool weightfound
= false, pointsizefound
= false;
881 bool encodingfound
= false;
883 bool insideQuotes
= false;
885 while ( tokenizer
.HasMoreTokens() )
887 wxString token
= tokenizer
.GetNextToken();
890 token
.Trim(true).Trim(false).MakeLower();
893 if (token
.StartsWith("'") ||
896 insideQuotes
= false;
898 // add this last token to the facename:
901 // normalize facename:
902 face
= face
.Trim(true).Trim(false);
903 face
.Replace("'", "");
910 if (token
.StartsWith("'"))
914 // look for the known tokens
917 // only the facename may be quoted:
921 if ( token
== wxT("underlined") || token
== _("underlined") )
925 else if ( token
== wxT("light") || token
== _("light") )
927 SetWeight(wxFONTWEIGHT_LIGHT
);
930 else if ( token
== wxT("bold") || token
== _("bold") )
932 SetWeight(wxFONTWEIGHT_BOLD
);
935 else if ( token
== wxT("italic") || token
== _("italic") )
937 SetStyle(wxFONTSTYLE_ITALIC
);
939 else if ( token
.ToULong(&size
) )
942 pointsizefound
= true;
947 // try to interpret this as an encoding
948 wxFontEncoding encoding
= wxFontMapper
::Get()->CharsetToEncoding(token
, false);
949 if ( encoding
!= wxFONTENCODING_DEFAULT
&&
950 encoding
!= wxFONTENCODING_SYSTEM
) // returned when the recognition failed
952 SetEncoding(encoding
);
953 encodingfound
= true;
957 #endif // wxUSE_FONTMAP
959 // assume it is the face name
967 // skip the code which resets face below
972 #endif // wxUSE_FONTMAP
975 // if we had had the facename, we shouldn't continue appending tokens
976 // to it (i.e. "foo bold bar" shouldn't result in the facename "foo
981 if ( face
.EndsWith(" family", &familyStr
) )
983 // it's not a facename but rather a font family
985 if ( familyStr
== "decorative" )
986 family
= wxFONTFAMILY_DECORATIVE
;
987 else if ( familyStr
== "roman" )
988 family
= wxFONTFAMILY_ROMAN
;
989 else if ( familyStr
== "script" )
990 family
= wxFONTFAMILY_SCRIPT
;
991 else if ( familyStr
== "swiss" )
992 family
= wxFONTFAMILY_SWISS
;
993 else if ( familyStr
== "modern" )
994 family
= wxFONTFAMILY_MODERN
;
995 else if ( familyStr
== "teletype" )
996 family
= wxFONTFAMILY_TELETYPE
;
1002 // NB: the check on the facename is implemented in wxFontBase::SetFaceName
1003 // and not in wxNativeFontInfo::SetFaceName thus we need to explicitly
1004 // call here wxFontEnumerator::IsValidFacename
1007 !wxFontEnumerator
::IsValidFacename(face
) ||
1008 #endif // wxUSE_FONTENUM
1009 !SetFaceName(face
) )
1011 SetFaceName(wxNORMAL_FONT
->GetFaceName());
1018 // we might not have flushed it inside the loop
1019 if ( !face
.empty() )
1021 // NB: the check on the facename is implemented in wxFontBase::SetFaceName
1022 // and not in wxNativeFontInfo::SetFaceName thus we need to explicitly
1023 // call here wxFontEnumerator::IsValidFacename
1026 !wxFontEnumerator
::IsValidFacename(face
) ||
1027 #endif // wxUSE_FONTENUM
1028 !SetFaceName(face
) )
1030 SetFaceName(wxNORMAL_FONT
->GetFaceName());
1034 // set point size to default value if size was not given
1035 if ( !pointsizefound
)
1036 SetPointSize(wxNORMAL_FONT
->GetPointSize());
1038 // set font weight to default value if weight was not given
1040 SetWeight(wxFONTWEIGHT_NORMAL
);
1043 // set font encoding to default value if encoding was not given
1044 if ( !encodingfound
)
1045 SetEncoding(wxFONTENCODING_SYSTEM
);
1046 #endif // wxUSE_FONTMAP
1051 #endif // generic or wxMSW or wxOS2
1054 // wxFont <-> wxString utilities, used by wxConfig
1055 wxString
wxToString(const wxFontBase
& font
)
1057 return font
.IsOk() ? font
.GetNativeFontInfoDesc()
1061 bool wxFromString(const wxString
& str
, wxFontBase
*font
)
1063 wxCHECK_MSG( font
, false, wxT("NULL output parameter") );
1071 return font
->SetNativeFontInfo(str
);