]> git.saurik.com Git - wxWidgets.git/commitdiff
applied wxNativeFontInfo patch from Derry Bryson (with minor changes)
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 18 Dec 2000 01:00:25 +0000 (01:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 18 Dec 2000 01:00:25 +0000 (01:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8934 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

17 files changed:
include/wx/font.h
include/wx/gtk/font.h
include/wx/gtk1/font.h
include/wx/motif/font.h
include/wx/msw/font.h
include/wx/unix/fontutil.h
samples/font/font.cpp
src/common/fontcmn.cpp
src/gtk/data.cpp
src/gtk/font.cpp
src/gtk/fontdlg.cpp
src/gtk1/data.cpp
src/gtk1/font.cpp
src/gtk1/fontdlg.cpp
src/motif/data.cpp
src/msw/data.cpp
src/unix/fontutil.cpp

index 706aad009f16697722618d901a7ab18ba8fcb433..3010028809358db7f5ea10890efddf57ac24806f 100644 (file)
@@ -67,6 +67,40 @@ enum wxFontWeight
     wxFONTWEIGHT_MAX
 };
 
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo is platform-specific font representation
+// ----------------------------------------------------------------------------
+
+// this struct should be considered as opaque font description only used by
+// the native functions, the user code can only get the objects of this type
+// from somewhere and pass it somewhere else (possibly save them somewhere
+// using ToString() and restore them using FromString())
+struct WXDLLEXPORT wxNativeFontInfo
+{
+#if defined(__WXGTK__)
+    wxString     xFontName;
+#else // other platforms
+    //
+    //  This is a generic implementation that should work on all ports
+    //  without specific support by the port.
+    //
+    int           pointSize;
+    int           family;
+    int           style;
+    int           weight;
+    bool          underlined;
+    wxString      faceName;
+    wxFontEncoding encoding;
+#endif // platforms
+
+    // it is important to be able to serialize wxNativeFontInfo objects to be
+    // able to store them (in config file, for example)
+    bool FromString(const wxString& s);
+    wxString ToString() const;
+};
+
+WXDLLEXPORT_DATA(extern wxNativeFontInfo) wxNullNativeFontInfo;
+
 // ----------------------------------------------------------------------------
 // wxFontBase represents a font object
 // ----------------------------------------------------------------------------
@@ -85,6 +119,7 @@ public:
         bool underlined = FALSE,    // not underlined by default
         const wxString& face = wxEmptyString,              // facename
         wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
+    static wxFont *New(const wxNativeFontInfo& info);
 
     // was the font successfully created?
     bool Ok() const { return m_refData != NULL; }
@@ -101,6 +136,7 @@ public:
     virtual bool GetUnderlined() const = 0;
     virtual wxString GetFaceName() const = 0;
     virtual wxFontEncoding GetEncoding() const = 0;
+    virtual wxNativeFontInfo GetNativeFontInfo() const;
 
     // change the font characteristics
     virtual void SetPointSize( int pointSize ) = 0;
@@ -110,6 +146,7 @@ public:
     virtual void SetFaceName( const wxString& faceName ) = 0;
     virtual void SetUnderlined( bool underlined ) = 0;
     virtual void SetEncoding(wxFontEncoding encoding) = 0;
+    virtual void SetNativeFontInfo(const wxNativeFontInfo& info);
 
     // translate the fonts into human-readable string (i.e. GetStyleString()
     // will return "wxITALIC" for an italic font, ...)
index c3885bfa268c624b400b5d462aa65faf2f6f8474..a15d5b5dcc0f2d51ce59fa0f3e0c01fe09e38f5e 100644 (file)
@@ -36,7 +36,8 @@ public:
     // ctors and such
     wxFont() { Init(); }
     wxFont(const wxFont& font) { Init(); Ref(font); }
-    wxFont(const wxString& fontname, const wxFontData& fontdata);
+    wxFont(const wxString& fontname, const wxFontData& fontdata) { Create(fontname, fontdata); }
+    wxFont(const wxNativeFontInfo& info);
 
     // assignment
     wxFont& operator=(const wxFont& font);
@@ -60,7 +61,10 @@ public:
                 int weight,
                 bool underlined = FALSE,
                 const wxString& face = wxEmptyString,
-                wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+                wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+                const wxNativeFontInfo& info = wxNullNativeFontInfo);
+
+    bool Create(const wxString& fontname, const wxFontData& fontdata);
 
     ~wxFont();
 
