Add get/set strikeline support to wxFont/x11.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77813 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-09-23 17:41:48 +00:00
parent ae1bc4fa82
commit d2573ed255
2 changed files with 70 additions and 3 deletions

View File

@@ -85,6 +85,7 @@ public:
virtual wxFontStyle GetStyle() const; virtual wxFontStyle GetStyle() const;
virtual wxFontWeight GetWeight() const; virtual wxFontWeight GetWeight() const;
virtual bool GetUnderlined() const; virtual bool GetUnderlined() const;
virtual bool GetStrikethrough() const wxOVERRIDE;
virtual wxString GetFaceName() const; virtual wxString GetFaceName() const;
virtual wxFontEncoding GetEncoding() const; virtual wxFontEncoding GetEncoding() const;
virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual const wxNativeFontInfo *GetNativeFontInfo() const;
@@ -97,6 +98,7 @@ public:
virtual void SetWeight(wxFontWeight weight); virtual void SetWeight(wxFontWeight weight);
virtual bool SetFaceName(const wxString& faceName); virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined); virtual void SetUnderlined(bool underlined);
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;
virtual void SetEncoding(wxFontEncoding encoding); virtual void SetEncoding(wxFontEncoding encoding);
wxDECLARE_COMMON_FONT_METHODS(); wxDECLARE_COMMON_FONT_METHODS();
@@ -116,6 +118,12 @@ public:
// Implementation // Implementation
#if wxUSE_PANGO #if wxUSE_PANGO
// Set Pango attributes in the specified layout. Currently only
// underlined and strike-through attributes are handled by this function.
//
// If neither of them is specified, returns false, otherwise sets up the
// attributes and returns true.
bool SetPangoAttrs(PangoLayout* layout) const;
#else #else
// Find an existing, or create a new, XFontStruct // Find an existing, or create a new, XFontStruct
// based on this wxFont and the given scale. Append the // based on this wxFont and the given scale. Append the

View File

