Fix discrepancy between different ways of measuring text extents under Mac.
wxGraphicsContext::GetTextExtent() didn't round the returned double result to int but truncated it instead and so returned different extent than GetPartialTextExtents() which did round it up. Moreover, wxGraphicsContext::GetPartialTextExtents() didn't round it up correctly: it wrongly added 0.5 to the value still stored as double and which was hence rounded up (correctly, this time) when converted to int in wxDC::GetPartialTextExtents(). These two errors combined to produce difference of up to 2 pixels between the last offset returned by wxDC::GetPartialTextExtents() and the total string extent returned by wxDC::GetTextExtent() which thoroughly confused the code in wxControlBase::DoEllipsizeSingleLine() (and probably not only there). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62580 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2349,10 +2349,13 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
|
|||||||
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) );
|
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) );
|
||||||
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
|
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
|
||||||
|
|
||||||
double w;
|
// round the returned extent: this is probably more correct anyhow but
|
||||||
|
// we also need to do it to be consistent with GetPartialTextExtents()
|
||||||
|
// below and avoid strange situation when the last partial extent
|
||||||
|
// returned by it could have been greater than the full extent returned
|
||||||
|
// by us
|
||||||
CGFloat a, d, l;
|
CGFloat a, d, l;
|
||||||
|
int w = CTLineGetTypographicBounds(line, &a, &d, &l) + 0.5;
|
||||||
w = CTLineGetTypographicBounds(line, &a, &d, &l) ;
|
|
||||||
|
|
||||||
if ( height )
|
if ( height )
|
||||||
*height = a+d+l;
|
*height = a+d+l;
|
||||||
@@ -2447,7 +2450,7 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr
|
|||||||
int chars = text.length();
|
int chars = text.length();
|
||||||
for ( int pos = 0; pos < (int)chars; pos ++ )
|
for ( int pos = 0; pos < (int)chars; pos ++ )
|
||||||
{
|
{
|
||||||
widths[pos] = CTLineGetOffsetForStringIndex( line, pos+1 , NULL )+0.5;
|
widths[pos] = CTLineGetOffsetForStringIndex( line, pos+1 , NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user