Low-level text, why so hard?
Low-level text, why so hard?
- Subject: Low-level text, why so hard?
- From: Graham Cox <email@hidden>
- Date: Mon, 24 Dec 2012 16:32:29 +1100
I need to use Quartz to draw a single character - a check mark - in a graphics context. I don't need anything elaborate, no typesetting etc, I just want to draw a single checkmark.
However, Quartz seemingly makes the trivial very difficult. Why for example, does this code not work? Specifically, it returns 0 from CGFontGetGlyphWithGlyphName meaning that the glyph name is unknown. But I see it right there in the 'Special Characters' palette. The alternative of use the CGShowTextAtPoint is no use either, because it only support MacRoman or 'font specific' encoding, neither of which apparently allow unicode, at least as far as the API is presented. The check mark has a unicode value of 0x2713, so can't be represented by a char.
The higher-level string drawing methods are not really appropriate here because this is part of a -drawInContext: method of a custom CALayer. It also has to work across iOS and Mac.
C'mon, this has got to be easy, hasn't it?
CGFontRef font = CGFontCreateWithFontName( CFSTR("Lucida Grande"));
CGContextSetFont( ctx, font );
CGContextSetFontSize( ctx, 16 );
CGGlyph cv = CGFontGetGlyphWithGlyphName( font, CFSTR("CHECK MARK"));
if( self.value > 0 )
{
CGAffineTransform tfm = CGAffineTransformMakeScale( 1.0, -1.0 );
CGContextSetTextMatrix( ctx, tfm );
CGContextShowGlyphsAtPoint( ctx, sr.origin.x + 2.0, sr.origin.y + sr.size.height, &cv, 1 );
}
CGFontRelease( font );
--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