@@ -72,6 +76,7 @@ public:
     virtual wxString GetFaceName() const;
     virtual bool GetUnderlined() const;
     virtual wxFontEncoding GetEncoding() const;
+    virtual wxNativeFontInfo GetNativeFontInfo() const;
 
     virtual void SetPointSize( int pointSize );
     virtual void SetFamily( int family );
@@ -80,6 +85,7 @@ public:
     virtual void SetFaceName( const wxString& faceName );
     virtual void SetUnderlined( bool underlined );
     virtual void SetEncoding(wxFontEncoding encoding);
+    virtual void SetNativeFontInfo( const wxNativeFontInfo& info );
 
     // implementation from now on
     void Unshare();
index c3885bfa268c624b400b5d462aa65faf2f6f8474..a15d5b5dcc0f2d51ce59fa0f3e0c01fe09e38f5e 100644 (file)
@@ -36,7 +36,8 @@ public:
     // ctors and such
     wxFont() { Init(); }
     wxFont(const wxFont& font) { Init(); Ref(font); }
-    wxFont(const wxString& fontname, const wxFontData& fontdata);
+    wxFont(const wxString& fontname, const wxFontData& fontdata) { Create(fontname, fontdata); }
+    wxFont(const wxNativeFontInfo& info);
 
     // assignment
     wxFont& operator=(const wxFont& font);
@@ -60,7 +61,10 @@ public:
                 int weight,
                 bool underlined = FALSE,
                 const wxString& face = wxEmptyString,
-                wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+                wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+                const wxNativeFontInfo& info = wxNullNativeFontInfo);
+
+    bool Create(const wxString& fontname, const wxFontData& fontdata);
 
     ~wxFont();
 
@@ -72,6 +76,7 @@ public:
     virtual wxString GetFaceName() const;
     virtual bool GetUnderlined() const;
     virtual wxFontEncoding GetEncoding() const;
+    virtual wxNativeFontInfo GetNativeFontInfo() const;
 
     virtual void SetPointSize( int pointSize );
     virtual void SetFamily( int family );
@@ -80,6 +85,7 @@ public:
     virtual void SetFaceName( const wxString& faceName );
     virtual void SetUnderlined( bool underlined );
     virtual void SetEncoding(wxFontEncoding encoding);
+    virtual void SetNativeFontInfo( const wxNativeFontInfo& info );
 
     // implementation from now on
     void Unshare();
index 906bc2462a681ca114a3c58b11f278aec8677436..d6aeb9e1bfe80bd40db8a7513cec499b0e228e3e 100644 (file)
@@ -37,6 +37,14 @@ public:
         (void)Create(size, family, style, weight, underlined, face, encoding);
     }
 
+    wxFont(const wxNativeFontInfo& info)
+    {
+        Init();
+
+        (void)Create(info.pointSize, info.family, info.style, info.weight,
+                     info.underlined, info.faceName, info.encoding);
+    }
+
     bool Create(int size,
                 int family,
                 int style,
index f7c564b1e90ac25632a5f183ef36d6fad8ec29ec..12677e19d594b684b6996e0dec91edea71ad742e 100644 (file)
@@ -40,6 +40,14 @@ public:
         (void)Create(size, family, style, weight, underlined, face, encoding);
     }
 
+    wxFont(const wxNativeFontInfo& info)
+    {
+        Init();
+
+        (void)Create(info.pointSize, info.family, info.style, info.weight,
+                     info.underlined, info.faceName, info.encoding);
+    }
+
     bool Create(int size,
                 int family,
                 int style,
index 836ed81705a62773adb79ae79b02dfc4dc187395..b021ac6fd1ac20657d64d7448b8531a4aeed41a7 100644 (file)
 #endif
 
 // returns the handle of the nearest available font or 0
-extern wxNativeFont wxLoadQueryNearestFont(int pointSize,
-                                           int family,
-                                           int style,
-                                           int weight,
-                                           bool underlined,
-                                           const wxString &facename,
-                                           wxFontEncoding encoding);
+extern wxNativeFont
+wxLoadQueryNearestFont(int pointSize,
+                       int family,
+                       int style,
+                       int weight,
+                       bool underlined,
+                       const wxString &facename,
+                       wxFontEncoding encoding,
+                       wxString* xFontName = (wxString *)NULL);
 
 #endif // _WX_UNIX_FONTUTIL_H_
index c8dd213baad978e32ce2e3947cc43dcdcac5885c..4322827f0a9f26649e790b81b5e42813e95aeabb 100644 (file)
@@ -96,6 +96,8 @@ public:
         { DoEnumerateFamilies(TRUE); }
     void OnEnumerateEncodings(wxCommandEvent& event);
 
+    void OnCheckNativeToFromString(wxCommandEvent& event);
+
     void OnSize(wxSizeEvent& event);
 
 protected:
@@ -136,7 +138,8 @@ enum
     Font_EnumFamilies,
     Font_EnumFixedFamilies,
     Font_EnumEncodings,
-    Font_Max
+    Font_CheckNativeToFromString
+    Font_Max,
 };
 
 // ----------------------------------------------------------------------------