@@ -100,6 +100,7 @@ public:
wxFontStyle style = wxFONTSTYLE_NORMAL, wxFontStyle style = wxFONTSTYLE_NORMAL,
wxFontWeight weight = wxFONTWEIGHT_NORMAL, wxFontWeight weight = wxFONTWEIGHT_NORMAL,
bool underlined = false, bool underlined = false,
bool strikethrough = false,
const wxString& faceName = wxEmptyString, const wxString& faceName = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT); wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
@@ -119,6 +120,7 @@ public:
void SetStyle(wxFontStyle style); void SetStyle(wxFontStyle style);
void SetWeight(wxFontWeight weight); void SetWeight(wxFontWeight weight);
void SetUnderlined(bool underlined); void SetUnderlined(bool underlined);
void SetStrikethrough(bool strikethrough);
bool SetFaceName(const wxString& facename); bool SetFaceName(const wxString& facename);
void SetEncoding(wxFontEncoding encoding); void SetEncoding(wxFontEncoding encoding);
@@ -132,6 +134,7 @@ protected:
wxFontStyle style, wxFontStyle style,
wxFontWeight weight, wxFontWeight weight,
bool underlined, bool underlined,
bool strikethrough,
const wxString& faceName, const wxString& faceName,
wxFontEncoding encoding); wxFontEncoding encoding);
@@ -144,6 +147,7 @@ protected:
wxFontStyle m_style; wxFontStyle m_style;
wxFontWeight m_weight; wxFontWeight m_weight;
bool m_underlined; bool m_underlined;
bool m_strikethrough;
wxString m_faceName; wxString m_faceName;
wxFontEncoding m_encoding; // Unused in Unicode mode wxFontEncoding m_encoding; // Unused in Unicode mode
@@ -169,6 +173,7 @@ void wxFontRefData::Init(int pointSize,
wxFontStyle style, wxFontStyle style,
wxFontWeight weight, wxFontWeight weight,
bool underlined, bool underlined,
bool strikethrough,
const wxString& faceName, const wxString& faceName,
wxFontEncoding encoding) wxFontEncoding encoding)
{ {
@@ -181,6 +186,7 @@ void wxFontRefData::Init(int pointSize,
m_weight = weight == wxDEFAULT ? wxFONTWEIGHT_NORMAL : weight; m_weight = weight == wxDEFAULT ? wxFONTWEIGHT_NORMAL : weight;
m_underlined = underlined; m_underlined = underlined;
m_strikethrough = strikethrough;
m_encoding = encoding; m_encoding = encoding;
#if wxUSE_UNICODE #if wxUSE_UNICODE
@@ -409,11 +415,11 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data )
} }
wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style, wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style,
wxFontWeight weight, bool underlined, wxFontWeight weight, bool underlined, bool strikethrough,
const wxString& faceName, const wxString& faceName,
wxFontEncoding encoding) wxFontEncoding encoding)
{ {
Init(size, family, style, weight, underlined, faceName, encoding); Init(size, family, style, weight, underlined, strikethrough, faceName, encoding);
} }
wxFontRefData::wxFontRefData(const wxString& fontname) wxFontRefData::wxFontRefData(const wxString& fontname)
@@ -508,6 +514,11 @@ void wxFontRefData::SetUnderlined(bool underlined)
// the XLFD doesn't have "underlined" field anyhow // the XLFD doesn't have "underlined" field anyhow
} }
void wxFontRefData::SetStrikethrough(bool strikethrough)
{
m_strikethrough = strikethrough;
}
bool wxFontRefData::SetFaceName(const wxString& facename) bool wxFontRefData::SetFaceName(const wxString& facename)
{ {
m_faceName = facename; m_faceName = facename;
@@ -544,6 +555,9 @@ wxFont::wxFont(const wxNativeFontInfo& info)
info.GetUnderlined(), info.GetUnderlined(),
info.GetFaceName(), info.GetFaceName(),
info.GetEncoding() ); info.GetEncoding() );
if ( info.GetStrikethrough() )
SetStrikethrough(true);
#else #else
(void) Create(info.GetXFontName()); (void) Create(info.GetXFontName());
#endif #endif
@@ -560,7 +574,7 @@ bool wxFont::Create(int pointSize,
UnRef(); UnRef();
m_refData = new wxFontRefData(pointSize, family, style, weight, m_refData = new wxFontRefData(pointSize, family, style, weight,
underlined, faceName, encoding); underlined, false, faceName, encoding);
return true; return true;
} }
@@ -749,6 +763,13 @@ bool wxFont::GetUnderlined() const
return M_FONTDATA->m_underlined; return M_FONTDATA->m_underlined;
} }
bool wxFont::GetStrikethrough() const
{
wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
return M_FONTDATA->m_strikethrough;
}
wxFontEncoding wxFont::GetEncoding() const wxFontEncoding wxFont::GetEncoding() const
{ {
wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
@@ -839,6 +860,13 @@ void wxFont::SetUnderlined(bool underlined)
M_FONTDATA->SetUnderlined(underlined); M_FONTDATA->SetUnderlined(underlined);
} }
void wxFont::SetStrikethrough(bool strikethrough)
{
Unshare();
M_FONTDATA->SetStrikethrough(strikethrough);
}
void wxFont::SetEncoding(wxFontEncoding encoding) void wxFont::SetEncoding(wxFontEncoding encoding)
{ {
Unshare(); Unshare();
@@ -853,6 +881,37 @@ void wxFont::DoSetNativeFontInfo( const wxNativeFontInfo& info )
M_FONTDATA->SetNativeFontInfo( info ); M_FONTDATA->SetNativeFontInfo( info );
} }
#if wxUSE_PANGO
// Although we don't use this function yet, but we must create it here.
// first, for the prepare the unicode drawing support in wxUniv/x11 port.
// If we use pango to draw the text, then we must set some attributes
// for pango layout, such as "strikethrough" and "underline".
bool wxFont::SetPangoAttrs(PangoLayout* layout) 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);
pango_attr_list_insert(attrs, a);
}
if (GetStrikethrough())
{
a = pango_attr_strikethrough_new(true);
pango_attr_list_insert(attrs, a);
}
pango_layout_set_attributes(layout, attrs);
pango_attr_list_unref(attrs);
return true;
}
#endif
#if !wxUSE_UNICODE #if !wxUSE_UNICODE
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------