Core Text
Appearance
This article needs additional citations for verification. (September 2007) |
Core Text is a CoreFoundation style API in Mac OS X, first introduced in Mac OS X 10.4 Tiger and made public in Mac OS X 10.5 Leopard. Written in C, it replaces the text rendering abilities of the now-deprecated QuickDraw framework in previous versions of Mac OS X.
Example
The following code displays the text "Hello, World!" to the given graphics context.
// Prepare font and color CTFont font = CTFontCreateWithName (CFSTR ("Times"), 48, NULL); // use the default text matrix CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB (); CGFloat components[] = { 0.0, 0.0, 1.0, 1.0 }; CGColorRef color = CGColorCreate (colorSpace, components); CGColorSpaceRelease (colorSpace); // Create an attributed string CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName }; CFTypeRef values[] = { font, color }; CFDictionaryRef attr = CFDictionaryCreate (kCFAllocatorDefault, (const void**) &keys, (const void**) &values, sizeof (keys) / sizeof (keys[0]), NULL, NULL); CFAttributedStringRef attrString = CFAttributedStringCreate (NULL, CFSTR ("Hello, World!"), attr); CFRelease (attr); // Draw the string to context CTLine line = CTLineCreateWithAttributedString (attrString); CTLineDraw (line, context); CFRelease (line); // Cleanup CFRelease (attrString); CFRelease (font); CFRelease (color);