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:
@@ -37,6 +37,7 @@ All (GUI):
|
|||||||
- Fix wxRearrangeList::Check() which asserted and misbehaved before.
|
- Fix wxRearrangeList::Check() which asserted and misbehaved before.
|
||||||
- Optimized wxRTC insertion and deletion when floating objects are present.
|
- Optimized wxRTC insertion and deletion when floating objects are present.
|
||||||
- Added on-demand image loading option to wxRTC.
|
- Added on-demand image loading option to wxRTC.
|
||||||
|
- Add wxFont::GetBaseFont() (Melroy Tellis).
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -507,6 +507,7 @@ WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
|
|||||||
wxFont& Scale(float x); \
|
wxFont& Scale(float x); \
|
||||||
/* functions for creating fonts based on this one */ \
|
/* functions for creating fonts based on this one */ \
|
||||||
wxFont Bold() const; \
|
wxFont Bold() const; \
|
||||||
|
wxFont GetBaseFont() const; \
|
||||||
wxFont Italic() const; \
|
wxFont Italic() const; \
|
||||||
wxFont Underlined() const; \
|
wxFont Underlined() const; \
|
||||||
wxFont Strikethrough() const; \
|
wxFont Strikethrough() const; \
|
||||||
|
@@ -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.
|
Returns the encoding of this font.
|
||||||
|
|
||||||
|
@@ -96,6 +96,8 @@ public:
|
|||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
|
||||||
|
void OnGetBaseFont(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{ DoChangeFont(m_canvas->GetTextFont().GetBaseFont()); }
|
||||||
void OnIncFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(+2); }
|
void OnIncFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(+2); }
|
||||||
void OnDecFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(-2); }
|
void OnDecFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(-2); }
|
||||||
|
|
||||||
@@ -171,6 +173,8 @@ enum
|
|||||||
Font_IncSize,
|
Font_IncSize,
|
||||||
Font_DecSize,
|
Font_DecSize,
|
||||||
|
|
||||||
|
Font_GetBaseFont,
|
||||||
|
|
||||||
Font_Bold,
|
Font_Bold,
|
||||||
Font_Light,
|
Font_Light,
|
||||||
|
|
||||||
@@ -222,6 +226,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(Font_ViewMsg, MyFrame::OnViewMsg)
|
EVT_MENU(Font_ViewMsg, MyFrame::OnViewMsg)
|
||||||
EVT_MENU(Font_About, MyFrame::OnAbout)
|
EVT_MENU(Font_About, MyFrame::OnAbout)
|
||||||
|
|
||||||
|
EVT_MENU(Font_GetBaseFont, MyFrame::OnGetBaseFont)
|
||||||
EVT_MENU(Font_IncSize, MyFrame::OnIncFont)
|
EVT_MENU(Font_IncSize, MyFrame::OnIncFont)
|
||||||
EVT_MENU(Font_DecSize, MyFrame::OnDecFont)
|
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;
|
wxMenu *menuFont = new wxMenu;
|
||||||
menuFont->Append(Font_IncSize, wxT("&Increase font size by 2 points\tCtrl-I"));
|
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_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->AppendSeparator();
|
||||||
menuFont->AppendCheckItem(Font_Bold, wxT("&Bold\tCtrl-B"), wxT("Toggle bold state"));
|
menuFont->AppendCheckItem(Font_Bold, wxT("&Bold\tCtrl-B"), wxT("Toggle bold state"));
|
||||||
menuFont->AppendCheckItem(Font_Light, wxT("&Light\tCtrl-L"), wxT("Toggle light state"));
|
menuFont->AppendCheckItem(Font_Light, wxT("&Light\tCtrl-L"), wxT("Toggle light state"));
|
||||||
|
@@ -510,6 +510,16 @@ wxFont wxFont::Bold() const
|
|||||||
return font;
|
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()
|
wxFont& wxFont::MakeItalic()
|
||||||
{
|
{
|
||||||
SetStyle(wxFONTSTYLE_ITALIC);
|
SetStyle(wxFONTSTYLE_ITALIC);
|
||||||
|
@@ -202,6 +202,13 @@ void FontTestCase::GetSet()
|
|||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CPPUNIT_ASSERT( test.IsOk() );
|
||||||
CPPUNIT_ASSERT_EQUAL( true, test.GetUnderlined() );
|
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()
|
// test Get/SetStrikethrough()
|
||||||
|
|
||||||
// Strike through support not implemented in wxOSX currently.
|
// Strike through support not implemented in wxOSX currently.
|
||||||
|
Reference in New Issue
Block a user