> 

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 (Cocoa-dev@lists.apple.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

Reply via email to