Core Text


Core Text is a Core Foundation style API in macOS, first introduced in Mac OS X 10.4 Tiger, made public in Mac OS X 10.5 Leopard, and introduced for the iPad with iPhone SDK 3.2. Exposing a C API, 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."

Features

Core Text provides the following opaque types:
The following code displays the text "Hello, World!" to the given graphics context.

// Prepare font
CTFontRef font = CTFontCreateWithName;
// Create an attributed string
CFStringRef keys = ;
CFTypeRef values = ;
CFDictionaryRef attr = CFDictionaryCreate&keys, &values,
sizeof / sizeof;
CFAttributedStringRef attrString = CFAttributedStringCreate;
CFRelease;
// Draw the string
CTLineRef line = CTLineCreateWithAttributedString;
CGContextSetTextMatrix; //Use this one when using standard view coordinates
//CGContextSetTextMatrix; //Use this one if the view's coordinates are flipped
CGContextSetTextPosition;
CTLineDraw;
// Clean up
CFRelease;
CFRelease;
CFRelease;