Fix the size of the font returned from wxTextCtrl::GetStyle() in wxMSW.

Due to a typo the size was expressed in 1/10th of a point and not in points.
Fix this and add a unit test checking that GetStyle() returns the same font as
was set by SetStyle().

Closes #2120.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70341 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-01-14 17:57:11 +00:00
parent 821073e386
commit be74a2a21a
3 changed files with 60 additions and 1 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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;