Created
November 9, 2008 02:13
-
-
Save ishikawa/23178 to your computer and use it in GitHub Desktop.
Typesetting a simple paragraph by using Core Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) drawText: (NSRect) theRect { | |
const CTFramesetterRef framesetter = | |
CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_text); | |
// Initialize a rectangular path. | |
const CGMutablePathRef path = CGPathCreateMutable(); | |
const CGRect rect = CGRectInset(NSRectToCGRect([self bounds]), 5.0, 5.0); | |
CGPathAddRect(path, NULL, rect); | |
// Create the frame and draw it into the graphics context | |
const CTFrameRef frame = | |
CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL); | |
CFRelease(path); | |
// Initialize a graphics context and set the text matrix to a known value | |
CGContextRef context = (CGContextRef) | |
[[NSGraphicsContext currentContext] graphicsPort]; | |
CGContextSetTextMatrix(context, CGAffineTransformIdentity); | |
CTFrameDraw(frame, context); | |
CFRelease(frame); | |
CFRelease(framesetter); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment