Typeface

public final class Typeface

The Typeface class specifies the typeface and intrinsic style of a font. This is used in the paint, along with optionally algorithmic settings like textSize, textskewX, textScaleX, FakeBoldText_Mask, to specify how text appears when drawn (and measured).

Typeface objects are immutable, and so they can be shared between threads.

  • Returns a new typeface configured with the defaults

    Declaration

    Swift

    public static func createDefault() -> Typeface
  • Initializes a new instance to a typeface that most closely matches the requested family name and style, can fail

    Declaration

    Swift

    public convenience init?(familyName: String?)

    Parameters

    familyName

    The name of the font family. May be nil

  • Initializes a new instance to a typeface that most closely matches the requested family name and style, can fail

    • style: The style of the typeface, one of the defaults from FontStyle (normal, bold, italic, or your own constructed FontStyle)

    Declaration

    Swift

    public init?(familyName: String?, style: FontStyle)

    Parameters

    familyName

    The name of the font family. May be nil

  • Initializes a new instance to a typeface that most closely matches the requested family name and style, can fail

    This constructor calls the FontStyle constructor with the provided parameters to create your typeface

    Declaration

    Swift

    public convenience init?(familyName: String?, weight: FontStyleWeight, width: FontStyleWidth, slant: FontStyleSlant)

    Parameters

    familyName

    The name of the font family. May be nil

    weight

    the desired weight

    width

    the desired width

    slant

    the desired slant

  • Initializes a new typeface from a file - for example to load a true type font, can fail

    Declaration

    Swift

    public init?(file: String, index: Int32 = 0)

    Parameters

    file

    the path to the file containing the font

    index

    The font face index in the file

  • Initializes a new typeface from a stream (for example from a stream reader that is reading a true type font) , can fail

    Declaration

    Swift

    public init?(stream: SKStream, index: Int32 = 0)

    Parameters

    stream

    the stream that contains the font

    index

    The font face index in the file

  • Initializes a new typeface from a data blob (for example from a stream reader that is reading a true type font) , can fail

    Declaration

    Swift

    public init?(data: SKData, index: Int32 = 0)

    Parameters

    data

    the data blob that contains the font

    index

    The font face index in the file

  • Return the family name for this typeface. It will always be returned encoded as UTF8, but the language of the name is whatever the host platform chooses.

    Declaration

    Swift

    public var familyName: String? { get }
  • Gets the font style

    Declaration

    Swift

    public var fontStyle: FontStyle { get }
  • Getes the font weight

    Declaration

    Swift

    public var fontWeight: Int32 { get }
  • Getes the font width

    Declaration

    Swift

    public var fontWidth: Int32 { get }
  • Gets the font slant

    Declaration

    Swift

    public var fontSlant: FontStyleSlant { get }
  • Return the units-per-em value for this typeface, or zero if there is an error.

    Declaration

    Swift

    public var unitsPerEm: Int32 { get }
  • Return the number of tables in the font.

    Declaration

    Swift

    public var tableCount: Int32 { get }
  • Given a table tag, return the size of its contents, or 0 if not present

    Declaration

    Swift

    public func getTableSize(tag: UInt32) -> Int
  • Gets the contents of the specified table tag as an array, or nil if the table is not found

    Declaration

    Swift

    public func getTableData(tag: UInt32) -> [UInt8]?

    Parameters

    tag

    The table tag whose contents are to be copied

    Return Value

    An array with the table contents, or nil on error

  • Copy the contents of a table into data (allocated by the caller). Note that the contents of the table will be in their native endian order (which for most truetype tables is big endian). If the table tag is not found, or there is an error copying the data, then 0 is returned. If this happens, it is possible that some or all of the memory pointed to by data may have been written to, even though an error has occured.

    Declaration

    Swift

    public func getTableData(tag: UInt32, offset: Int, length: Int, storage: UnsafeMutablePointer<UInt8>) -> Int

    Parameters

    tag

    The table tag whose contents are to be copied

    offset

    The offset in bytes into the table’s contents where the copy should start from.

    length

    The number of bytes, starting at offset, of table data to copy.

    storage

    storage address where the table contents are copied to

    Return Value

    the number of bytes actually copied into data. If offset+length exceeds the table’s size, then only the bytes up to the table’s size are actually copied, and this is the value returned. If offset > the table’s size, or tag is not a valid table, then 0 is returned.

  • Returns the number of glyphs in the string.

    Declaration

    Swift

    public func countGlyphs(str: String) -> Int32
  • Retrieve the corresponding glyph IDs of a string of characters.

    Declaration

    Swift

    public func getGlyphs(str: String) -> [UInt16]?

    Return Value

    the array of glyphs, or nil if there is an error

  • Returns a stream for the contents of the font data.

    Declaration

    Swift

    public func openStream() -> (stream: SKStream, trueTypeCollectionIndex: Int32)?