]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fontcmn.cpp
no need to check for wxID_HELP buttons in SetLabel() now that it's overridden in...
[wxWidgets.git] / src / common / fontcmn.cpp
index 4fec6361806d8a4681f221b52814e889504de7bb..86d4e874c47b47871062b8d70cf792758cfb7d7c 100644 (file)
@@ -375,6 +375,7 @@ wxString wxFontBase::GetFamilyString() const
         case wxFONTFAMILY_SWISS:        return "wxFONTFAMILY_SWISS";
         case wxFONTFAMILY_MODERN:       return "wxFONTFAMILY_MODERN";
         case wxFONTFAMILY_TELETYPE:     return "wxFONTFAMILY_TELETYPE";
+        case wxFONTFAMILY_UNKNOWN:      return "wxFONTFAMILY_UNKNOWN";
         default:                        return "wxFONTFAMILY_DEFAULT";
     }
 }
@@ -420,6 +421,44 @@ bool wxFontBase::SetFaceName(const wxString& facename)
     return true;
 }
 
+wxFont& wxFont::MakeBold()
+{
+    SetWeight(wxFONTWEIGHT_BOLD);
+    return *this;
+}
+
+wxFont wxFont::Bold() const
+{
+    wxFont font(*this);
+    font.MakeBold();
+    return font;
+}
+
+wxFont& wxFont::MakeItalic()
+{
+    SetStyle(wxFONTSTYLE_ITALIC);
+    return *this;
+}
+
+wxFont wxFont::Italic() const
+{
+    wxFont font(*this);
+    font.SetStyle(wxFONTSTYLE_ITALIC);
+    return font;
+}
+
+wxFont& wxFont::Scale(float x)
+{
+    SetPointSize(int(x*GetPointSize() + 0.5));
+    return *this;
+}
+
+wxFont wxFont::Scaled(float x) const
+{
+    wxFont font(*this);
+    font.Scale(x);
+    return font;
+}
 
 // ----------------------------------------------------------------------------
 // wxNativeFontInfo
@@ -677,6 +716,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() )
@@ -704,13 +784,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);
@@ -818,10 +891,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