HOME

TheInfoList



OR:

Core Text is a
Core Foundation Core Foundation (also called CF) is a C application programming interface (API) written by Apple for its operating systems, and is a mix of low-level routines and wrapper functions. Most Core Foundation routines follow a certain naming conventio ...
style API in
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and la ...
, first introduced in Mac OS X 10.4 Tiger, made public in Mac OS X 10.5 Leopard, and introduced for the
iPad The iPad is a brand of iOS and iPadOS-based tablet computers that are developed by Apple Inc., Apple Inc. The iPad was conceived before the related iPhone but the iPhone was developed and released first. Speculation about the development, ...
with iPhone SDK 3.2. Exposing a C API, it replaces the text rendering abilities of the now-deprecated
QuickDraw A quickdraw (also known as an extender) is a piece of climbing equipment used by rock and ice climbers to allow the climbing rope to run freely through protection such as a bolt anchors or other traditional gear while leading. A quickdr ...
and
ATSUI The Apple Type Services for Unicode Imaging (ATSUI) is the set of services for rendering Unicode-encoded text introduced in Mac OS 8.5 and carried forward into Mac OS X. It replaced the WorldScript engine for legacy encodings. Obsolescence ...
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."Core Text Programming Guide: Core Text Overview
/ref>


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. * CTRun - an ordered collection of glyphs sharing the same attribute. * CTFont - represents a font.


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[] = ; CFTypeRef values[] = ; CFDictionaryRef attr = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, sizeof(keys) / sizeof(keys[0]), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFAttributedStringRef attrString = CFAttributedStringCreate(NULL, CFSTR("Hello, World!"), attr); CFRelease(attr); // Draw the string CTLineRef line = CTLineCreateWithAttributedString(attrString); CGContextSetTextMatrix(context, CGAffineTransformIdentity); //Use this one when using standard view coordinates //CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0)); //Use this one if the view's coordinates are flipped CGContextSetTextPosition(context, 10, 20); CTLineDraw(line, context); // Clean up CFRelease(line); CFRelease(attrString); CFRelease(font);


References


External links


Core Text overview
at
Apple Developer Connection Apple Developer (formerly Apple Developer Connection) is Apple Inc.'s website for software development tools, application programming interfaces (APIs), and technical resources. It contains resources to help software developers write software for ...
{{Mac-stub Text rendering libraries macOS APIs