CTFont

A font object.

Overview

The CTFont opaque type represents a Core Text font object.

Font objects represent fonts to an application, providing access to characteristics of the font, such as point size, transform matrix, and other attributes. Fonts provide assistance in laying out glyphs relative to one another and are used to establish the current font when drawing in a graphics context.

Topics

Creating Fonts

func CTFontCreateWithFontDescriptor(CTFontDescriptor, CGFloat, UnsafePointer<CGAffineTransform>?) -> CTFont

Returns a new font reference that best matches the given font descriptor.

func CTFontCreateUIFontForLanguage(CTFontUIFontType, CGFloat, CFString?) -> CTFont?

Returns the special user-interface font for the given language and user-interface type.

func CTFontCreateCopyWithFamily(CTFont, CGFloat, UnsafePointer<CGAffineTransform>?, CFString) -> CTFont?

Returns a new font in the specified family based on the traits of the original font.

func CTFontCreateForString(CTFont, CFString, CFRange) -> CTFont

Returns a font reference that most accurately maps the string range based on the current font.

func CTFontCreateForStringWithLanguage(CTFont, CFString, CFRange, CFString?) -> CTFont

Returns a font reference that most accurately maps the string range based on the current font and language.

Getting Font Data

func CTFontCopyFontDescriptor(CTFont) -> CTFontDescriptor

Returns the normalized font descriptor for the given font reference.

func CTFontCopyAttribute(CTFont, CFString) -> CFTypeRef?

Returns the value associated with an arbitrary attribute of the given font.

func CTFontGetSize(CTFont) -> CGFloat

Returns the point size of the given font.

func CTFontGetMatrix(CTFont) -> CGAffineTransform

Returns the transformation matrix of the given font.

func CTFontGetSymbolicTraits(CTFont) -> CTFontSymbolicTraits

Returns the symbolic traits of the given font.

func CTFontCopyTraits(CTFont) -> CFDictionary

Returns the traits dictionary of the given font.

func CTFontCopyDefaultCascadeListForLanguages(CTFont, CFArray?) -> CFArray?

Retrieves an ordered list of font substitution preferences.

Getting Font Names

func CTFontCopyPostScriptName(CTFont) -> CFString

Returns the PostScript name of the given font.

func CTFontCopyFamilyName(CTFont) -> CFString

Returns the family name of the given font.

func CTFontCopyFullName(CTFont) -> CFString

Returns the full name of the given font.

func CTFontCopyDisplayName(CTFont) -> CFString

Returns the display name of the given font.

func CTFontCopyName(CTFont, CFString) -> CFString?

Returns a reference to the requested name of the given font.

Working With Encoding

func CTFontCopyCharacterSet(CTFont) -> CFCharacterSet

Returns the Unicode character set of the font.

func CTFontGetStringEncoding(CTFont) -> CFStringEncoding

Returns the best string encoding for legacy format support.

func CTFontCopySupportedLanguages(CTFont) -> CFArray

Returns an array of languages supported by the font.

Getting Font Metrics

func CTFontGetAscent(CTFont) -> CGFloat

Returns the scaled font-ascent metric of the given font.

func CTFontGetDescent(CTFont) -> CGFloat

Returns the scaled font-descent metric of the given font.

func CTFontGetLeading(CTFont) -> CGFloat

Returns the scaled font-leading metric of the given font.

func CTFontGetUnitsPerEm(CTFont) -> UInt32

Returns the units-per-em metric of the given font.

func CTFontGetGlyphCount(CTFont) -> CFIndex

Returns the number of glyphs of the given font.

func CTFontGetBoundingBox(CTFont) -> CGRect

Returns the scaled bounding box of the given font.

func CTFontGetUnderlinePosition(CTFont) -> CGFloat

Returns the scaled underline position of the given font.

func CTFontGetUnderlineThickness(CTFont) -> CGFloat

Returns the scaled underline-thickness metric of the given font.

func CTFontGetSlantAngle(CTFont) -> CGFloat

Returns the slant angle of the given font.

func CTFontGetCapHeight(CTFont) -> CGFloat

Returns the cap-height metric of the given font.

func CTFontGetXHeight(CTFont) -> CGFloat

Returns the x-height metric of the given font.

Getting Glyph Data

func CTFontGetGlyphWithName(CTFont, CFString) -> CGGlyph

Returns the CGGlyph value for the specified glyph name in the given font.

func CTFontGetBoundingRectsForGlyphs(CTFont, CTFontOrientation, UnsafePointer<CGGlyph>, UnsafeMutablePointer<CGRect>?, CFIndex) -> CGRect

Calculates the bounding rects for an array of glyphs and returns the overall bounding rectangle for the glyph run.

func CTFontGetOpticalBoundsForGlyphs(CTFont, UnsafePointer<CGGlyph>, UnsafeMutablePointer<CGRect>?, CFIndex, CFOptionFlags) -> CGRect

Calculates the optical bounds for an array of glyphs and returns the overall optical bounds for the run.

func CTFontGetVerticalTranslationsForGlyphs(CTFont, UnsafePointer<CGGlyph>, UnsafeMutablePointer<CGSize>, CFIndex)

Calculates the offset from the default (horizontal) origin to the vertical origin for an array of glyphs.

Working With Font Variations

func CTFontCopyVariationAxes(CTFont) -> CFArray?

Returns an array of variation axes.

func CTFontCopyVariation(CTFont) -> CFDictionary?

Returns a variation dictionary from the font reference.

Getting Font Features

func CTFontCopyFeatures(CTFont) -> CFArray?

Returns an array of font features.

func CTFontCopyFeatureSettings(CTFont) -> CFArray?

Returns an array of font feature-setting tuples.

Working with Glyphs

func CTFontGetGlyphsForCharacters(CTFont, UnsafePointer<UniChar>, UnsafeMutablePointer<CGGlyph>, CFIndex) -> Bool

Provides basic Unicode encoding for the given font, returning by reference an array of CGGlyph values corresponding to a given array of Unicode characters for the given font.

func CTFontDrawGlyphs(CTFont, UnsafePointer<CGGlyph>, UnsafePointer<CGPoint>, Int, CGContext)

Renders the given glyphs of a font at the specified positions in the supplied graphics context.

Getting Font Table Data

Getting the Type Identifier

func CTFontGetTypeID() -> CFTypeID

Returns the type identifier for Core Text font references.

Data Types

class CTFont

A reference to a Core Text font object.

Global Variables

Name Specifier Constants

Name specifier constants provide access to the different names associated with a font.

Font Variation Axis Dictionary Keys

These constants provide keys to font variation axis dictionary values.

Font Feature Constants

These constants provide keys to font feature dictionary values.

Enumerations

enum CTFontUIFontType

These constants represent the specific user-interface purpose to specify for font creation.

typealias CTFontTableTag

Font table tags provide access to font table data.

struct CTFontTableOptions

These constants describe font table options.

struct CTFontOptions

These constants describe options for font creation and descriptor matching. They are used by the functions CTFontCreateWithNameAndOptions(_:_:_:_:) and CTFontCreateWithFontDescriptorAndOptions(_:_:_:_:).

See Also

Opaque Types

CTFramesetter

Generate text frames.

CTGlyphInfo

Override a font's specified mapping from Unicode to the glyph ID.

CTLine

A line of text.

CTParagraphStyle

Paragraph or ruler attributes in an attributed string.

CTTextTab

A tab in a paragraph style, storing an alignment type and location.

CTTypesetter

A typesetter which performs line layout.