]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fontcmn.cpp
Various fixes for wxFilename.
[wxWidgets.git] / src / common / fontcmn.cpp
index c876d04f7423e82ed308a2d8e723725273da8ca0..7044e66827f1e32b5b155b95d17b43a83cdf2d93 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
+#ifdef __GNUG__
+    #pragma implementation "fontbase.h"
+#endif
+
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
     #include "wx/font.h"
 #endif // WX_PRECOMP
 
+#include "wx/fontutil.h" // for wxNativeFontInfo
+
+#include "wx/tokenzr.h"
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -38,6 +46,7 @@
 
 wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM;
 
+/* static */
 wxFont *wxFontBase::New(int size,
                         int family,
                         int style,
@@ -49,6 +58,67 @@ wxFont *wxFontBase::New(int size,
     return new wxFont(size, family, style, weight, underlined, face, encoding);
 }
 
+/* static */
+wxFont *wxFontBase::New(const wxNativeFontInfo& info)
+{
+    return new wxFont(info);
+}
+
+/* static */
+wxFont *wxFontBase::New(const wxString& strNativeFontDesc)
+{
+    wxNativeFontInfo fontInfo;
+    if ( !fontInfo.FromString(strNativeFontDesc) )
+        return (wxFont *)NULL;
+
+    return New(fontInfo);
+}
+
+wxNativeFontInfo *wxFontBase::GetNativeFontInfo() const
+{
+#if !defined(__WXGTK__)
+    wxNativeFontInfo *fontInfo = new wxNativeFontInfo;
+
+    fontInfo->pointSize = GetPointSize();
+    fontInfo->family = GetFamily();
+    fontInfo->style = GetStyle();
+    fontInfo->weight = GetWeight();
+    fontInfo->underlined = GetUnderlined();
+    fontInfo->faceName = GetFaceName();
+    fontInfo->encoding = GetEncoding();
+
+    return fontInfo;
+#else
+    return (wxNativeFontInfo *)NULL;
+#endif
+}
+
+void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo& info)
+{
+#if !defined(__WXGTK__)
+    SetPointSize(info.pointSize);
+    SetFamily(info.family);
+    SetStyle(info.style);
+    SetWeight(info.weight);
+    SetUnderlined(info.underlined);
+    SetFaceName(info.faceName);
+    SetEncoding(info.encoding);
+#endif
+}
+
+wxString wxFontBase::GetNativeFontInfoDesc() const
+{
+    wxString fontDesc;
+    wxNativeFontInfo *fontInfo = GetNativeFontInfo();
+    if ( fontInfo )
+    {
+        fontDesc = fontInfo->ToString();
+        delete fontInfo;
+    }
+
+    return fontDesc;
+}
+
 wxFont& wxFont::operator=(const wxFont& font)
 {
     if ( this != &font )
@@ -70,43 +140,115 @@ bool wxFontBase::operator!=(const wxFont& font) const
 
 wxString wxFontBase::GetFamilyString() const
 {
-    wxCHECK_MSG( Ok(), T("wxDEFAULT"), T("invalid font") );
+    wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
 
     switch ( GetFamily() )
     {
-        case wxDECORATIVE:   return T("wxDECORATIVE");
-        case wxROMAN:        return T("wxROMAN");
-        case wxSCRIPT:       return T("wxSCRIPT");
-        case wxSWISS:        return T("wxSWISS");
-        case wxMODERN:       return T("wxMODERN");
-        case wxTELETYPE:     return T("wxTELETYPE");
-        default:             return T("wxDEFAULT");
+        case wxDECORATIVE:   return wxT("wxDECORATIVE");
+        case wxROMAN:        return wxT("wxROMAN");
+        case wxSCRIPT:       return wxT("wxSCRIPT");
+        case wxSWISS:        return wxT("wxSWISS");
+        case wxMODERN:       return wxT("wxMODERN");
+        case wxTELETYPE:     return wxT("wxTELETYPE");
+        default:             return wxT("wxDEFAULT");
     }
 }
 
 wxString wxFontBase::GetStyleString() const
 {
-    wxCHECK_MSG( Ok(), T("wxDEFAULT"), T("invalid font") );
+    wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
 
     switch ( GetStyle() )
     {
-        case wxNORMAL:   return T("wxNORMAL");
-        case wxSLANT:    return T("wxSLANT");
-        case wxITALIC:   return T("wxITALIC");
-        default:         return T("wxDEFAULT");
+        case wxNORMAL:   return wxT("wxNORMAL");
+        case wxSLANT:    return wxT("wxSLANT");
+        case wxITALIC:   return wxT("wxITALIC");
+        default:         return wxT("wxDEFAULT");
     }
 }
 
 wxString wxFontBase::GetWeightString() const
 {
-    wxCHECK_MSG( Ok(), T("wxDEFAULT"), T("invalid font") );
+    wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
 
     switch ( GetWeight() )
     {
-        case wxNORMAL:   return T("wxNORMAL");
-        case wxBOLD:     return T("wxBOLD");
-        case wxLIGHT:    return T("wxLIGHT");
-        default:         return T("wxDEFAULT");
+        case wxNORMAL:   return wxT("wxNORMAL");
+        case wxBOLD:     return wxT("wxBOLD");
+        case wxLIGHT:    return wxT("wxLIGHT");
+        default:         return wxT("wxDEFAULT");
     }
 }
 
+#if !defined(__WXGTK__)
+
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+// These are the generic forms of FromString()/ToString.
+//
+// convert to/from the string representation: format is
+//      pointsize;family;style;weight;underlined;facename;encoding
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+    long l;
+
+    wxStringTokenizer tokenizer(s, _T(";"));
+
+    wxString token = tokenizer.GetNextToken();
+    if ( !token.ToLong(&l) )
+        return FALSE;
+    pointSize = (int)l;
+
+    token = tokenizer.GetNextToken();
+    if ( !token.ToLong(&l) )
+        return FALSE;
+    family = (int)l;
+
+    token = tokenizer.GetNextToken();
+    if ( !token.ToLong(&l) )
+        return FALSE;
+    style = (int)l;
+
+    token = tokenizer.GetNextToken();
+    if ( !token.ToLong(&l) )
+        return FALSE;
+    weight = (int)l;
+
+    token = tokenizer.GetNextToken();
+    if ( !token.ToLong(&l) )
+        return FALSE;
+    underlined = l != 0;
+
+    faceName = tokenizer.GetNextToken();
+    if( !faceName )
+        return FALSE;
+
+    token = tokenizer.GetNextToken();
+    if ( !token.ToLong(&l) )
+        return FALSE;
+    encoding = (wxFontEncoding)l;
+
+    return TRUE;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+    wxString s;
+
+    s.Printf(_T("%d;%d;%d;%d;%d;%s;%d"),
+             pointSize,
+             family,
+             style,
+             weight,
+             underlined,
+             faceName.GetData(),
+             (int)encoding);
+
+    return s;
+}
+
+#endif // generic wxNativeFontInfo implementation
+