• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: boundingRectWithSize gives wrong size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: boundingRectWithSize gives wrong size


  • Subject: Re: boundingRectWithSize gives wrong size
  • From: Gabriel Zachmann via Cocoa-dev <email@hidden>
  • Date: Wed, 11 Sep 2019 21:07:12 +0200

>

I must confess that I made the mistake of calculating the size of the text
using the attributed string,
but I did *not* assign the attributed string to the text layer, but instead I
assigned the orig. plain string.
That way, the text layer must have used a different font for rendering the text,
different from the font that CTFramesetterSuggestFrameSizeWithConstraints() used
(as specified in the attributed string).
Argh.


So, for the record, in case other people might have a similar problem some time
in the future, too,
I am enclosing my current version of the code below.


And thanks again! Your suggestions kept me experimenting.
Best regards, Gabriel


Encl.:

    NSFont * font = [NSFont fontWithName: @"Andale Mono" size: fontSize_ ];
    if ( ! font )
        [self logMessage: @"Could not find font Andale Mono!" asError: YES];
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc]
init];
    paragraphStyle.lineBreakMode = NSLineBreakByClipping;
    NSColor *color = [NSColor whiteColor];
    NSDictionary * attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                      font, NSFontAttributeName,
                                      color, NSForegroundColorAttributeName,
                                      paragraphStyle,
NSParagraphStyleAttributeName,
                                      nil];
    NSAttributedString * mesg_attrstring = [[NSAttributedString alloc]
initWithString: mesg

attributes: attrsDictionary];

    textLayer_.string = mesg_attrstring;
    textLayer_.fontSize = fontSize_;                                    // not
sure this is actually needed

    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(
(__bridge CFAttributedStringRef) mesg_attrstring );
    CFRange mesg_string_range;
    CGSize string_rect = CTFramesetterSuggestFrameSizeWithConstraints(
framesetter, CFRangeMake(0,0), NULL, drawRect_.size, & mesg_string_range );

    textLayer_.bounds = CGRectMake( 0.0, 0.0, string_rect.width,
string_rect.height );
    textLayer_.shadowPath = CGPathCreateWithRect( textLayer_.bounds, NULL );
                  // set drop shadow

    [textLayer_ setNeedsDisplay];


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >Re: boundingRectWithSize gives wrong size (From: Gabriel Zachmann via Cocoa-dev <email@hidden>)
 >Re: boundingRectWithSize gives wrong size (From: Jens Alfke via Cocoa-dev <email@hidden>)

  • Prev by Date: Re: boundingRectWithSize gives wrong size
  • Next by Date: 10.15 command line tools headers missing
  • Previous by thread: Re: boundingRectWithSize gives wrong size
  • Next by thread: Re: boundingRectWithSize gives wrong size
  • Index(es):
    • Date
    • Thread