Core Text

Core Text

Core Text is a Core Foundation style API in Mac OS X, 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."[1]

Contents

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[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
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

  1. ^ Core Text Programming Guide: Core Text Overview

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Core Data — Developer(s) Apple Inc. Stable release 3.2.0 Operating syst …   Wikipedia

  • Core Audio — Developer(s) Apple Inc. Stable release 3.2.6 Operating system Mac OS X, iOS …   Wikipedia

  • Core Foundation — (also called CF) is a C application programming interface (API) in Mac OS X iOS, and is a mix of low level routines and wrapper functions. Apple releases most of it as an open source project called CFLite that can be used to write cross platform… …   Wikipedia

  • Core Animation — (Графическая модель Mac OS X) Тип System Utility Разработчик Apple Inc. Операционная система Mac OS X Лицензия Проприетарн …   Википедия

  • Core Services — are a set of Mac OS X and iOS application programming interfaces that architecturally are underneath Carbon, Cocoa and Cocoa Touch. In addition to Core Foundation,[1] it also encompasses other APIs including Grand Central Dispatch, Blocks,… …   Wikipedia

  • Core Image — Mac OS X graphics model Rendering QuickDraw • Core OpenGL Quartz 2D • Core Image Core Animation • …   Wikipedia

  • Core Video — Mac OS X graphics model Rendering QuickDraw • Core OpenGL Quartz 2D • Core Image Core Animation • Core Video ColorSync …   Wikipedia

  • Core OpenGL — Mac OS X graphics model Rendering QuickDraw • Core OpenGL Quartz 2D • Core Image Core Animation • Core Video ColorSync • QuickTime Compositing …   Wikipedia

  • Core Animation — Mac OS X graphics model Rendering QuickDraw • Core OpenGL Quartz 2D • Core Image Core Animation • Core Video Color …   Wikipedia

  • CORE (advertising media) — CORE Core is an advertising agency. Core was founded in St. Louis, Missouri, in 1995 by Marc Kempter Core has three major divisions: a full service advertising agency; Core Audiovisual; Core Content.Core was named in Graphis Magazine’s “Top 10… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”