@@ -157,6 +160,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(Font_EnumFamilies, MyFrame::OnEnumerateFamilies)
     EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies)
     EVT_MENU(Font_EnumEncodings, MyFrame::OnEnumerateEncodings)
+    EVT_MENU(Font_CheckNativeToFromString, MyFrame::OnCheckNativeToFromString)
 
     EVT_SIZE(MyFrame::OnSize)
 END_EVENT_TABLE()
@@ -228,6 +232,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     menuFont->Append(Font_EnumFamiliesForEncoding,
                      "Find font for en&coding...\tCtrl-C",
                      "Find font families for given encoding");
+    menuFont->AppendSeparator();
+    menuFont->Append(Font_CheckNativeToFromString,
+                     "Check Native Font Info To/From String");
 
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar;
@@ -382,7 +389,7 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
         wxFONTENCODING_CP1252,
     };
 
-    static const char *encodingNames[] =
+    static const wxString encodingNames[] =
     {
         "West European (Latin 1)",
         "Central European (Latin 2)",
@@ -397,7 +404,7 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
 
     int n = wxGetSingleChoiceIndex("Choose an encoding", "Font demo",
                                    WXSIZEOF(encodingNames),
-                                   (char **)encodingNames,
+                                   encodingNames,
                                    this);
 
     if ( n != -1 )
@@ -406,6 +413,27 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
     }
 }
 
+void MyFrame::OnCheckNativeToFromString(wxCommandEvent& WXUNUSED(event))
+{
+    wxString fontInfo = m_canvas->GetTextFont().GetNativeFontInfo().ToString();
+
+    if(fontInfo.IsEmpty())
+        wxMessageBox("Native font info string is empty!", "Font demo",
+                     wxOK);
+    else
+    {
+        wxNativeFontInfo info;
+        info.FromString(fontInfo);
+        wxFont font(info);
+        if(fontInfo == font.GetNativeFontInfo().ToString())
+            wxMessageBox("wxNativeFontInfo ToString()/FromString() works!",
+                         "Font demo", wxOK);
+        else
+            wxMessageBox("wxNativeFontInfo ToString()/FromString() doesn't work!",
+                         "Font demo", wxOK);
+     }
+}
+
 void MyFrame::DoResizeFont(int diff)
 {
     wxFont fontOld = m_canvas->GetTextFont();
@@ -650,6 +678,13 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
     dc.DrawText(fontInfo, 5, 5);
 
+    if(m_font.Ok())
+    {
+      dc.SetFont(wxFont(m_font.GetNativeFontInfo()));
+      fontInfo.Printf("Native font info: %s", m_font.GetNativeFontInfo().ToString().GetData());
+      dc.DrawText(fontInfo, 5, 5 + dc.GetCharHeight());
+    }
+
     // prepare to draw the font
     dc.SetFont(m_font);
     dc.SetTextForeground(m_colour);
index 8a5e31d4dd70edad2abd716a884491a691f3e3f4..812c56c42c473c0777c75e5afb78d03a6e6ab90c 100644 (file)
@@ -32,6 +32,8 @@
     #include "wx/font.h"
 #endif // WX_PRECOMP
 
+#include "wx/tokenzr.h"
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -54,6 +56,44 @@ 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);
+}
+
+wxNativeFontInfo wxFontBase::GetNativeFontInfo() const
+{
+#if !defined(__WXGTK__)
+    wxNativeFontInfo fontInfo;
+
+    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 wxNullNativeFontInfo;
+#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
+}
+
 wxFont& wxFont::operator=(const wxFont& font)
 {
     if ( this != &font )
@@ -115,3 +155,75 @@ wxString wxFontBase::GetWeightString() const
     }
 }
 
