Core Text
From Wikipedia, the free encyclopedia
This article needs additional citations for verification. Please help improve this article by adding reliable references. Unsourced material may be challenged and removed. (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 and ATSUI frameworks in previous versions of Mac OS X. According to Apple, Core Text is "designed for high performance and ease of use" and its layout API is "simple, consistent, and tightly integrated with Core Foundation, Core Graphics, and Cocoa."[1]
Contents |
[edit] Features
Core Text provides the following opaque types:
- CTFramesetter - creates CTFrame objects from given attributed string object and CGPath object using CTTypesetter.
- CTTypesetter - performs line layouts; e.g., line breaking
- CTFrame - represents an array of lines (i.e., CTLine objects).
- CTLine - represents an array of glyph runs; a glyph run is an array of glyphs sharing the same attribute.
- CTFont - represents a font.
[edit] Example
The following code displays the text "Hello, World!" to the given graphics context.
// Prepare font CTFontRef font = CTFontCreateWithName(CFSTR("Times"), 48, NULL); // Create an attributed string CFStringRef keys[] = { kCTFontAttributeName }; CFTypeRef values[] = { font }; CFDictionaryRef attr = CFDictionaryCreate(NULL, (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 CTLineRef line = CTLineCreateWithAttributedString(attrString); CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGContextSetTextPosition(context, 10, 20); CTLineDraw(line, context); // Clean up CFRelease(line); CFRelease(attrString); CFRelease(font);
[edit] References
[edit] External links
|