I am trying to determine the size of a piece of text using boundingRectWithSize.
The problem is that this method does not return the correct width. (The height seems to be about right.) Sometimes, the width is only a little bit too wide, sometimes it is much too wide. And I could not find a pattern, it is not just a linear factor. Below is the code snippet that I use. I already did considerable googling but could not find a solution for my problem. (Most posts say that I needed to use the correct options, so I included them, to no avail.) I would appreciate very much all kinds of pointers or suggestions. Best regards, Gabriel NSMutableString * mesg = NULL; ... textLayer_.string = mesg; textLayer_.fontSize = fontSize_; NSStringDrawingContext * ctxt = [NSStringDrawingContext new]; ctxt.minimumScaleFactor = 1.0; NSFont * font = [NSFont fontWithName: @"Andale Mono" size: textLayer_.fontSize ]; NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineBreakMode = NSLineBreakByClipping; NSDictionary * attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil]; NSAttributedString * mesg_string = [[NSAttributedString alloc] initWithString: mesg attributes: attrsDictionary]; NSRect string_rect = CGRectIntegral( [mesg_string boundingRectWithSize: drawRect_.size options: NSStringDrawingUsesLineFragmentOrigin | // NSStringDrawingUsesDeviceMetrics | // tried with and w/o NSStringDrawingUsesFontLeading context: ctxt ] ); string_rect.size.height += 0.2 * textLayer_.fontSize; // for the shadow if ( string_rect.size.width < drawRect_.size.width ) string_rect.size.width *= 0.9; // ???? textLayer_.bounds = string_rect; // set drop shadow textLayer_.shadowPath = CGPathCreateWithRect( string_rect, NULL ); [textLayer_ setNeedsDisplay];
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoaemail@example.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com