Add wxFont::GetBaseFont().

This can be used to "undo" the result of Bold() ,Underlined() or Italic()
methods and returns an unadorned version of the font.

Closes #11815.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76120 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-03-11 20:48:20 +00:00
parent 8b5d2687db
commit b356d1d3c7
6 changed files with 33 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ All (GUI):
- Fix wxRearrangeList::Check() which asserted and misbehaved before.
- Optimized wxRTC insertion and deletion when floating objects are present.
- Added on-demand image loading option to wxRTC.
- Add wxFont::GetBaseFont() (Melroy Tellis).
wxGTK:

View File

@@ -507,6 +507,7 @@ WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
wxFont& Scale(float x); \
/* functions for creating fonts based on this one */ \
wxFont Bold() const; \
wxFont GetBaseFont() const; \
wxFont Italic() const; \
wxFont Underlined() const; \
wxFont Strikethrough() const; \

View File

@@ -607,6 +607,14 @@ public:
*/
//@{
/**
Returns a font with the same face/size as the given one but with normal
weight and style and not underlined nor stricken through.
@since 3.1.0
*/
wxFont GetBaseFont() const;
/**
Returns the encoding of this font.

View File

@@ -96,6 +96,8 @@ public:
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnGetBaseFont(wxCommandEvent& WXUNUSED(event))
{ DoChangeFont(m_canvas->GetTextFont().GetBaseFont()); }
void OnIncFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(+2); }
void OnDecFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(-2); }
@@ -171,6 +173,8 @@ enum
Font_IncSize,
Font_DecSize,
Font_GetBaseFont,
Font_Bold,
Font_Light,
@@ -222,6 +226,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Font_ViewMsg, MyFrame::OnViewMsg)
EVT_MENU(Font_About, MyFrame::OnAbout)
EVT_MENU(Font_GetBaseFont, MyFrame::OnGetBaseFont)
EVT_MENU(Font_IncSize, MyFrame::OnIncFont)
EVT_MENU(Font_DecSize, MyFrame::OnDecFont)
@@ -320,6 +325,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
wxMenu *menuFont = new wxMenu;
menuFont->Append(Font_IncSize, wxT("&Increase font size by 2 points\tCtrl-I"));
menuFont->Append(Font_DecSize, wxT("&Decrease font size by 2 points\tCtrl-D"));
menuFont->Append(Font_GetBaseFont, wxT("Use &base version of the font\tCtrl-0"));
menuFont->AppendSeparator();
menuFont->AppendCheckItem(Font_Bold, wxT("&Bold\tCtrl-B"), wxT("Toggle bold state"));
menuFont->AppendCheckItem(Font_Light, wxT("&Light\tCtrl-L"), wxT("Toggle light state"));

View File

@@ -510,6 +510,16 @@ wxFont wxFont::Bold() const
return font;
}
wxFont wxFont::GetBaseFont() const
{
wxFont font(*this);
font.SetStyle(wxFONTSTYLE_NORMAL);
font.SetWeight(wxFONTWEIGHT_NORMAL );
font.SetUnderlined(false);
font.SetStrikethrough(false);
return font;
}
wxFont& wxFont::MakeItalic()
{
SetStyle(wxFONTSTYLE_ITALIC);

View File

@@ -202,6 +202,13 @@ void FontTestCase::GetSet()
CPPUNIT_ASSERT( test.IsOk() );
CPPUNIT_ASSERT_EQUAL( true, test.GetUnderlined() );
const wxFont fontBase = test.GetBaseFont();
CPPUNIT_ASSERT( fontBase.IsOk() );
CPPUNIT_ASSERT( !fontBase.GetUnderlined() );
CPPUNIT_ASSERT( !fontBase.GetStrikethrough() );
CPPUNIT_ASSERT_EQUAL( wxFONTWEIGHT_NORMAL, fontBase.GetWeight() );
CPPUNIT_ASSERT_EQUAL( wxFONTSTYLE_NORMAL, fontBase.GetStyle() );
// test Get/SetStrikethrough()
// Strike through support not implemented in wxOSX currently.