use FixedToFloat everywhere to make sure we don't round too early, preserve fractional width with CoreText as well

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2011-03-06 15:27:44 +00:00
parent e418552365
commit 7dbda71e4b

View File

@@ -2387,8 +2387,8 @@ void wxMacCoreGraphicsContext::DoDrawRotatedText(const wxString &str,
wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
Rect rect; Rect rect;
x += (int)(sin(angle) * FixedToInt(ascent)); x += (int)(sin(angle) * FixedToFloat(ascent));
y += (int)(cos(angle) * FixedToInt(ascent)); y += (int)(cos(angle) * FixedToFloat(ascent));
status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
IntToFixed(x) , IntToFixed(y) , &rect ); IntToFixed(x) , IntToFixed(y) , &rect );
@@ -2446,13 +2446,8 @@ 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) );
// round the returned extent: this is probably more correct anyhow but CGFloat a, d, l, w;
// we also need to do it to be consistent with GetPartialTextExtents() w = CTLineGetTypographicBounds(line, &a, &d, &l);
// 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;
int w = CTLineGetTypographicBounds(line, &a, &d, &l) + 0.5;
if ( height ) if ( height )
*height = a+d+l; *height = a+d+l;
@@ -2489,13 +2484,13 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
&textBefore , &textAfter, &textAscent , &textDescent ); &textBefore , &textAfter, &textAscent , &textDescent );
if ( height ) if ( height )
*height = FixedToInt(textAscent + textDescent); *height = FixedToFloat(textAscent + textDescent);
if ( descent ) if ( descent )
*descent = FixedToInt(textDescent); *descent = FixedToFloat(textDescent);
if ( externalLeading ) if ( externalLeading )
*externalLeading = 0; *externalLeading = 0;
if ( width ) if ( width )
*width = FixedToInt(textAfter - textBefore); *width = FixedToFloat(textAfter - textBefore);
::ATSUDisposeTextLayout(atsuLayout); ::ATSUDisposeTextLayout(atsuLayout);
@@ -2512,7 +2507,7 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
*height = sz.height; *height = sz.height;
/* /*
if ( descent ) if ( descent )
*descent = FixedToInt(textDescent); *descent = FixedToFloat(textDescent);
if ( externalLeading ) if ( externalLeading )
*externalLeading = 0; *externalLeading = 0;
*/ */
@@ -2583,7 +2578,7 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr
if (result != noErr || actualNumberOfBounds != 1 ) if (result != noErr || actualNumberOfBounds != 1 )
return; return;
widths[pos] = FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x ); widths[pos] = FixedToFloat( glyphBounds.upperRight.x - glyphBounds.upperLeft.x );
//unsigned char uch = s[i]; //unsigned char uch = s[i];
} }
#else #else
@@ -2603,7 +2598,7 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr
{ {
for ( int pos = 1; pos < (int)glyphCount ; pos ++ ) for ( int pos = 1; pos < (int)glyphCount ; pos ++ )
{ {
widths[pos-1] = FixedToInt( layoutRecords[pos].realPos ); widths[pos-1] = FixedToFloat( layoutRecords[pos].realPos );
} }
} }