From c7e99122a0f181d199be3ec6c3928109c2bdf76b Mon Sep 17 00:00:00 2001 From: Paul Cornett <paulcor@bullseye.com> Date: Sun, 29 Jan 2012 08:00:15 +0000 Subject: [PATCH] move SetPangoAttrsForFont to wxFont git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/font.h | 11 +++++++ include/wx/gtk/private.h | 18 ------------ src/gtk/dcclient.cpp | 63 ++-------------------------------------- src/gtk/font.cpp | 54 ++++++++++++++++++++++++++++++++++ src/gtk/print.cpp | 7 ++--- 5 files changed, 69 insertions(+), 84 deletions(-) diff --git a/include/wx/gtk/font.h b/include/wx/gtk/font.h index d1c04e2d8b..8d1168f0e0 100644 --- a/include/wx/gtk/font.h +++ b/include/wx/gtk/font.h @@ -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(); diff --git a/include/wx/gtk/private.h b/include/wx/gtk/private.h index 2bf984ce45..43d85125c7 100644 --- a/include/wx/gtk/private.h +++ b/include/wx/gtk/private.h @@ -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_ - diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 398d319bd8..9c6b2e11db 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -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 //----------------------------------------------------------------------------- diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 1ae79d7eb7..d8eb88ef94 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -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; +} diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index bb207524c0..2fd307b42c 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -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(); -- 2.47.2