• 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: Displaying a number with Quartz
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Displaying a number with Quartz


  • Subject: Re: Displaying a number with Quartz
  • From: Graham Cox <email@hidden>
  • Date: Wed, 27 May 2009 12:50:06 +1000


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 (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: 
 >Displaying a number with Quartz (From: Pierre Berloquin <email@hidden>)
 >Re: Displaying a number with Quartz (From: Alexander Spohr <email@hidden>)
 >Re: Displaying a number with Quartz (From: "Sean McBride" <email@hidden>)
 >Re: Displaying a number with Quartz (From: Alexander Spohr <email@hidden>)
 >Re: Displaying a number with Quartz (From: "Sean McBride" <email@hidden>)
 >Re: Displaying a number with Quartz (From: Pierre Berloquin <email@hidden>)
 >Re: Displaying a number with Quartz (From: Gunnar Proppe <email@hidden>)
 >Re: Displaying a number with Quartz (From: Pierre Berloquin <email@hidden>)
 >Re: Displaying a number with Quartz (From: Graham Cox <email@hidden>)

  • Prev by Date: Filling a Bezier path with a texture
  • Next by Date: Re: Filling a Bezier path with a texture
  • Previous by thread: Re: Displaying a number with Quartz
  • Next by thread: Re: Displaying a number with Quartz
  • Index(es):
    • Date
    • Thread