+#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 = (int)l;
+
+    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("%d;%d;%d;%d;%d;%s;%d",
+             pointSize,
+             family,
+             style,
+             weight,
+             underlined,
+             faceName.GetData(),
+             (int)encoding);
+
+    return s;
+}
+
+#endif
+
index dc6b6523a8562816e30755763106bcb225ee4fc2..932a0d00c250841ae68b8f423fa5c13e61ed9627 100644 (file)
@@ -126,6 +126,7 @@ wxBrush    wxNullBrush;
 wxFont     wxNullFont;
 wxColour   wxNullColour;
 wxPalette  wxNullPalette;
+wxNativeFontInfo wxNullNativeFontInfo;
 
 /* Default window names */
 const wxChar *wxControlNameStr = wxT("control");
index 83010c18da9d477b7255e7ff55a91e9294f9c9f9..0dbf09dd4d352889a2c89e73d657643db92c31fe 100644 (file)
@@ -47,7 +47,8 @@ public:
                   int weight = wxDEFAULT,
                   bool underlined = FALSE,
                   const wxString& faceName = wxEmptyString,
-                  wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+                  wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+                  const wxNativeFontInfo& info = wxNullNativeFontInfo);
     wxFontRefData( const wxFontRefData& data );
     virtual ~wxFontRefData();
 
@@ -59,7 +60,8 @@ protected:
               int weight,
               bool underlined,
               const wxString& faceName,
-              wxFontEncoding encoding);
+              wxFontEncoding encoding,
+              const wxNativeFontInfo& info);
 
 private:
     wxList          m_scaled_xfonts;
@@ -70,6 +72,7 @@ private:
     bool            m_underlined;
     wxString        m_faceName;
     wxFontEncoding  m_encoding;
+    wxNativeFontInfo m_nativeFontInfo;
 
     friend class wxFont;
 };
@@ -88,7 +91,8 @@ void wxFontRefData::Init(int pointSize,
                          int weight,
                          bool underlined,
                          const wxString& faceName,
-                         wxFontEncoding encoding)
+                         wxFontEncoding encoding,
+                         const wxNativeFontInfo& info = wxNullNativeFontInfo)
 {
     if (family == wxDEFAULT)
         m_family = wxSWISS;
@@ -114,21 +118,24 @@ void wxFontRefData::Init(int pointSize,
 
     m_underlined = underlined;
     m_encoding = encoding;
+    m_nativeFontInfo = info;
 }
 
 wxFontRefData::wxFontRefData( const wxFontRefData& data )
     : m_scaled_xfonts(wxKEY_INTEGER)
 {
     Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
-        data.m_underlined, data.m_faceName, data.m_encoding);
+        data.m_underlined, data.m_faceName, data.m_encoding,
+        data.m_nativeFontInfo );
 }
 
 wxFontRefData::wxFontRefData(int size, int family, int style,
-    int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding )
+    int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding,
+    const wxNativeFontInfo& info = wxNullNativeFontInfo)
     : m_scaled_xfonts(wxKEY_INTEGER)
 {
     Init(size, family, style, weight,
-        underlined, faceName, encoding);
+        underlined, faceName, encoding, info);
 }
 
 wxFontRefData::~wxFontRefData()
@@ -143,6 +150,21 @@ wxFontRefData::~wxFontRefData()
     }
 }
 
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+    xFontName = s;
+    return TRUE;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+    return xFontName;
+}
+
 // ----------------------------------------------------------------------------
 // wxFont
 // ----------------------------------------------------------------------------
@@ -155,14 +177,40 @@ void wxFont::Init()
         wxTheFontList->Append( this );
 }
 
-wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
+wxFont::wxFont(const wxNativeFontInfo& info)
+{
+    Create(info.xFontName, wxFontData());
+}
+
+bool wxFont::Create( int pointSize,
+                     int family,
+                     int style,
+                     int weight,
+                     bool underlined,
+                     const wxString& face,
+                     wxFontEncoding encoding,
+                     const wxNativeFontInfo& info )
+{
+    m_refData = new wxFontRefData(pointSize, family, style, weight,
+                                  underlined, face, encoding, info);
+
+    return TRUE;
+}
+
+bool wxFont::Create(const wxString& fontname, const wxFontData& fontdata)
 {
     Init();
 
-    wxCHECK_RET( !!fontname, _T("invalid font spec") );
+    if(!fontname)
+    {
+         *this = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT);
+         return TRUE;
+    }
 
     m_refData = new wxFontRefData();
 
+    M_FONTDATA->m_nativeFontInfo.xFontName = fontname;  // X font name
+
     wxString tmp;
 
     wxStringTokenizer tn( fontname, wxT("-") );
@@ -170,6 +218,7 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
     tn.GetNextToken();                           // skip initial empty token
     tn.GetNextToken();                           // foundry
 
+
     M_FONTDATA->m_faceName = tn.GetNextToken();  // family
 
     tmp = tn.GetNextToken().MakeUpper();         // weight
@@ -247,20 +296,9 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
             M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
         }
         //else: unknown encoding - may be give a warning here?
+        else
+            return FALSE;
     }
-}
-
-bool wxFont::Create( int pointSize,
-                     int family,
-                     int style,
-                     int weight,
-                     bool underlined,
-                     const wxString& face,
-                     wxFontEncoding encoding )
-{
-    m_refData = new wxFontRefData(pointSize, family, style, weight,
-                                  underlined, face, encoding);
-
     return TRUE;
 }
 
@@ -338,6 +376,16 @@ wxFontEncoding wxFont::GetEncoding() const
     return M_FONTDATA->m_encoding;
 }
 
+wxNativeFontInfo wxFont::GetNativeFontInfo() const
+{
+    wxCHECK_MSG( Ok(), wxNullNativeFontInfo, wxT("invalid font") );
+
+    if(M_FONTDATA->m_nativeFontInfo.xFontName.IsEmpty())
+        GetInternalFont();
+    return M_FONTDATA->m_nativeFontInfo;
+}
+
+
 // ----------------------------------------------------------------------------
 // change font attributes
 // ----------------------------------------------------------------------------
@@ -347,6 +395,7 @@ void wxFont::SetPointSize(int pointSize)
     Unshare();
 
     M_FONTDATA->m_pointSize = pointSize;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetFamily(int family)
@@ -354,6 +403,7 @@ void wxFont::SetFamily(int family)
     Unshare();
 
     M_FONTDATA->m_family = family;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetStyle(int style)
@@ -361,6 +411,7 @@ void wxFont::SetStyle(int style)
     Unshare();
 
     M_FONTDATA->m_style = style;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetWeight(int weight)
@@ -368,6 +419,7 @@ void wxFont::SetWeight(int weight)
     Unshare();
 
     M_FONTDATA->m_weight = weight;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetFaceName(const wxString& faceName)
@@ -375,6 +427,7 @@ void wxFont::SetFaceName(const wxString& faceName)
     Unshare();
 
     M_FONTDATA->m_faceName = faceName;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetUnderlined(bool underlined)
@@ -389,6 +442,14 @@ void wxFont::SetEncoding(wxFontEncoding encoding)
     Unshare();
 
     M_FONTDATA->m_encoding = encoding;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
+}
+
+void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info)
+{
+    Unshare();
+
+    M_FONTDATA->m_nativeFontInfo = info;
 }
 
 // ----------------------------------------------------------------------------
@@ -450,7 +511,8 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
                                            M_FONTDATA->m_weight,
                                            M_FONTDATA->m_underlined,
                                            M_FONTDATA->m_faceName,
-                                           M_FONTDATA->m_encoding );
+                                           M_FONTDATA->m_encoding,
+                                           &M_FONTDATA->m_nativeFontInfo.xFontName );
         }
 
         M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
index 0cd7791011314b621de8df7b715ed59457674f39..47a34e1bcc3c31a6cd36707be5bd851fb459e6d1 100644 (file)
@@ -174,6 +174,16 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
 
     gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
         GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
+
+    wxFont font = m_fontData.GetInitialFont();
+    if( font.Ok() )
+    {
+        wxNativeFontInfo info = font.GetNativeFontInfo();
+
+        if( info.xFontName.IsEmpty() )
+            font.GetInternalFont();
+        gtk_font_selection_dialog_set_font_name(sel, wxConvCurrent->cWX2MB(info.xFontName.GetData()));
+    }
 }
 
 wxFontDialog::~wxFontDialog()
