Avoid unnecessary calls in wxGDIPlusContext::GetTextExtent()
Don't always call several GDI+ functions when we often don't need their results: only retrieve the cell descent, ascent and the line spacing if we are going to really use any of these values.
This commit is contained in:
@@ -2111,9 +2111,12 @@ void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDo
|
|||||||
wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") );
|
wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") );
|
||||||
|
|
||||||
wxWCharBuffer s = str.wc_str( *wxConvUI );
|
wxWCharBuffer s = str.wc_str( *wxConvUI );
|
||||||
FontFamily ffamily ;
|
|
||||||
Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont();
|
Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont();
|
||||||
|
|
||||||
|
// Get the font metrics if we actually need them.
|
||||||
|
if ( descent || externalLeading || (height && str.empty()) )
|
||||||
|
{
|
||||||
|
FontFamily ffamily ;
|
||||||
f->GetFamily(&ffamily) ;
|
f->GetFamily(&ffamily) ;
|
||||||
|
|
||||||
REAL factorY = m_fontScaleRatio;
|
REAL factorY = m_fontScaleRatio;
|
||||||
@@ -2127,17 +2130,21 @@ void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDo
|
|||||||
REAL rAscent = ffamily.GetCellAscent(style) * size / emHeight;
|
REAL rAscent = ffamily.GetCellAscent(style) * size / emHeight;
|
||||||
REAL rHeight = ffamily.GetLineSpacing(style) * size / emHeight;
|
REAL rHeight = ffamily.GetLineSpacing(style) * size / emHeight;
|
||||||
|
|
||||||
if ( height )
|
if ( height && str.empty() )
|
||||||
*height = rHeight * factorY;
|
*height = rHeight * factorY;
|
||||||
if ( descent )
|
if ( descent )
|
||||||
*descent = rDescent * factorY;
|
*descent = rDescent * factorY;
|
||||||
if ( externalLeading )
|
if ( externalLeading )
|
||||||
*externalLeading = (rHeight - rAscent - rDescent) * factorY;
|
*externalLeading = (rHeight - rAscent - rDescent) * factorY;
|
||||||
|
}
|
||||||
|
|
||||||
// measuring empty strings is not guaranteed, so do it by hand
|
// measuring empty strings is not guaranteed, so do it by hand
|
||||||
if ( str.IsEmpty())
|
if ( str.IsEmpty())
|
||||||
{
|
{
|
||||||
if ( width )
|
if ( width )
|
||||||
*width = 0 ;
|
*width = 0 ;
|
||||||
|
|
||||||
|
// Height already assigned above if necessary.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user