On 27/05/2009, at 12:34 PM, Graham Cox wrote:


On 27/05/2009, at 12:24 PM, Pierre Berloquin wrote:

That would mean dropping all the niceties of Quartz that lets me draw
outlined text, for one.


That's not the case. The attributes you pass in - drawAtPoint:withAttributes: can include outlines (NSStrokeWidthAttributeName) in different colours (NSStrokeColorAttributeName), shadows (NSShadowAttributeName), underlines and strikethroughs, all in different colours from the main text fill.

Furthermore, the CGContextShowText... methods accept a C string argument, so they can't cope with unicode. Neither can they apply attributes in ranges. Both issues are entirely solved by NSAttributedString. This class has infinitely more "niceties" than raw Quartz text.


Just to be a bit more helpful, since you want to a) display an integer and b) draw it outlined, here's a method that would do so: (warning: typed into mail)

- (void)        drawInt:(int) i atPoint:(NSPoint) p
{
    NSString* str = [NSString stringWithFormat:@"%d", i];
    NSMutableDictionary* attrs = [NSMutableDictionary dictionary];

[attrs setObject:[NSFont fontWithName:@"Helvetica" size:14] forKey:NSFontAttributeName]; // Helvetica 14pt [attrs setObject:[NSNumber numberWithInt:3] forKey:NSStrokeWidthAttributeName]; // outline only, 3% of font size [attrs setObject:[NSColor blackColor] forKey:NSStrokeColorAttributeName]; // black outline

    [str drawAtPoint:p withAttributes:attrs];
}


--Graham


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to