move SetPangoAttrsForFont to wxFont
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -104,6 +104,17 @@ public:
|
|||||||
|
|
||||||
wxDECLARE_COMMON_FONT_METHODS();
|
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
|
// implementation from now on
|
||||||
void Unshare();
|
void Unshare();
|
||||||
|
|
||||||
|
@@ -17,8 +17,6 @@
|
|||||||
#include "wx/gtk/private/string.h"
|
#include "wx/gtk/private/string.h"
|
||||||
#include "wx/gtk/private/gtk2-compat.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
|
// pango_version_check symbol is quite recent ATM (4/2007)... so we
|
||||||
// use our own wrapper which implements a smart trick.
|
// use our own wrapper which implements a smart trick.
|
||||||
// Use this function as you'd use pango_version_check:
|
// Use this function as you'd use pango_version_check:
|
||||||
@@ -113,22 +111,6 @@ GtkWidget *GetSplitterWidget();
|
|||||||
GtkWidget *GetTextEntryWidget();
|
GtkWidget *GetTextEntryWidget();
|
||||||
GtkWidget *GetTreeWidget();
|
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
|
} // wxGTKPrivate
|
||||||
|
|
||||||
#endif // _WX_GTK_PRIVATE_H_
|
#endif // _WX_GTK_PRIVATE_H_
|
||||||
|
|
||||||
|
@@ -26,8 +26,6 @@
|
|||||||
#include "wx/gtk/private.h"
|
#include "wx/gtk/private.h"
|
||||||
#include "wx/gtk/private/object.h"
|
#include "wx/gtk/private/object.h"
|
||||||
|
|
||||||
using wxGTKPrivate::SetPangoAttrsForFont;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// local defines
|
// local defines
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -1411,7 +1409,7 @@ void wxWindowDCImpl::DoDrawText(const wxString& text,
|
|||||||
|
|
||||||
pango_layout_set_text(m_layout, data, datalen);
|
pango_layout_set_text(m_layout, data, datalen);
|
||||||
const bool
|
const bool
|
||||||
setAttrs = SetPangoAttrsForFont(m_font, m_layout, datalen, needshack);
|
setAttrs = m_font.GTKSetPangoAttrs(m_layout, datalen, needshack);
|
||||||
|
|
||||||
int oldSize = 0;
|
int oldSize = 0;
|
||||||
const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
|
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);
|
y = YLOG2DEV(y);
|
||||||
|
|
||||||
pango_layout_set_text(m_layout, wxGTK_CONV(text), -1);
|
pango_layout_set_text(m_layout, wxGTK_CONV(text), -1);
|
||||||
SetPangoAttrsForFont( m_font, m_layout );
|
m_font.GTKSetPangoAttrs(m_layout);
|
||||||
int oldSize = 0;
|
int oldSize = 0;
|
||||||
const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
|
const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
|
||||||
if (isScaled)
|
if (isScaled)
|
||||||
@@ -2272,63 +2270,6 @@ int wxWindowDCImpl::GetDepth() const
|
|||||||
return gdk_drawable_get_depth(m_gdkwindow);
|
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
|
// wxClientDCImpl
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@@ -487,3 +487,57 @@ wxGDIRefData* wxFont::CloneGDIRefData(const wxGDIRefData* data) const
|
|||||||
{
|
{
|
||||||
return new wxFontRefData(*static_cast<const wxFontRefData*>(data));
|
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;
|
||||||
|
}
|
||||||
|
@@ -31,7 +31,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/fontutil.h"
|
#include "wx/fontutil.h"
|
||||||
#include "wx/gtk/private.h"
|
|
||||||
#include "wx/dynlib.h"
|
#include "wx/dynlib.h"
|
||||||
#include "wx/paper.h"
|
#include "wx/paper.h"
|
||||||
|
|
||||||
@@ -1740,11 +1739,9 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo
|
|||||||
|
|
||||||
const wxScopedCharBuffer data = text.utf8_str();
|
const wxScopedCharBuffer data = text.utf8_str();
|
||||||
|
|
||||||
size_t datalen = strlen(data);
|
pango_layout_set_text(m_layout, data, data.length());
|
||||||
pango_layout_set_text( m_layout, data, datalen);
|
|
||||||
|
|
||||||
const bool
|
const bool setAttrs = m_font.GTKSetPangoAttrs(m_layout);
|
||||||
setAttrs = wxGTKPrivate::SetPangoAttrsForFont(m_font, m_layout, datalen);
|
|
||||||
if (m_textForegroundColour.IsOk())
|
if (m_textForegroundColour.IsOk())
|
||||||
{
|
{
|
||||||
unsigned char red = m_textForegroundColour.Red();
|
unsigned char red = m_textForegroundColour.Red();
|
||||||
|
Reference in New Issue
Block a user