diff --git a/docs/changes.txt b/docs/changes.txt index d9397e54b0..6722097017 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -478,6 +478,7 @@ MSW: - Added support for wxEXEC_MAKE_GROUP_LEADER to wxExecute (tteras). - Set wxMenu being closed in wxEVT_MENU_CLOSE events (Marcin Malich). - Fix coordinates and Z-position for joystick events (Markus Juergens). +- Fix size of the font returned by wxTextCtrl::GetStyle() (Igor Korot). OSX: diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index d62b8ab161..ef2b7a8989 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2744,7 +2744,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) // Convert the height from the units of 1/20th of the point in which // CHARFORMAT stores it to pixel-based units used by LOGFONT. const wxCoord ppi = wxClientDC(this).GetPPI().y; - lf.lfHeight = -MulDiv(cf.yHeight/2, ppi, 72); + lf.lfHeight = -MulDiv(cf.yHeight/20, ppi, 72); lf.lfWidth = 0; lf.lfCharSet = ANSI_CHARSET; // FIXME: how to get correct charset? lf.lfClipPrecision = 0; diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 4ab4e82367..5836e68bc1 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -57,6 +57,7 @@ private: //WXUISIM_TEST( ProcessEnter ); WXUISIM_TEST( Url ); CPPUNIT_TEST( Style ); + CPPUNIT_TEST( FontStyle ); CPPUNIT_TEST( Lines ); CPPUNIT_TEST( LogTextCtrl ); CPPUNIT_TEST( PositionToCoords ); @@ -72,6 +73,7 @@ private: //void ProcessEnter(); void Url(); void Style(); + void FontStyle(); void Lines(); void LogTextCtrl(); void PositionToCoords(); @@ -386,6 +388,62 @@ void TextCtrlTestCase::Style() #endif } +void TextCtrlTestCase::FontStyle() +{ + // We need wxTE_RICH under MSW and wxTE_MULTILINE under GTK for style + // support so recreate the control with these styles. + delete m_text; + m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "", + wxDefaultPosition, wxDefaultSize, + wxTE_MULTILINE | wxTE_RICH); + + // Check that we get back the same font from GetStyle() after setting it + // with SetDefaultStyle(). + wxFont fontIn(14, + wxFONTFAMILY_DEFAULT, + wxFONTSTYLE_NORMAL, + wxFONTWEIGHT_NORMAL); + wxTextAttr attrIn; + attrIn.SetFont(fontIn); + if ( !m_text->SetDefaultStyle(attrIn) ) + { + // Skip the test if the styles are not supported. + return; + } + + m_text->AppendText("Default font size 14"); + + wxTextAttr attrOut; + m_text->GetStyle(5, attrOut); + + CPPUNIT_ASSERT( attrOut.HasFont() ); + + wxFont fontOut = attrOut.GetFont(); +#ifdef __WXMSW__ + // Under MSW we get back an encoding in the font even though we hadn't + // specified it originally. It's not really a problem but we need this hack + // to prevent the assert below from failing because of it. + fontOut.SetEncoding(fontIn.GetEncoding()); +#endif + CPPUNIT_ASSERT_EQUAL( fontIn, fontOut ); + + + // Also check the same for SetStyle(). + fontIn.SetPointSize(10); + fontIn.SetWeight(wxFONTWEIGHT_BOLD); + attrIn.SetFont(fontIn); + m_text->SetStyle(0, 6, attrIn); + + m_text->GetStyle(4, attrOut); + CPPUNIT_ASSERT( attrOut.HasFont() ); + + fontOut = attrOut.GetFont(); +#ifdef __WXMSW__ + fontOut.SetEncoding(fontIn.GetEncoding()); +#endif + CPPUNIT_ASSERT_EQUAL( fontIn, fontOut ); +} + void TextCtrlTestCase::Lines() { delete m_text;