]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fontcmn.cpp
some stupid attempts to make utf8 work - it doesn't, but the code does no harm and...
[wxWidgets.git] / src / common / fontcmn.cpp
index ca1921a2bc6ae38feb20f7afb529a2b6a3754d0a..e973ffbc0d0924395040bc25efbdca8402298fb7 100644 (file)
     #include "wx/font.h"
 #endif // WX_PRECOMP
 
+#include "wx/gdicmn.h"
+#include "wx/fontutil.h" // for wxNativeFontInfo
+
+#include "wx/tokenzr.h"
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -42,6 +47,7 @@
 
 wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM;
 
+/* static */
 wxFont *wxFontBase::New(int size,
                         int family,
                         int style,
@@ -53,6 +59,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 new wxFont(*wxNORMAL_FONT);
+
+    return New(fontInfo);
+}
+
+wxNativeFontInfo *wxFontBase::GetNativeFontInfo() const
+{
+#if !defined(__WXGTK__) && !defined(__WXMSW__)
+    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__) && !defined(__WXMSW__)
+    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 )
@@ -114,3 +181,81 @@ wxString wxFontBase::GetWeightString() const
     }
 }
 
+#if !defined(__WXGTK__) && !defined(__WXMSW__)
+
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+// These are the generic forms of FromString()/ToString.
+//
+// convert to/from the string representation: format is
+//      version;pointsize;family;style;weight;underlined;facename;encoding
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+    long l;
+
+    wxStringTokenizer tokenizer(s, _T(";"));
+
+    wxString token = tokenizer.GetNextToken();
+    //
+    //  Ignore the version for now
+    //
+    
+    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;%d;%s;%d"),
+             0,                                 // version
+             pointSize,
+             family,
+             style,
+             weight,
+             underlined,
+             faceName.GetData(),
+             (int)encoding);
+
+    return s;
+}
+
+#endif // generic wxNativeFontInfo implementation
+