From eaf46c3213fb5cb48ddcb6fe1ebf5e27c15fdf5b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 Aug 2014 12:55:02 +0000 Subject: [PATCH] Fix wxFont construction from default wxFontInfo in wxMSW. Don't use -1 as the real point size. Also update the font sample to allow testing such font. Closes #16468. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/font/font.cpp | 9 +++++++++ src/msw/font.cpp | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/samples/font/font.cpp b/samples/font/font.cpp index 484d049fb6..f774effb89 100644 --- a/samples/font/font.cpp +++ b/samples/font/font.cpp @@ -111,6 +111,7 @@ public: void OnStrikethrough(wxCommandEvent& event); void OnwxPointerFont(wxCommandEvent& event); + void OnFontDefault(wxCommandEvent& event); void OnwxSystemSettingsFont(wxCommandEvent& event); void OnTestTextValue(wxCommandEvent& event); @@ -189,6 +190,7 @@ enum Font_wxSMALL_FONT, Font_wxITALIC_FONT, Font_wxSWISS_FONT, + Font_wxFont_Default, Font_Standard, // wxSystemSettings::GetFont possible objects: @@ -243,6 +245,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Font_wxSMALL_FONT, MyFrame::OnwxPointerFont) EVT_MENU(Font_wxITALIC_FONT, MyFrame::OnwxPointerFont) EVT_MENU(Font_wxSWISS_FONT, MyFrame::OnwxPointerFont) + EVT_MENU(Font_wxFont_Default, MyFrame::OnFontDefault) EVT_MENU(Font_wxSYS_OEM_FIXED_FONT, MyFrame::OnwxSystemSettingsFont) EVT_MENU(Font_wxSYS_ANSI_FIXED_FONT, MyFrame::OnwxSystemSettingsFont) @@ -360,6 +363,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) menuStdFonts->Append(Font_wxSMALL_FONT, wxT("wxSMALL_FONT"), wxT("Small font used by wxWidgets")); menuStdFonts->Append(Font_wxITALIC_FONT, wxT("wxITALIC_FONT"), wxT("Italic font used by wxWidgets")); menuStdFonts->Append(Font_wxSWISS_FONT, wxT("wxSWISS_FONT"), wxT("Swiss font used by wxWidgets")); + menuStdFonts->Append(Font_wxFont_Default, wxT("wxFont()"), wxT("wxFont constructed from default wxFontInfo")); menuSelect->Append(Font_Standard, wxT("Standar&d fonts"), menuStdFonts); wxMenu *menuSettingFonts = new wxMenu; @@ -780,6 +784,11 @@ void MyFrame::OnwxPointerFont(wxCommandEvent& event) DoChangeFont(font); } +void MyFrame::OnFontDefault(wxCommandEvent& WXUNUSED(event)) +{ + DoChangeFont(wxFont(wxFontInfo())); +} + void MyFrame::OnwxSystemSettingsFont(wxCommandEvent& event) { wxFont font; diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 6c747e821e..78786d142d 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -360,7 +360,7 @@ void wxFontRefData::Init(int pointSize, if ( m_sizeUsingPixels ) SetPixelSize(pixelSize); else - SetPointSize(pointSize); + SetPointSize(pointSize == -1 ? wxNORMAL_FONT->GetPointSize() : pointSize); SetStyle(style); SetWeight(weight); @@ -841,7 +841,7 @@ bool wxFont::DoCreate(int pointSize, // wxDEFAULT is a valid value for the font size too so we must treat it // specially here (otherwise the size would be 70 == wxDEFAULT value) - if ( pointSize == wxDEFAULT || pointSize == -1 ) + if ( pointSize == wxDEFAULT ) { pointSize = wxNORMAL_FONT->GetPointSize(); }