Created
January 29, 2010 08:42
-
-
Save cxa/289563 to your computer and use it in GitHub Desktop.
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
- (void)drawRect:(NSRect)rect | |
{ | |
// Drawing code here. | |
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | |
CGContextSetTextMatrix(context, CGAffineTransformIdentity); | |
NSAttributedString *str = [[NSAttributedString alloc ] | |
initWithString:@"学习 Core Text. Learning Core Text. 中华人民共和国。" | |
attributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Adobe Song Std" size:24.0f], (NSString *)kCTFontAttributeName, [NSNumber numberWithBool:YES], (NSString *)kCTVerticalFormsAttributeName, nil]]; | |
CFAttributedStringRef attrString = (CFAttributedStringRef)str; | |
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString); | |
CGMutablePathRef path = CGPathCreateMutable(); | |
CGRect bounds = CGRectMake(10.0, 10.0, 200.0, 200.0); | |
CGPathAddRect(path, NULL, bounds); | |
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCTFrameProgressionRightToLeft], (NSString *)kCTFrameProgressionAttributeName, nil]); | |
CTFrameDraw(frame, context); | |
CFRelease(attrString); | |
CFRelease(framesetter); | |
CFRelease(frame); | |
CFRelease(path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment