]> git.saurik.com Git - wxWidgets.git/commitdiff
move SetPangoAttrsForFont to wxFont
authorPaul Cornett <paulcor@bullseye.com>
Sun, 29 Jan 2012 08:00:15 +0000 (08:00 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Sun, 29 Jan 2012 08:00:15 +0000 (08:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/font.h
include/wx/gtk/private.h
src/gtk/dcclient.cpp
src/gtk/font.cpp
src/gtk/print.cpp

index d1c04e2d8be81c6fdd2463662ecdd3f0fe33751a..8d1168f0e02526c7fc891d1840f5e5d26e1bd8b0 100644 (file)
@@ -104,6 +104,17 @@ public:
 
     wxDECLARE_COMMON_FONT_METHODS();
 
+    // Set Pango attributes for the span 0..len (or
+    // without any bounds if len == 0) in the specified layout. Currently only
+    // underlined and strike-through attributes are handled by this function.
+    //
+    // Special "addDummyAttrs" parameter is used to work around a bug in old Pango
+    // versions in wxWindowDCImpl::DoDrawText(), see comment there.
+    //
+    // If neither of them is specified, returns false, otherwise sets up the
+    // attributes and returns true.
+    bool GTKSetPangoAttrs(PangoLayout* layout, size_t len = 0, bool addDummyAttrs = false) const;
+
     // implementation from now on
     void Unshare();
 
index 2bf984ce4513df239fa5782c296f813ab9e404d1..43d85125c76fc648cd89be8cf09e38f91fc08809 100644 (file)
@@ -17,8 +17,6 @@
 #include "wx/gtk/private/string.h"
 #include "wx/gtk/private/gtk2-compat.h"
 
-class WXDLLIMPEXP_FWD_CORE wxFont;
-
 // pango_version_check symbol is quite recent ATM (4/2007)... so we
 // use our own wrapper which implements a smart trick.
 // Use this function as you'd use pango_version_check:
@@ -113,22 +111,6 @@ GtkWidget *GetSplitterWidget();
 GtkWidget *GetTextEntryWidget();
 GtkWidget *GetTreeWidget();
 
-// Set Pango attributes corresponding to the given font for the span 0..len (or
-// without any bounds if len == 0) in the specified layout. Currently only
-// underlined and strike-through attributes are handled by this function.
-//
-// Special "addDummyAttrs" parameter is used to work around a bug in old Pango
-// versions in wxWindowDCImpl::DoDrawText(), see comment there.
-//
-// If neither of them is specified, returns false, otherwise sets up the
-// attributes and returns true.
-//
-// This function is implemented in src/gtk/dcclient.cpp.
-bool
-SetPangoAttrsForFont(const wxFont& font, PangoLayout* layout, size_t len = 0,
-                     bool addDummyAttrs = false);
-
 } // wxGTKPrivate
 
 #endif // _WX_GTK_PRIVATE_H_
-
index 398d319bd8787c552577c21480f770db6d5992c9..9c6b2e11db06355fe4c131f102a5922e8795dfed 100644 (file)
@@ -26,8 +26,6 @@
 #include "wx/gtk/private.h"
 #include "wx/gtk/private/object.h"
 
-using wxGTKPrivate::SetPangoAttrsForFont;
-
 //-----------------------------------------------------------------------------
 // local defines
 //-----------------------------------------------------------------------------
@@ -1411,7 +1409,7 @@ void wxWindowDCImpl::DoDrawText(const wxString& text,
 
     pango_layout_set_text(m_layout, data, datalen);
     const bool
-        setAttrs = SetPangoAttrsForFont(m_font, m_layout, datalen, needshack);
+        setAttrs = m_font.GTKSetPangoAttrs(m_layout, datalen, needshack);
 
     int oldSize = 0;
     const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
@@ -1476,7 +1474,7 @@ void wxWindowDCImpl::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord
         y = YLOG2DEV(y);
 
         pango_layout_set_text(m_layout, wxGTK_CONV(text), -1);
-        SetPangoAttrsForFont( m_font, m_layout );
+        m_font.GTKSetPangoAttrs(m_layout);
         int oldSize = 0;
         const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
         if (isScaled)
@@ -2272,63 +2270,6 @@ int wxWindowDCImpl::GetDepth() const
     return gdk_drawable_get_depth(m_gdkwindow);
 }
 
-bool
-wxGTKPrivate::SetPangoAttrsForFont(const wxFont& font,
-                                   PangoLayout *layout,
-                                   size_t len,
-                                   bool addDummyAttrs)
-{
-    if ( !font.IsOk() || !(font.GetUnderlined() || font.GetStrikethrough()) )
-        return false;
-
-    PangoAttrList* attrs = pango_attr_list_new();
-
-    if ( font.GetUnderlined() )
-    {
-        PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
-        if ( len )
-        {
-            a->start_index = 0;
-            a->end_index = len;
-        }
-        pango_attr_list_insert(attrs, a);
-
-        // Add dummy attributes (use colour as it's invisible anyhow for 0
-        // width spaces) to ensure that the spaces in the beginning/end of the
-        // string are underlined too.
-        if ( addDummyAttrs )
-        {
-            wxASSERT_MSG( len > 2, "Must have 0-width spaces at string ends" );
-
-            a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
-            a->start_index = 0;
-            a->end_index = 1;
-            pango_attr_list_insert(attrs, a);
-
-            a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
-            a->start_index = len - 1;
-            a->end_index = len;
-            pango_attr_list_insert(attrs, a);
-        }
-    }
-
-    if ( font.GetStrikethrough() )
-    {
-        PangoAttribute *a = pango_attr_strikethrough_new( TRUE );
-        if ( len )
-        {
-            a->start_index = 0;
-            a->end_index = len;
-        }
-        pango_attr_list_insert(attrs, a);
-    }
-
-    pango_layout_set_attributes(layout, attrs);
-    pango_attr_list_unref(attrs);
-
-    return true;
-}
-
 //-----------------------------------------------------------------------------
 // wxClientDCImpl
 //-----------------------------------------------------------------------------
index 1ae79d7eb7bbc4f73d2bcc91dc8a2750735e44ec..d8eb88ef9479e0c85101420c2b02b80c45ceed72 100644 (file)
@@ -487,3 +487,57 @@ wxGDIRefData* wxFont::CloneGDIRefData(const wxGDIRefData* data) const
 {
     return new wxFontRefData(*static_cast<const wxFontRefData*>(data));
 }
+
+bool wxFont::GTKSetPangoAttrs(PangoLayout* layout, size_t len, bool addDummyAttrs) const
+{
+    if (!IsOk() || !(GetUnderlined() || GetStrikethrough()))
+        return false;
+
+    PangoAttrList* attrs = pango_attr_list_new();
+    PangoAttribute* a;
+
+    if (GetUnderlined())
+    {
+        a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
+        if (len)
+        {
+            a->start_index = 0;
+            a->end_index = len;
+        }
+        pango_attr_list_insert(attrs, a);
+
+        // Add dummy attributes (use colour as it's invisible anyhow for 0
+        // width spaces) to ensure that the spaces in the beginning/end of the
+        // string are underlined too.
+        if ( addDummyAttrs )
+        {
+            wxASSERT_MSG( len > 2, "Must have 0-width spaces at string ends" );
+
+            a = pango_attr_foreground_new(0x0057, 0x52A9, 0xD614);
+            a->start_index = 0;
+            a->end_index = 1;
+            pango_attr_list_insert(attrs, a);
+
+            a = pango_attr_foreground_new(0x0057, 0x52A9, 0xD614);
+            a->start_index = len - 1;
+            a->end_index = len;
+            pango_attr_list_insert(attrs, a);
+        }
+    }
+
+    if (GetStrikethrough())
+    {
+        a = pango_attr_strikethrough_new(true);
+        if (len)
+        {
+            a->start_index = 0;
+            a->end_index = len;
+        }
+        pango_attr_list_insert(attrs, a);
+    }
+
+    pango_layout_set_attributes(layout, attrs);
+    pango_attr_list_unref(attrs);
+
+    return true;
+}
index bb207524c0a486d3b169b9d5e091eeb64efc67ac..2fd307b42c3b5f4cccd34a6f90a5da715ab0bcb6 100644 (file)
@@ -31,7 +31,6 @@
 #endif
 
 #include "wx/fontutil.h"
-#include "wx/gtk/private.h"
 #include "wx/dynlib.h"
 #include "wx/paper.h"
 
@@ -1740,11 +1739,9 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo
 
     const wxScopedCharBuffer data = text.utf8_str();
 
-    size_t datalen = strlen(data);
-    pango_layout_set_text( m_layout, data, datalen);
+    pango_layout_set_text(m_layout, data, data.length());
 
-    const bool
-      setAttrs = wxGTKPrivate::SetPangoAttrsForFont(m_font, m_layout, datalen);
+    const bool setAttrs = m_font.GTKSetPangoAttrs(m_layout);
     if (m_textForegroundColour.IsOk())
     {
         unsigned char red = m_textForegroundColour.Red();