fbpx
Wikipedia

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."[1]

Features edit

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 edit

The following code displays the text "Hello, World!" to the given graphics context in Objective-C.

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

  1. ^ Core Text Programming Guide: Core Text Overview

External links edit

core, text, this, article, needs, additional, citations, verification, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material, challenged, removed, find, sources, news, newspapers, books, scholar, jstor, september, 2007. This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Core Text news newspapers books scholar JSTOR September 2007 Learn how and when to remove this message 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 1 Contents 1 Features 2 Example 3 References 4 External linksFeatures editCore 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 editThe following code displays the text Hello World to the given graphics context in Objective C 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 amp keys const void amp values sizeof keys sizeof keys 0 amp kCFTypeDictionaryKeyCallBacks amp 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 edit Core Text Programming Guide Core Text OverviewExternal links editCore Text overview at Apple Developer Connection nbsp This Macintosh related article is a stub You can help Wikipedia by expanding it vte Retrieved from https en wikipedia org w index php title Core Text amp oldid 1203363981, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.