index dc6b6523a8562816e30755763106bcb225ee4fc2..932a0d00c250841ae68b8f423fa5c13e61ed9627 100644 (file)
@@ -126,6 +126,7 @@ wxBrush    wxNullBrush;
 wxFont     wxNullFont;
 wxColour   wxNullColour;
 wxPalette  wxNullPalette;
+wxNativeFontInfo wxNullNativeFontInfo;
 
 /* Default window names */
 const wxChar *wxControlNameStr = wxT("control");
index 83010c18da9d477b7255e7ff55a91e9294f9c9f9..0dbf09dd4d352889a2c89e73d657643db92c31fe 100644 (file)
@@ -47,7 +47,8 @@ public:
                   int weight = wxDEFAULT,
                   bool underlined = FALSE,
                   const wxString& faceName = wxEmptyString,
-                  wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+                  wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+                  const wxNativeFontInfo& info = wxNullNativeFontInfo);
     wxFontRefData( const wxFontRefData& data );
     virtual ~wxFontRefData();
 
@@ -59,7 +60,8 @@ protected:
               int weight,
               bool underlined,
               const wxString& faceName,
-              wxFontEncoding encoding);
+              wxFontEncoding encoding,
+              const wxNativeFontInfo& info);
 
 private:
     wxList          m_scaled_xfonts;
@@ -70,6 +72,7 @@ private:
     bool            m_underlined;
     wxString        m_faceName;
     wxFontEncoding  m_encoding;
+    wxNativeFontInfo m_nativeFontInfo;
 
     friend class wxFont;
 };
@@ -88,7 +91,8 @@ void wxFontRefData::Init(int pointSize,
                          int weight,
                          bool underlined,
                          const wxString& faceName,
-                         wxFontEncoding encoding)
+                         wxFontEncoding encoding,
+                         const wxNativeFontInfo& info = wxNullNativeFontInfo)
 {
     if (family == wxDEFAULT)
         m_family = wxSWISS;
@@ -114,21 +118,24 @@ void wxFontRefData::Init(int pointSize,
 
     m_underlined = underlined;
     m_encoding = encoding;
+    m_nativeFontInfo = info;
 }
 
 wxFontRefData::wxFontRefData( const wxFontRefData& data )
     : m_scaled_xfonts(wxKEY_INTEGER)
 {
     Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
-        data.m_underlined, data.m_faceName, data.m_encoding);
+        data.m_underlined, data.m_faceName, data.m_encoding,
+        data.m_nativeFontInfo );
 }
 
 wxFontRefData::wxFontRefData(int size, int family, int style,
-    int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding )
+    int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding,
+    const wxNativeFontInfo& info = wxNullNativeFontInfo)
     : m_scaled_xfonts(wxKEY_INTEGER)
 {
     Init(size, family, style, weight,
-        underlined, faceName, encoding);
+        underlined, faceName, encoding, info);
 }
 
 wxFontRefData::~wxFontRefData()
@@ -143,6 +150,21 @@ wxFontRefData::~wxFontRefData()
     }
 }
 
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+    xFontName = s;
+    return TRUE;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+    return xFontName;
+}
+
 // ----------------------------------------------------------------------------
 // wxFont
 // ----------------------------------------------------------------------------
@@ -155,14 +177,40 @@ void wxFont::Init()
         wxTheFontList->Append( this );
 }
 
-wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
+wxFont::wxFont(const wxNativeFontInfo& info)
+{
+    Create(info.xFontName, wxFontData());
+}
+
+bool wxFont::Create( int pointSize,
+                     int family,
+                     int style,
+                     int weight,
+                     bool underlined,
+                     const wxString& face,
+                     wxFontEncoding encoding,
+                     const wxNativeFontInfo& info )
+{
+    m_refData = new wxFontRefData(pointSize, family, style, weight,
+                                  underlined, face, encoding, info);
+
+    return TRUE;
+}
+
+bool wxFont::Create(const wxString& fontname, const wxFontData& fontdata)
 {
     Init();
 
-    wxCHECK_RET( !!fontname, _T("invalid font spec") );
+    if(!fontname)
+    {
+         *this = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT);
+         return TRUE;
+    }
 
     m_refData = new wxFontRefData();
 
