World Library  
Flag as Inappropriate
Email this Article

Core Text

Article Id: WHEBN0011238113
Reproduction Date:

Title: Core Text  
Author: World Heritage Encyclopedia
Language: English
Subject: OS X, Core OpenGL, Core Foundation, TenFourFox, Blued (Mac OS X)
Collection: Os X Apis, Text Rendering Libraries
Publisher: World Heritage Encyclopedia

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]


  • Features 1
  • Example 2
  • References 3
  • External links 4


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.


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);

// 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


  1. ^ Core Text Programming Guide: Core Text Overview

External links

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.