CTFont

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 new font reference that can best map the given string range based on the current font.

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.

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

CTFontCollection

The CTFontCollection opaque type represents a font collection, that is, a group of font descriptors taken together as a single object.

CTFontDescriptor

The CTFontDescriptor opaque type represents a font descriptor, that is, a dictionary of attributes (such as name, point size, and variation) that can completely specify a font.

CTFrame

The CTFrame opaque type represents a frame containing multiple lines of text. The frame object is the output resulting from the text-framing process performed by a framesetter object.

CTFramesetter

The CTFramesetter opaque type is used to generate text frames. That is, CTFramesetter is an object factory for CTFrame objects.

CTGlyphInfo

The CTGlyphInfo opaque type enables you to override a font's specified mapping from Unicode to the glyph ID.

CTLine

The CTLine opaque type represents a line of text.

CTParagraphStyle

The CTParagraphStyle opaque type represents paragraph or ruler attributes in an attributed string.

CTRun

The CTRun opaque type represents a glyph run, which is a set of consecutive glyphs sharing the same attributes and direction.

CTRunDelegate

The CTRunDelegate opaque type represents a run delegate, which is assigned to a run (attribute range) to control typographic traits such glyph ascent, glyph descent, and glyph width.

CTTextTab

The CTTextTab opaque type represents a tab in a paragraph style, storing an alignment type and location.

CTTypesetter

The CTTypesetter opaque type represents a typesetter, which performs line layout.