+    M_FONTDATA->m_nativeFontInfo.xFontName = fontname;  // X font name
+
     wxString tmp;
 
     wxStringTokenizer tn( fontname, wxT("-") );
@@ -170,6 +218,7 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
     tn.GetNextToken();                           // skip initial empty token
     tn.GetNextToken();                           // foundry
 
+
     M_FONTDATA->m_faceName = tn.GetNextToken();  // family
 
     tmp = tn.GetNextToken().MakeUpper();         // weight
@@ -247,20 +296,9 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
             M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
         }
         //else: unknown encoding - may be give a warning here?
+        else
+            return FALSE;
     }
-}
-
-bool wxFont::Create( int pointSize,
-                     int family,
-                     int style,
-                     int weight,
-                     bool underlined,
-                     const wxString& face,
-                     wxFontEncoding encoding )
-{
-    m_refData = new wxFontRefData(pointSize, family, style, weight,
-                                  underlined, face, encoding);
-
     return TRUE;
 }
 
@@ -338,6 +376,16 @@ wxFontEncoding wxFont::GetEncoding() const
     return M_FONTDATA->m_encoding;
 }
 
+wxNativeFontInfo wxFont::GetNativeFontInfo() const
+{
+    wxCHECK_MSG( Ok(), wxNullNativeFontInfo, wxT("invalid font") );
+
+    if(M_FONTDATA->m_nativeFontInfo.xFontName.IsEmpty())
+        GetInternalFont();
+    return M_FONTDATA->m_nativeFontInfo;
+}
+
+
 // ----------------------------------------------------------------------------
 // change font attributes
 // ----------------------------------------------------------------------------
@@ -347,6 +395,7 @@ void wxFont::SetPointSize(int pointSize)
     Unshare();
 
     M_FONTDATA->m_pointSize = pointSize;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetFamily(int family)
@@ -354,6 +403,7 @@ void wxFont::SetFamily(int family)
     Unshare();
 
     M_FONTDATA->m_family = family;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetStyle(int style)
@@ -361,6 +411,7 @@ void wxFont::SetStyle(int style)
     Unshare();
 
     M_FONTDATA->m_style = style;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetWeight(int weight)
@@ -368,6 +419,7 @@ void wxFont::SetWeight(int weight)
     Unshare();
 
     M_FONTDATA->m_weight = weight;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetFaceName(const wxString& faceName)
@@ -375,6 +427,7 @@ void wxFont::SetFaceName(const wxString& faceName)
     Unshare();
 
     M_FONTDATA->m_faceName = faceName;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
 }
 
 void wxFont::SetUnderlined(bool underlined)
@@ -389,6 +442,14 @@ void wxFont::SetEncoding(wxFontEncoding encoding)
     Unshare();
 
     M_FONTDATA->m_encoding = encoding;
+    M_FONTDATA->m_nativeFontInfo.xFontName.Clear();            // invalid now
+}
+
+void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info)
+{
+    Unshare();
+
+    M_FONTDATA->m_nativeFontInfo = info;
 }
 
 // ----------------------------------------------------------------------------
@@ -450,7 +511,8 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
                                            M_FONTDATA->m_weight,
                                            M_FONTDATA->m_underlined,
                                            M_FONTDATA->m_faceName,
-                                           M_FONTDATA->m_encoding );
+                                           M_FONTDATA->m_encoding,
+                                           &M_FONTDATA->m_nativeFontInfo.xFontName );
         }
 
         M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
index 0cd7791011314b621de8df7b715ed59457674f39..47a34e1bcc3c31a6cd36707be5bd851fb459e6d1 100644 (file)
@@ -174,6 +174,16 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
 
     gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
         GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
+
+    wxFont font = m_fontData.GetInitialFont();
+    if( font.Ok() )
+    {
+        wxNativeFontInfo info = font.GetNativeFontInfo();
+
+        if( info.xFontName.IsEmpty() )
+            font.GetInternalFont();
+        gtk_font_selection_dialog_set_font_name(sel, wxConvCurrent->cWX2MB(info.xFontName.GetData()));
+    }
 }
 
 wxFontDialog::~wxFontDialog()
