Support using GetTextExtent() with empty string to get descent in wxOSX.
Allow measuring the descent and external leading of an empty string by measuring just a space instead in wxOSX. This makes the behaviour more consistent with wxMSW and makes the unit test added in r74464 pass under OS X too. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74524 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2512,15 +2512,19 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
|
|||||||
if ( externalLeading )
|
if ( externalLeading )
|
||||||
*externalLeading = 0;
|
*externalLeading = 0;
|
||||||
|
|
||||||
|
// In wxWidgets (MSW-inspired) API it is possible to call GetTextExtent()
|
||||||
|
// with an empty string to get just the descent and the leading of the
|
||||||
|
// font, so support this (mis)use.
|
||||||
|
wxString strToMeasure(str);
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
return;
|
strToMeasure = wxS(" ");
|
||||||
|
|
||||||
#if wxOSX_USE_CORE_TEXT
|
#if wxOSX_USE_CORE_TEXT
|
||||||
{
|
{
|
||||||
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
|
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
|
||||||
CTFontRef font = fref->OSXGetCTFont();
|
CTFontRef font = fref->OSXGetCTFont();
|
||||||
|
|
||||||
wxCFStringRef text(str, wxLocale::GetSystemEncoding() );
|
wxCFStringRef text(strToMeasure, wxLocale::GetSystemEncoding() );
|
||||||
CFStringRef keys[] = { kCTFontAttributeName };
|
CFStringRef keys[] = { kCTFontAttributeName };
|
||||||
CFTypeRef values[] = { font };
|
CFTypeRef values[] = { font };
|
||||||
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
|
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
|
||||||
@@ -2531,14 +2535,18 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
|
|||||||
CGFloat a, d, l, w;
|
CGFloat a, d, l, w;
|
||||||
w = CTLineGetTypographicBounds(line, &a, &d, &l);
|
w = CTLineGetTypographicBounds(line, &a, &d, &l);
|
||||||
|
|
||||||
|
if ( !str.empty() )
|
||||||
|
{
|
||||||
|
if ( width )
|
||||||
|
*width = w;
|
||||||
if ( height )
|
if ( height )
|
||||||
*height = a+d+l;
|
*height = a+d+l;
|
||||||
|
}
|
||||||
|
|
||||||
if ( descent )
|
if ( descent )
|
||||||
*descent = d;
|
*descent = d;
|
||||||
if ( externalLeading )
|
if ( externalLeading )
|
||||||
*externalLeading = l;
|
*externalLeading = l;
|
||||||
if ( width )
|
|
||||||
*width = w;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2547,7 +2555,7 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
|
|||||||
OSStatus status = noErr;
|
OSStatus status = noErr;
|
||||||
|
|
||||||
ATSUTextLayout atsuLayout;
|
ATSUTextLayout atsuLayout;
|
||||||
wxMacUniCharBuffer unibuf( str );
|
wxMacUniCharBuffer unibuf( strToMeasure );
|
||||||
UniCharCount chars = unibuf.GetChars();
|
UniCharCount chars = unibuf.GetChars();
|
||||||
|
|
||||||
ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle());
|
ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle());
|
||||||
@@ -2565,14 +2573,18 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
|
|||||||
status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
|
status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
|
||||||
&textBefore , &textAfter, &textAscent , &textDescent );
|
&textBefore , &textAfter, &textAscent , &textDescent );
|
||||||
|
|
||||||
|
if ( !str.empty() )
|
||||||
|
{
|
||||||
|
if ( width )
|
||||||
|
*width = FixedToFloat(textAfter - textBefore);
|
||||||
if ( height )
|
if ( height )
|
||||||
*height = FixedToFloat(textAscent + textDescent);
|
*height = FixedToFloat(textAscent + textDescent);
|
||||||
|
}
|
||||||
|
|
||||||
if ( descent )
|
if ( descent )
|
||||||
*descent = FixedToFloat(textDescent);
|
*descent = FixedToFloat(textDescent);
|
||||||
if ( externalLeading )
|
if ( externalLeading )
|
||||||
*externalLeading = 0;
|
*externalLeading = 0;
|
||||||
if ( width )
|
|
||||||
*width = FixedToFloat(textAfter - textBefore);
|
|
||||||
|
|
||||||
::ATSUDisposeTextLayout(atsuLayout);
|
::ATSUDisposeTextLayout(atsuLayout);
|
||||||
|
|
||||||
@@ -2582,19 +2594,23 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
|
|||||||
#if wxOSX_USE_IPHONE
|
#if wxOSX_USE_IPHONE
|
||||||
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
|
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
|
||||||
|
|
||||||
wxCFStringRef text(str, wxLocale::GetSystemEncoding() );
|
wxCFStringRef text(strToMeasure, wxLocale::GetSystemEncoding() );
|
||||||
CGSize sz = MeasureTextInContext( fref->GetUIFont() , text.AsNSString() );
|
CGSize sz = MeasureTextInContext( fref->GetUIFont() , text.AsNSString() );
|
||||||
|
|
||||||
|
if ( !str.empty() )
|
||||||
|
{
|
||||||
|
if ( width )
|
||||||
|
*width = sz.width;
|
||||||
if ( height )
|
if ( height )
|
||||||
*height = sz.height;
|
*height = sz.height;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if ( descent )
|
if ( descent )
|
||||||
*descent = FixedToFloat(textDescent);
|
*descent = FixedToFloat(textDescent);
|
||||||
if ( externalLeading )
|
if ( externalLeading )
|
||||||
*externalLeading = 0;
|
*externalLeading = 0;
|
||||||
*/
|
*/
|
||||||
if ( width )
|
|
||||||
*width = sz.width;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CheckInvariants();
|
CheckInvariants();
|
||||||
|
Reference in New Issue
Block a user