Created
January 6, 2011 17:16
-
-
Save rsms/768203 to your computer and use it in GitHub Desktop.
Some ramblings and cut-outs from wwdc presentation on CoreText
This file contains 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
#import <Foundation/Foundation.h> | |
#import <ApplicationServices/ApplicationServices.h> | |
CTFontRef font = CTFontCreateWithName(CFSTR("LucidaGrande"), 11.0, NULL); | |
CFTypeRef keys[] = { kCTFontAttributeName }; | |
CFTypeRef values[] = { font }; | |
CFDictionaryRef attributes = | |
CFDictionaryCreate(kCFAllocatorDefault, | |
(const void**)keys, | |
(const void**)values, | |
sizeof(keys) / sizeof(keys[0]), // CFIndex numValues | |
&kCFTypeDictionaryKeyCallBacks, | |
&kCFTypeDictionaryValueCallBacks); | |
CFAttributedStringRef attributedString = | |
CFAttributedStringCreate(kCFAllocatorDefault, | |
CFSTR("Hello internet"), | |
attributes); | |
// --------- | |
// Drawing a simple line | |
CTLineRef line = CTLineCreateWithAttributedString(attributedString); | |
CGContextRef g = NULL; // TODO | |
CGContextSetTextMatrix(g, CGAffineTransformIdentity); | |
// todo: determine text position, perhaps by measuring line | |
CGContextSetTextPosition(g, 123.0, 456.0); | |
CTLineDraw(line, g); | |
// -------- | |
// Drawing a frame (simple paragraph) | |
CGMutablePathRef path = CGPathCreateMutable(); | |
CGPathAddRect(path, CGAffineTransformIdentity, | |
CGRectMake(0.0, 0.0, 100.0, 100.0)); | |
CTFramesetterRef framesetter = | |
CTFramesetterCreateWithAttributedString(attributedString); | |
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0,0), | |
path, NULL); | |
CTFrameDraw(frame, g); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment