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( wxDEFAULT
)
80 wxENUM_MEMBER( wxDECORATIVE
)
81 wxENUM_MEMBER( wxROMAN
)
82 wxENUM_MEMBER( wxSCRIPT
)
83 wxENUM_MEMBER( wxSWISS
)
84 wxENUM_MEMBER( wxMODERN
)
85 wxENUM_MEMBER( wxTELETYPE
)
86 wxEND_ENUM( wxFontFamily
)
88 wxBEGIN_ENUM( wxFontStyle
)
89 wxENUM_MEMBER( wxNORMAL
)
90 wxENUM_MEMBER( wxITALIC
)
91 wxENUM_MEMBER( wxSLANT
)
92 wxEND_ENUM( wxFontStyle
)
94 wxBEGIN_ENUM( wxFontWeight
)
95 wxENUM_MEMBER( wxNORMAL
)
96 wxENUM_MEMBER( wxLIGHT
)
97 wxENUM_MEMBER( wxBOLD
)
98 wxEND_ENUM( wxFontWeight
)
100 wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
, "wx/font.h")
102 wxBEGIN_PROPERTIES_TABLE(wxFont
)
103 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12, 0 /*flags*/, \
104 wxT("Helpstring"), wxT("group"))
105 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, \
106 0 /*flags*/, wxT("Helpstring"), wxT("group")) // wxFontFamily
107 wxPROPERTY( Style
, int, SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/, \
108 wxT("Helpstring"), wxT("group")) // wxFontStyle
109 wxPROPERTY( Weight
, int, SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/, \
110 wxT("Helpstring"), wxT("group")) // wxFontWeight
111 wxPROPERTY( Underlined
, bool, SetUnderlined
, GetUnderlined
, false, 0 /*flags*/, \
112 wxT("Helpstring"), wxT("group"))
113 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, wxEMPTY_PARAMETER_VALUE
, \
114 0 /*flags*/, wxT("Helpstring"), wxT("group"))
115 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, \
116 wxFONTENCODING_DEFAULT
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
117 wxEND_PROPERTIES_TABLE()
119 wxCONSTRUCTOR_6( wxFont
, int, Size
, int, Family
, int, Style
, int, Weight
, \
120 bool, Underlined
, wxString
, Face
)
122 wxEMPTY_HANDLERS_TABLE(wxFont
)
124 // ============================================================================
126 // ============================================================================
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 static inline int flags2Style(int flags
)
134 return flags
& wxFONTFLAG_ITALIC
136 : flags
& wxFONTFLAG_SLANT
138 : wxFONTSTYLE_NORMAL
;
141 static inline int flags2Weight(int flags
)
143 return flags
& wxFONTFLAG_LIGHT
145 : flags
& wxFONTFLAG_BOLD
147 : wxFONTWEIGHT_NORMAL
;
150 static inline bool flags2Underlined(int flags
)
152 return (flags
& wxFONTFLAG_UNDERLINED
) != 0;
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 wxFontEncoding
wxFontBase::ms_encodingDefault
= wxFONTENCODING_SYSTEM
;
162 void wxFontBase::SetDefaultEncoding(wxFontEncoding encoding
)
164 // GetDefaultEncoding() should return something != wxFONTENCODING_DEFAULT
165 // and, besides, using this value here doesn't make any sense
166 wxCHECK_RET( encoding
!= wxFONTENCODING_DEFAULT
,
167 wxT("can't set default encoding to wxFONTENCODING_DEFAULT") );
169 ms_encodingDefault
= encoding
;
172 wxFontBase::~wxFontBase()
174 // this destructor is required for Darwin
178 wxFont
*wxFontBase::New(int size
,
183 const wxString
& face
,
184 wxFontEncoding encoding
)
186 return new wxFont(size
, family
, style
, weight
, underlined
, face
, encoding
);
190 wxFont
*wxFontBase::New(const wxSize
& pixelSize
,
195 const wxString
& face
,
196 wxFontEncoding encoding
)
198 return new wxFont(pixelSize
, family
, style
, weight
, underlined
,
203 wxFont
*wxFontBase::New(int pointSize
,
206 const wxString
& face
,
207 wxFontEncoding encoding
)
209 return New(pointSize
, family
, flags2Style(flags
), flags2Weight(flags
),
210 flags2Underlined(flags
), face
, encoding
);
214 wxFont
*wxFontBase::New(const wxSize
& pixelSize
,
217 const wxString
& face
,
218 wxFontEncoding encoding
)
220 return New(pixelSize
, family
, flags2Style(flags
), flags2Weight(flags
),
221 flags2Underlined(flags
), face
, encoding
);
225 wxFont
*wxFontBase::New(const wxNativeFontInfo
& info
)
227 return new wxFont(info
);
231 wxFont
*wxFontBase::New(const wxString
& strNativeFontDesc
)
233 wxNativeFontInfo fontInfo
;
234 if ( !fontInfo
.FromString(strNativeFontDesc
) )
235 return new wxFont(*wxNORMAL_FONT
);
237 return New(fontInfo
);
240 bool wxFontBase::IsFixedWidth() const
242 return GetFamily() == wxFONTFAMILY_TELETYPE
;
245 wxSize
wxFontBase::GetPixelSize() const
248 dc
.SetFont(*(wxFont
*)this);
249 return wxSize(dc
.GetCharWidth(), dc
.GetCharHeight());
252 bool wxFontBase::IsUsingSizeInPixels() const
257 void wxFontBase::SetPixelSize( const wxSize
& pixelSize
)
259 wxCHECK_RET( pixelSize
.GetWidth() >= 0 && pixelSize
.GetHeight() > 0,
260 "Negative values for the pixel size or zero pixel height are not allowed" );
264 // NOTE: this algorithm for adjusting the font size is used by all
265 // implementations of wxFont except under wxMSW and wxGTK where
266 // native support to font creation using pixel-size is provided.
271 bool initialGoodFound
= false;
272 bool initialBadFound
= false;
274 // NB: this assignment was separated from the variable definition
275 // in order to fix a gcc v3.3.3 compiler crash
276 int currentSize
= GetPointSize();
277 while (currentSize
> 0)
279 dc
.SetFont(*static_cast<wxFont
*>(this));
281 // if currentSize (in points) results in a font that is smaller
282 // than required by pixelSize it is considered a good size
283 // NOTE: the pixel size width may be zero
284 if (dc
.GetCharHeight() <= pixelSize
.GetHeight() &&
285 (pixelSize
.GetWidth() == 0 ||
286 dc
.GetCharWidth() <= pixelSize
.GetWidth()))
288 largestGood
= currentSize
;
289 initialGoodFound
= true;
293 smallestBad
= currentSize
;
294 initialBadFound
= true;
296 if (!initialGoodFound
)
300 else if (!initialBadFound
)
306 int distance
= smallestBad
- largestGood
;
310 currentSize
= largestGood
+ distance
/ 2;
313 SetPointSize(currentSize
);
316 if (currentSize
!= largestGood
)
317 SetPointSize(largestGood
);
320 void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
322 #ifdef wxNO_NATIVE_FONTINFO
323 SetPointSize(info
.pointSize
);
324 SetFamily(info
.family
);
325 SetStyle(info
.style
);
326 SetWeight(info
.weight
);
327 SetUnderlined(info
.underlined
);
328 SetFaceName(info
.faceName
);
329 SetEncoding(info
.encoding
);
335 wxString
wxFontBase::GetNativeFontInfoDesc() const
337 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
340 const wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
343 fontDesc
= fontInfo
->ToString();
344 wxASSERT_MSG(!fontDesc
.empty(), wxT("This should be a non-empty string!"));
348 wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!"));
354 wxString
wxFontBase::GetNativeFontInfoUserDesc() const
356 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
359 const wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
362 fontDesc
= fontInfo
->ToUserString();
363 wxASSERT_MSG(!fontDesc
.empty(), wxT("This should be a non-empty string!"));
367 wxFAIL_MSG(wxT("Derived class should have created the wxNativeFontInfo!"));
373 bool wxFontBase::SetNativeFontInfo(const wxString
& info
)
375 wxNativeFontInfo fontInfo
;
376 if ( !info
.empty() && fontInfo
.FromString(info
) )
378 SetNativeFontInfo(fontInfo
);
385 bool wxFontBase::SetNativeFontInfoUserDesc(const wxString
& info
)
387 wxNativeFontInfo fontInfo
;
388 if ( !info
.empty() && fontInfo
.FromUserString(info
) )
390 SetNativeFontInfo(fontInfo
);
397 bool wxFontBase::operator==(const wxFont
& font
) const
399 // either it is the same font, i.e. they share the same common data or they
400 // have different ref datas but still describe the same font
401 return IsSameAs(font
) ||
403 IsOk() == font
.IsOk() &&
404 GetPointSize() == font
.GetPointSize() &&
405 // in wxGTK1 GetPixelSize() calls GetInternalFont() which uses
406 // operator==() resulting in infinite recursion so we can't use it
408 #if !defined(__WXGTK__) || defined(__WXGTK20__)
409 GetPixelSize() == font
.GetPixelSize() &&
411 GetFamily() == font
.GetFamily() &&
412 GetStyle() == font
.GetStyle() &&
413 GetWeight() == font
.GetWeight() &&
414 GetUnderlined() == font
.GetUnderlined() &&
415 GetFaceName().IsSameAs(font
.GetFaceName(), false) &&
416 GetEncoding() == font
.GetEncoding()
420 wxFontFamily
wxFontBase::GetFamily() const
422 wxCHECK_MSG( IsOk(), wxFONTFAMILY_UNKNOWN
, wxS("invalid font") );
424 // Don't return wxFONTFAMILY_UNKNOWN from here because it prevents the code
425 // like wxFont(size, wxNORMAL_FONT->GetFamily(), ...) from working (see
426 // #12330). This is really just a hack but it allows to keep compatibility
427 // and doesn't really have any bad drawbacks so do this until someone comes
428 // up with a better idea.
429 const wxFontFamily family
= DoGetFamily();
431 return family
== wxFONTFAMILY_UNKNOWN
? wxFONTFAMILY_DEFAULT
: family
;
434 wxString
wxFontBase::GetFamilyString() const
436 wxCHECK_MSG( IsOk(), "wxFONTFAMILY_DEFAULT", "invalid font" );
438 switch ( GetFamily() )
440 case wxFONTFAMILY_DECORATIVE
: return "wxFONTFAMILY_DECORATIVE";
441 case wxFONTFAMILY_ROMAN
: return "wxFONTFAMILY_ROMAN";
442 case wxFONTFAMILY_SCRIPT
: return "wxFONTFAMILY_SCRIPT";
443 case wxFONTFAMILY_SWISS
: return "wxFONTFAMILY_SWISS";
444 case wxFONTFAMILY_MODERN
: return "wxFONTFAMILY_MODERN";
445 case wxFONTFAMILY_TELETYPE
: return "wxFONTFAMILY_TELETYPE";
446 case wxFONTFAMILY_UNKNOWN
: return "wxFONTFAMILY_UNKNOWN";
447 default: return "wxFONTFAMILY_DEFAULT";
451 wxString
wxFontBase::GetStyleString() const
453 wxCHECK_MSG( IsOk(), "wxFONTSTYLE_DEFAULT", "invalid font" );
455 switch ( GetStyle() )
457 case wxFONTSTYLE_NORMAL
: return "wxFONTSTYLE_NORMAL";
458 case wxFONTSTYLE_SLANT
: return "wxFONTSTYLE_SLANT";
459 case wxFONTSTYLE_ITALIC
: return "wxFONTSTYLE_ITALIC";
460 default: return "wxFONTSTYLE_DEFAULT";
464 wxString
wxFontBase::GetWeightString() const
466 wxCHECK_MSG( IsOk(), "wxFONTWEIGHT_DEFAULT", "invalid font" );
468 switch ( GetWeight() )
470 case wxFONTWEIGHT_NORMAL
: return "wxFONTWEIGHT_NORMAL";
471 case wxFONTWEIGHT_BOLD
: return "wxFONTWEIGHT_BOLD";
472 case wxFONTWEIGHT_LIGHT
: return "wxFONTWEIGHT_LIGHT";
473 default: return "wxFONTWEIGHT_DEFAULT";
477 bool wxFontBase::SetFaceName(const wxString
& facename
)
480 if (!wxFontEnumerator::IsValidFacename(facename
))
482 UnRef(); // make IsOk() return false
485 #else // !wxUSE_FONTENUM
486 wxUnusedVar(facename
);
487 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
492 wxFont
& wxFont::MakeBold()
494 SetWeight(wxFONTWEIGHT_BOLD
);
498 wxFont
wxFont::Bold() const
505 wxFont
& wxFont::MakeItalic()
507 SetStyle(wxFONTSTYLE_ITALIC
);
511 wxFont
wxFont::Italic() const
514 font
.SetStyle(wxFONTSTYLE_ITALIC
);
518 wxFont
& wxFont::Scale(float x
)
520 SetPointSize(int(x
*GetPointSize() + 0.5));
524 wxFont
wxFont::Scaled(float x
) const
531 // ----------------------------------------------------------------------------
533 // ----------------------------------------------------------------------------
535 // Up to now, there are no native implementations of this function:
536 void wxNativeFontInfo::SetFaceName(const wxArrayString
& facenames
)
539 for (size_t i
=0; i
< facenames
.GetCount(); i
++)
541 if (wxFontEnumerator::IsValidFacename(facenames
[i
]))
543 SetFaceName(facenames
[i
]);
548 // set the first valid facename we can find on this system
549 wxString validfacename
= wxFontEnumerator::GetFacenames().Item(0);
550 wxLogTrace(wxT("font"), wxT("Falling back to '%s'"), validfacename
.c_str());
551 SetFaceName(validfacename
);
552 #else // !wxUSE_FONTENUM
553 SetFaceName(facenames
[0]);
554 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
558 #ifdef wxNO_NATIVE_FONTINFO
560 // These are the generic forms of FromString()/ToString.
562 // convert to/from the string representation: format is
563 // version;pointsize;family;style;weight;underlined;facename;encoding
565 bool wxNativeFontInfo::FromString(const wxString
& s
)
569 wxStringTokenizer
tokenizer(s
, wxT(";"));
571 wxString token
= tokenizer
.GetNextToken();
573 // Ignore the version for now
576 token
= tokenizer
.GetNextToken();
577 if ( !token
.ToLong(&l
) )
581 token
= tokenizer
.GetNextToken();
582 if ( !token
.ToLong(&l
) )
584 family
= (wxFontFamily
)l
;
586 token
= tokenizer
.GetNextToken();
587 if ( !token
.ToLong(&l
) )
589 style
= (wxFontStyle
)l
;
591 token
= tokenizer
.GetNextToken();
592 if ( !token
.ToLong(&l
) )
594 weight
= (wxFontWeight
)l
;
596 token
= tokenizer
.GetNextToken();
597 if ( !token
.ToLong(&l
) )
601 faceName
= tokenizer
.GetNextToken();
608 token
= tokenizer
.GetNextToken();
609 if ( !token
.ToLong(&l
) )
611 encoding
= (wxFontEncoding
)l
;
616 wxString
wxNativeFontInfo::ToString() const
620 s
.Printf(wxT("%d;%d;%d;%d;%d;%d;%s;%d"),
633 void wxNativeFontInfo::Init()
636 family
= wxFONTFAMILY_DEFAULT
;
637 style
= wxFONTSTYLE_NORMAL
;
638 weight
= wxFONTWEIGHT_NORMAL
;
641 encoding
= wxFONTENCODING_DEFAULT
;
644 int wxNativeFontInfo::GetPointSize() const
649 wxFontStyle
wxNativeFontInfo::GetStyle() const
654 wxFontWeight
wxNativeFontInfo::GetWeight() const
659 bool wxNativeFontInfo::GetUnderlined() const
664 wxString
wxNativeFontInfo::GetFaceName() const
669 wxFontFamily
wxNativeFontInfo::GetFamily() const
674 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
679 void wxNativeFontInfo::SetPointSize(int pointsize
)
681 pointSize
= pointsize
;
684 void wxNativeFontInfo::SetStyle(wxFontStyle style_
)
689 void wxNativeFontInfo::SetWeight(wxFontWeight weight_
)
694 void wxNativeFontInfo::SetUnderlined(bool underlined_
)
696 underlined
= underlined_
;
699 bool wxNativeFontInfo::SetFaceName(const wxString
& facename_
)
701 faceName
= facename_
;
705 void wxNativeFontInfo::SetFamily(wxFontFamily family_
)
710 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_
)
712 encoding
= encoding_
;
715 #endif // generic wxNativeFontInfo implementation
717 // conversion to/from user-readable string: this is used in the generic
718 // versions and under MSW as well because there is no standard font description
719 // format there anyhow (but there is a well-defined standard for X11 fonts used
720 // by wxGTK and wxMotif)
722 #if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) || defined(__WXOSX__)
724 wxString
wxNativeFontInfo::ToUserString() const
728 // first put the adjectives, if any - this is English-centric, of course,
729 // but what else can we do?
730 if ( GetUnderlined() )
732 desc
<< _("underlined");
735 switch ( GetWeight() )
738 wxFAIL_MSG( wxT("unknown font weight") );
741 case wxFONTWEIGHT_NORMAL
:
744 case wxFONTWEIGHT_LIGHT
:
748 case wxFONTWEIGHT_BOLD
:
753 switch ( GetStyle() )
756 wxFAIL_MSG( wxT("unknown font style") );
759 case wxFONTSTYLE_NORMAL
:
762 // we don't distinguish between the two for now anyhow...
763 case wxFONTSTYLE_ITALIC
:
764 case wxFONTSTYLE_SLANT
:
765 desc
<< _(" italic");
769 wxString face
= GetFaceName();
772 if (face
.Contains(' ') || face
.Contains(';') || face
.Contains(','))
774 face
.Replace("'", "");
775 // eventually remove quote characters: most systems do not
776 // allow them in a facename anyway so this usually does nothing
778 // make it possible for FromUserString() function to understand
779 // that the different words which compose this facename are
780 // not different adjectives or other data but rather all parts
782 desc
<< wxT(" '") << face
<< _("'");
785 desc
<< wxT(' ') << face
;
787 else // no face name specified
791 switch ( GetFamily() )
793 case wxFONTFAMILY_DECORATIVE
:
794 familyStr
= "decorative";
797 case wxFONTFAMILY_ROMAN
:
801 case wxFONTFAMILY_SCRIPT
:
802 familyStr
= "script";
805 case wxFONTFAMILY_SWISS
:
809 case wxFONTFAMILY_MODERN
:
810 familyStr
= "modern";
813 case wxFONTFAMILY_TELETYPE
:
814 familyStr
= "teletype";
817 case wxFONTFAMILY_DEFAULT
:
818 case wxFONTFAMILY_UNKNOWN
:
822 wxFAIL_MSG( "unknown font family" );
825 if ( !familyStr
.empty() )
826 desc
<< " '" << familyStr
<< " family'";
829 int size
= GetPointSize();
830 if ( size
!= wxNORMAL_FONT
->GetPointSize() )
832 desc
<< wxT(' ') << size
;
836 wxFontEncoding enc
= GetEncoding();
837 if ( enc
!= wxFONTENCODING_DEFAULT
&& enc
!= wxFONTENCODING_SYSTEM
)
839 desc
<< wxT(' ') << wxFontMapper::GetEncodingName(enc
);
841 #endif // wxUSE_FONTMAP
843 return desc
.Strip(wxString::both
).MakeLower();
846 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
848 // reset to the default state
851 // ToUserString() will quote the facename if it contains spaces, commas
852 // or semicolons: we must be able to understand that quoted text is
856 // parse a more or less free form string
857 wxStringTokenizer
tokenizer(toparse
, wxT(";, "), wxTOKEN_STRTOK
);
861 bool weightfound
= false, pointsizefound
= false;
863 bool encodingfound
= false;
865 bool insideQuotes
= false;
867 while ( tokenizer
.HasMoreTokens() )
869 wxString token
= tokenizer
.GetNextToken();
872 token
.Trim(true).Trim(false).MakeLower();
875 if (token
.StartsWith("'") ||
878 insideQuotes
= false;
880 // add this last token to the facename:
883 // normalize facename:
884 face
= face
.Trim(true).Trim(false);
885 face
.Replace("'", "");
892 if (token
.StartsWith("'"))
896 // look for the known tokens
899 // only the facename may be quoted:
903 if ( token
== wxT("underlined") || token
== _("underlined") )
907 else if ( token
== wxT("light") || token
== _("light") )
909 SetWeight(wxFONTWEIGHT_LIGHT
);
912 else if ( token
== wxT("bold") || token
== _("bold") )
914 SetWeight(wxFONTWEIGHT_BOLD
);
917 else if ( token
== wxT("italic") || token
== _("italic") )
919 SetStyle(wxFONTSTYLE_ITALIC
);
921 else if ( token
.ToULong(&size
) )
924 pointsizefound
= true;
929 // try to interpret this as an encoding
930 wxFontEncoding encoding
= wxFontMapper::Get()->CharsetToEncoding(token
, false);
931 if ( encoding
!= wxFONTENCODING_DEFAULT
&&
932 encoding
!= wxFONTENCODING_SYSTEM
) // returned when the recognition failed
934 SetEncoding(encoding
);
935 encodingfound
= true;
939 #endif // wxUSE_FONTMAP
941 // assume it is the face name
949 // skip the code which resets face below
954 #endif // wxUSE_FONTMAP
957 // if we had had the facename, we shouldn't continue appending tokens
958 // to it (i.e. "foo bold bar" shouldn't result in the facename "foo
963 if ( face
.EndsWith(" family", &familyStr
) )
965 // it's not a facename but rather a font family
967 if ( familyStr
== "decorative" )
968 family
= wxFONTFAMILY_DECORATIVE
;
969 else if ( familyStr
== "roman" )
970 family
= wxFONTFAMILY_ROMAN
;
971 else if ( familyStr
== "script" )
972 family
= wxFONTFAMILY_SCRIPT
;
973 else if ( familyStr
== "swiss" )
974 family
= wxFONTFAMILY_SWISS
;
975 else if ( familyStr
== "modern" )
976 family
= wxFONTFAMILY_MODERN
;
977 else if ( familyStr
== "teletype" )
978 family
= wxFONTFAMILY_TELETYPE
;
984 // NB: the check on the facename is implemented in wxFontBase::SetFaceName
985 // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely
986 // call here wxFontEnumerator::IsValidFacename
989 !wxFontEnumerator::IsValidFacename(face
) ||
990 #endif // wxUSE_FONTENUM
993 SetFaceName(wxNORMAL_FONT
->GetFaceName());
1000 // we might not have flushed it inside the loop
1001 if ( !face
.empty() )
1003 // NB: the check on the facename is implemented in wxFontBase::SetFaceName
1004 // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely
1005 // call here wxFontEnumerator::IsValidFacename
1008 !wxFontEnumerator::IsValidFacename(face
) ||
1009 #endif // wxUSE_FONTENUM
1010 !SetFaceName(face
) )
1012 SetFaceName(wxNORMAL_FONT
->GetFaceName());
1016 // set point size to default value if size was not given
1017 if ( !pointsizefound
)
1018 SetPointSize(wxNORMAL_FONT
->GetPointSize());
1020 // set font weight to default value if weight was not given
1022 SetWeight(wxFONTWEIGHT_NORMAL
);
1025 // set font encoding to default value if encoding was not given
1026 if ( !encodingfound
)
1027 SetEncoding(wxFONTENCODING_SYSTEM
);
1028 #endif // wxUSE_FONTMAP
1033 #endif // generic or wxMSW or wxOS2
1036 // wxFont <-> wxString utilities, used by wxConfig
1037 wxString
wxToString(const wxFontBase
& font
)
1039 return font
.IsOk() ? font
.GetNativeFontInfoDesc()
1043 bool wxFromString(const wxString
& str
, wxFontBase
*font
)
1045 wxCHECK_MSG( font
, false, wxT("NULL output parameter") );
1053 return font
->SetNativeFontInfo(str
);