CoreText - CTFrameDraw doesn't draw paragraph's last line
CoreText - CTFrameDraw doesn't draw paragraph's last line
- Subject: CoreText - CTFrameDraw doesn't draw paragraph's last line
- From: Robert Vojta <email@hidden>
- Date: Fri, 26 Nov 2010 14:12:09 +0100
Hi all,
I'm trying to solve my CoreText problem with paragraph text drawing. It draws my paragraph perfectly, but it doesn't draw the last line in some cases. I have no idea why.
Here's the frame size calculation method ...
- (CGSize)sizeThatFits:(CGSize)size {
CFRange labelFitRange;
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString( __labelData.attributedString );
CGSize labelSize = CTFramesetterSuggestFrameSizeWithConstraints( framesetter, CFRangeMake( 0, 0 ),
NULL, CGSizeMake( size.width, CGFLOAT_MAX ), &labelFitRange );
CFRelease( framesetter );
if ( labelFitRange.location != 0 || labelFitRange.length != CFAttributedStringGetLength( __labelData.attributedString ) ) {
NSLog( @"The whole string doesn't fit. Range: %d.%d != 0.%d", (int)labelFitRange.location, (int)labelFitRange.length,
(int)CFAttributedStringGetLength( __labelData.attributedString ) );
}
return labelSize;
}
... and here's the -drawRect:(CGRect)rect method ...
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState( ctx );
CGContextTranslateCTM( ctx, 0, rect.size.height );
CGContextScaleCTM( ctx, 1.0f, -1.0f );
CGContextSetTextMatrix( ctx, CGAffineTransformIdentity );
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect( path, NULL, rect );
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString( __labelData.attributedString );
CTFrameRef frame = CTFramesetterCreateFrame( framesetter, CFRangeMake( 0, 0 ), path, NULL );
CTFrameDraw( frame, ctx );
CGPathRelease( path );
CFRelease( frame );
CFRelease( framesetter );
CGContextRestoreGState( ctx );
}
... -sizeThatFits: returns numbers like 654.98 x 129.18, etc. I mean not integers. And when I set the UIView (my label) frame to this size, paragraph text is visible, but the last line is not drawn sometimes (some paragraphs have all lines, some of them are missing the last line). I tried everything, even I was trying to ceil numbers before assigning UIView's frame, I removed all string attributes, etc. but nothing helps.
Interesting things is, that iOS 3.2.x is much more affected when compared to the 4.2.1 where number of paragraphs (same text as on 3.2.x) without the last line is much lower.
Any idea what can be wrong?
Regards,
Robert
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden