From 1a2ca1d67304e413d258c237222ac31bee3435ba Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 May 2009 11:47:08 +0000 Subject: [PATCH] deal with the fonts without any specified face name in wxNativeFontInfo::To/FromUserString() correctly by using the family as fallback git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60672 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/fontcmn.cpp | 72 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index b10870a927..ef779b3fb4 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -678,6 +678,47 @@ wxString wxNativeFontInfo::ToUserString() const else desc << _T(' ') << face; } + else // no face name specified + { + // use the family + wxString familyStr; + switch ( GetFamily() ) + { + case wxFONTFAMILY_DECORATIVE: + familyStr = "decorative"; + break; + + case wxFONTFAMILY_ROMAN: + familyStr = "roman"; + break; + + case wxFONTFAMILY_SCRIPT: + familyStr = "script"; + break; + + case wxFONTFAMILY_SWISS: + familyStr = "swiss"; + break; + + case wxFONTFAMILY_MODERN: + familyStr = "modern"; + break; + + case wxFONTFAMILY_TELETYPE: + familyStr = "teletype"; + break; + + case wxFONTFAMILY_DEFAULT: + case wxFONTFAMILY_UNKNOWN: + break; + + default: + wxFAIL_MSG( "unknown font family" ); + } + + if ( !familyStr.empty() ) + desc << " '" << familyStr << " family'"; + } int size = GetPointSize(); if ( size != wxNORMAL_FONT->GetPointSize() ) @@ -705,13 +746,6 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) // or semicolons: we must be able to understand that quoted text is // a single token: wxString toparse(s); - /* - wxString::iterator i = toparse.find("'"); - if (i != wxString::npos) - { - for (; *i != '\'' && *i != toparse.end(); i++) - ; - }*/ // parse a more or less free form string wxStringTokenizer tokenizer(toparse, _T(";, "), wxTOKEN_STRTOK); @@ -819,10 +853,32 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) // bar") if ( !face.empty() ) { + wxString familyStr; + if ( face.EndsWith(" family", &familyStr) ) + { + // it's not a facename but rather a font family + wxFontFamily family; + if ( familyStr == "decorative" ) + family = wxFONTFAMILY_DECORATIVE; + else if ( familyStr == "roman" ) + family = wxFONTFAMILY_ROMAN; + else if ( familyStr == "script" ) + family = wxFONTFAMILY_SCRIPT; + else if ( familyStr == "swiss" ) + family = wxFONTFAMILY_SWISS; + else if ( familyStr == "modern" ) + family = wxFONTFAMILY_MODERN; + else if ( familyStr == "teletype" ) + family = wxFONTFAMILY_TELETYPE; + else + return false; + + SetFamily(family); + } // NB: the check on the facename is implemented in wxFontBase::SetFaceName // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely // call here wxFontEnumerator::IsValidFacename - if ( + else if ( #if wxUSE_FONTENUM !wxFontEnumerator::IsValidFacename(face) || #endif // wxUSE_FONTENUM -- 2.45.2