index eb1c8e0713066ae5d82fedcb96ce7ae53fcc7f19..543d3178067c1d7f2a21a728eadbc6be3144547e 100644 (file)
@@ -87,6 +87,7 @@ wxBrush  wxNullBrush;
 wxPalette wxNullPalette;
 wxFont   wxNullFont;
 wxColour wxNullColour;
+wxNativeFontInfo wxNullNativeFontInfo;
 
 // Default window names
 const char *wxButtonNameStr = "button";
index 0a9c7286a28779aeddbc2f0d8357b4b35736e120..e9e1c75c78e729a2469f14a601606cebdf78d386 100644 (file)
@@ -96,6 +96,7 @@ wxBrush   wxNullBrush;
 wxPalette wxNullPalette;
 wxFont    wxNullFont;
 wxColour  wxNullColour;
+wxNativeFontInfo wxNullNativeFontInfo;
 
 // Default window names
 const wxChar *wxControlNameStr = wxT("control");
index 224725f7b6d26d5aaf70f8fe65976ff249176dd1..2c371f3c1f4357ff440dd9ab42981ee56dc7c9ee 100644 (file)
@@ -95,7 +95,8 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
                                     bool underlined,
                                     const wxString& facename,
                                     const wxString& xregistry,
-                                    const wxString& xencoding);
+                                    const wxString& xencoding,
+                                    wxString* xFontName);
 
 // ============================================================================
 // implementation
@@ -240,7 +241,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
                                     int weight,
                                     bool underlined,
                                     const wxString &facename,
-                                    wxFontEncoding encoding)
+                                    wxFontEncoding encoding,
+                                    wxString* xFontName)
 {
     if ( encoding == wxFONTENCODING_DEFAULT )
     {
@@ -274,9 +276,17 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
     }
     
     // OK, we have the correct xregistry/xencoding in info structure
-    wxNativeFont font = wxLoadQueryFont( pointSize, family, style, weight,
+    wxNativeFont font = 0;
+
+    // if we already have the X font name, try to use it
+    if( xFontName && !xFontName->IsEmpty() )
+        font = wxLoadFont(*xFontName);
+
+    if( !font )
+        font = wxLoadQueryFont( pointSize, family, style, weight,
                                          underlined, facename,
-                                         info.xregistry, info.xencoding );
+                                info.xregistry, info.xencoding,
+                                xFontName );
 
     if ( !font )
     {
@@ -290,14 +300,16 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
         for ( i = pointSize - 10; !font && i >= 10 && i >= min_size; i -= 10 )
         {
             font = wxLoadQueryFont(i, family, style, weight, underlined,
-                                   facename, info.xregistry, info.xencoding);
+                                   facename, info.xregistry, info.xencoding,
+                                   xFontName);
         }
 
         // Search for larger size (approx.)
         for ( i = pointSize + 10; !font && i <= max_size; i += 10 )
         {
             font = wxLoadQueryFont(i, family, style, weight, underlined,
-                                   facename, info.xregistry, info.xencoding);
+                                   facename, info.xregistry, info.xencoding,
+                                   xFontName);
         }
 
         // Try default family
@@ -305,7 +317,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
         {
             font = wxLoadQueryFont(pointSize, wxDEFAULT, style, weight,
                                    underlined, facename,
-                                   info.xregistry, info.xencoding );
+                                   info.xregistry, info.xencoding,
+                                   xFontName );
         }
 
         // Bogus font I
@@ -313,7 +326,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
         {
             font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
                                    underlined, facename,
-                                   info.xregistry, info.xencoding);
+                                   info.xregistry, info.xencoding,
+                                   xFontName);
         }
 
         // Bogus font II
@@ -321,7 +335,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
         {
             font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
                                    underlined, wxEmptyString,
-                                   info.xregistry, info.xencoding);
+                                   info.xregistry, info.xencoding,
+                                   xFontName);
         }
     }
 
@@ -371,7 +386,8 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
                                     bool WXUNUSED(underlined),
                                     const wxString& facename,
                                     const wxString& xregistry,
-                                    const wxString& xencoding)
+                                    const wxString& xencoding,
+                                    wxString* xFontName)
 {
     wxString xfamily;
     switch (family)
@@ -545,6 +561,9 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
                     xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
                     pointSize, xregistry.c_str(), xencoding.c_str());
 
+    if( xFontName )
+        *xFontName = fontSpec;
+
     return wxLoadFont(fontSpec);
 }