Mac Developer Library

Developer

AppKit Framework Reference NSFont Class Reference

Options
Deployment Target:

On This Page
Language:

NSFont

Inheritance


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

NSFont objects represent fonts to an application, providing access to characteristics of the font and assistance in laying out glyphs relative to one another. Font objects are also used to establish the current font for drawing text directly into a graphics context, using the set method.

You don’t create NSFont objects using the alloc and init methods. Instead, you use either fontWithDescriptor:size: or fontWithName:size: to look up an available font and alter its size or matrix to your needs. These methods check for an existing font object with the specified characteristics, returning it if there is one. Otherwise, they look up the font data requested and create the appropriate object. NSFont also defines a number of methods for getting standard system fonts, such as systemFontOfSize:, userFontOfSize:, and messageFontOfSize:. To request the default size for these standard fonts, pass a negative number or 0 as the font size. See The OS X Environment in OS X Human Interface Guidelines for more information about system fonts.

  • Creates a font object for the specified font name and font size.

    Declaration

    Swift

    init?(name fontName: String, size fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize

    Parameters

    fontName

    The fully specified family-face name of the font.

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object for the specified name and size.

    Discussion

    The value of the fontName parameter is a fully specified family-face name, preferably the PostScript name, such as Helvetica-BoldOblique or Times-Roman. (The Font Book app displays PostScript names of fonts in the Font Info panel.)

    Specifying fontSize is equivalent to using a font matrix of [fontSize 0 0 fontSize 0 0] with fontWithDescriptor:size:. If you use a fontSize of 0.0, this method uses the default User Font size.

    Fonts created with this method automatically flip themselves in flipped views. This method is the preferred means for creating fonts.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a font object for the specified font descriptor and font size.

    Declaration

    Swift

    init?(descriptor fontDescriptor: NSFontDescriptor, size fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)fontWithDescriptor:(NSFontDescriptor *)fontDescriptor size:(CGFloat)fontSize

    Parameters

    fontDescriptor

    A font descriptor object.

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object for the specified descriptor and size.

    Discussion

    In most cases, you can simply use fontWithName:size: to create standard scaled fonts.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns a font object for the specified font descriptor and text transform.

    Declaration

    Swift

    init?(descriptor fontDescriptor: NSFontDescriptor, textTransform textTransform: NSAffineTransform?) -> NSFont

    Objective-C

    + (NSFont *)fontWithDescriptor:(NSFontDescriptor *)fontDescriptor textTransform:(NSAffineTransform *)textTransform

    Parameters

    fontDescriptor

    The font descriptor object describing the font to return.

    textTransform

    An affine transformation applied to the font.

    Return Value

    A font object for the specified name and transform.

    Discussion

    In most cases, you can simply use fontWithName:size: to create standard scaled fonts. If textTransform is non-nil, it has precedence over NSFontMatrixAttribute in fontDescriptor.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns a font object for the specified font name and matrix.

    Declaration

    Swift

    init?(name fontName: String, matrix fontMatrix: UnsafePointer<CGFloat>) -> NSFont

    Objective-C

    + (NSFont *)fontWithName:(NSString *)fontName matrix:(const CGFloat *)fontMatrix

    Parameters

    fontName

    The fully specified family-face name of the font.

    fontMatrix

    A transformation matrix applied to the font.

    Return Value

    A font object for the specified name and transformation matrix.

    Discussion

    The fontName is a fully specified family-face name, such as Helvetica-BoldOblique or Times-Roman (not a name as shown in the Font Panel). The fontMatrix is a standard 6-element transformation matrix as used in the PostScript language, specifically with the makefont operator. In most cases, you can simply use fontWithName:size: to create standard scaled fonts.

    You can use the defined value NSFontIdentityMatrix for [1 0 0 1 0 0]. Fonts created with a matrix other than NSFontIdentityMatrix don’t automatically flip themselves in flipped views.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – isFlipped (NSView)

  • Returns the font used by default for documents and other text under the user’s control (that is, text whose font the user can normally change), in the specified size.

    Declaration

    Swift

    class func userFontOfSize(_ fontSize: CGFloat) -> NSFont?

    Objective-C

    + (NSFont *)userFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the user font at the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used by default for documents and other text under the user’s control (that is, text whose font the user can normally change), when that font should be fixed-pitch, in the specified size.

    Declaration

    Swift

    class func userFixedPitchFontOfSize(_ fontSize: CGFloat) -> NSFont?

    Objective-C

    + (NSFont *)userFixedPitchFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the fixed-pitch font at the default size.

    The system does not guarantee that all the glyphs in a fixed-pitch font are the same width. For example, certain Japanese fonts are dual-pitch, and other fonts may have nonspacing marks that can affect the display of other glyphs.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the Aqua system font used for standard interface items that are rendered in boldface type in the specified size.

    Declaration

    Swift

    class func boldSystemFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)boldSystemFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the boldface system font at the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used for the content of controls in the specified size.

    Declaration

    Swift

    class func controlContentFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)controlContentFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    For example, in a table, the user’s input uses the control content font, and the table’s header uses another font. If fontSize is 0 or negative, returns the control content font at the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used for standard interface labels in the specified size.

    Declaration

    Swift

    class func labelFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)labelFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size. If fontSize is 0 or negative, returns the label font with the default size.

    Discussion

    The label font (Lucida Grande Regular 10 point) is used for the labels on toolbar buttons and to label tick marks on full-size sliders. See The OS X Environment in OS X Human Interface Guidelines for more information about system fonts.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used for menu items, in the specified size.

    Declaration

    Swift

    class func menuFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)menuFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the menu items font with the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used for menu bar items, in the specified size.

    Declaration

    Swift

    class func menuBarFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)menuBarFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the menu bar font with the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the font used for standard interface items, such as button labels, menu items, and so on, in the specified size.

    Declaration

    Swift

    class func messageFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)messageFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns this font at the default size. This method is equivalent to systemFontOfSize:.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used for palette window title bars, in the specified size.

    Declaration

    Swift

    class func paletteFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)paletteFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the palette title font at the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the Aqua system font used for standard interface items, such as button labels, menu items, and so on, in the specified size.

    Declaration

    Swift

    class func systemFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)systemFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the system font at the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used for window title bars, in the specified size.

    Declaration

    Swift

    class func titleBarFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)titleBarFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the title bar font at the default size. This method is equivalent to boldSystemFontOfSize:.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used for tool tips labels, in the specified size.

    Declaration

    Swift

    class func toolTipsFontOfSize(_ fontSize: CGFloat) -> NSFont

    Objective-C

    + (NSFont *)toolTipsFontOfSize:(CGFloat)fontSize

    Parameters

    fontSize

    The size in points to which the font is scaled.

    Return Value

    A font object of the specified size.

    Discussion

    If fontSize is 0 or negative, returns the tool tips font at the default size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets this font as the font for the current graphics context.

    Declaration

    Swift

    func set()

    Objective-C

    - (void)set

    Discussion

    This method sets the font for the graphics system but does not affect the higher-level settings of the Cocoa text system, which are controlled by text attributes.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets this font as the font for the specified graphics context.

    Declaration

    Swift

    func setInContext(_ graphicsContext: NSGraphicsContext)

    Objective-C

    - (void)setInContext:(NSGraphicsContext *)graphicsContext

    Parameters

    graphicsContext

    The graphics context for which the font is set.

    Discussion

    This method sets the font for the graphics system but does not affect the higher-level settings of the Cocoa text system, which are controlled by text attributes.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The character set containing all of the nominal characters that the font can render. (read-only)

    Declaration

    Swift

    var coveredCharacterSet: NSCharacterSet { get }

    Objective-C

    @property(readonly, strong) NSCharacterSet *coveredCharacterSet

    Discussion

    The nominal character set is all of the entries in the font’s cmap table.

    The number of glyphs supported by a given font is often larger than the number of characters contained in the character set returned by this method. This is because characters and glyphs have a many-to-many mapping, rather than a strict one-to-one correspondence. In some cases a character may be represented by multiple glyphs, such as an “é” which may be an “e” glyph combined with an acute accent glyph “´”. In other cases, a single glyph may represent multiple characters, as in the case of a ligature, or joined letter. See Typographical Concepts in Cocoa Text Architecture Guide for more information.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.2 and later.

  • The font descriptor object for the font. (read-only)

    Declaration

    Swift

    var fontDescriptor: NSFontDescriptor { get }

    Objective-C

    @property(readonly, strong) NSFontDescriptor *fontDescriptor

    Discussion

    The font descriptor contains a mutable dictionary of optional attributes for creating an NSFont object. For more information about font descriptors, see NSFontDescriptor Class Reference.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • A Boolean value indicating whether all glyphs in the font have the same advancement. (read-only)

    Declaration

    Swift

    var fixedPitch: Bool { get }

    Objective-C

    @property(getter=isFixedPitch, readonly) BOOL fixedPitch

    Discussion

    The value of this property is YEStrue when all glyphs have the same advancement or NOfalse when they do not. Some Japanese fonts encoded with the scheme “EUC12-NJE-CFEncoding” return that they have the same advancement, but actually encode glyphs with one of two advancements, for historical compatibility. You may need to handle such fonts specially for some applications.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • The string encoding that works best with the font. (read-only)

    Declaration

    Swift

    var mostCompatibleStringEncoding: UInt { get }

    Objective-C

    @property(readonly) NSStringEncoding mostCompatibleStringEncoding

    Discussion

    The string encoding in this property is the encoding with the fewest unmatched characters and glyphs in the font. If this value is NSASCIIStringEncoding, the font could not determine the correct encoding; you should assume the font can render only ASCII characters. The font uses heuristically well-known font encodings to determine the value of this property, so for nonstandard encodings the property may not contain the optimal string encoding.

    You can use the dataUsingEncoding: or dataUsingEncoding:allowLossyConversion: methods of NSString to convert strings to this encoding.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The rendering mode of the font. (read-only)

    Declaration

    Swift

    var renderingMode: NSFontRenderingMode { get }

    Objective-C

    @property(readonly) NSFontRenderingMode renderingMode

    Discussion

    For a list of valid rendering modes, see NSFontRenderingMode.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the named encoded glyph, or –1 if the receiver contains no such glyph.

    Declaration

    Swift

    func glyphWithName(_ glyphName: String) -> NSGlyph

    Objective-C

    - (NSGlyph)glyphWithName:(NSString *)glyphName

    Parameters

    glyphName

    The name of the glyph.

    Return Value

    The named encoded glyph.

    Discussion

    Returns –1 if the glyph named glyphName isn’t encoded.

    Glyph names in fonts do not always accurately identify the glyph. The layout manager, an instance of NSLayoutManager, finds the correspondence between characters and glyphs. See Text Layout Programming Guide and NSLayoutManager Class Reference for more information.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the size of the standard label font.

    Declaration

    Swift

    class func labelFontSize() -> CGFloat

    Objective-C

    + (CGFloat)labelFontSize

    Return Value

    The label font size in points.

    Discussion

    The label font (Lucida Grande Regular 10 point) is used for the labels on toolbar buttons and to label tick marks on full-size sliders. See The OS X Environment in OS X Human Interface Guidelines for more information about system fonts.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the size of the standard small system font.

    Declaration

    Swift

    class func smallSystemFontSize() -> CGFloat

    Objective-C

    + (CGFloat)smallSystemFontSize

    Return Value

    The small system font size in points.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the size of the standard system font.

    Declaration

    Swift

    class func systemFontSize() -> CGFloat

    Objective-C

    + (CGFloat)systemFontSize

    Return Value

    The standard system font size in points.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font size used for the specified control size.

    Declaration

    Swift

    class func systemFontSizeForControlSize(_ controlSize: NSControlSize) -> CGFloat

    Objective-C

    + (CGFloat)systemFontSizeForControlSize:(NSControlSize)controlSize

    Parameters

    controlSize

    The control size constant.

    Return Value

    The font size in points for the specified control size.

    Discussion

    If controlSize does not correspond to a valid NSControlSize, returns the size of the standard system font.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the nominal spacing for the given glyph—the distance the current point moves after showing the glyph—accounting for the receiver’s size.

    Declaration

    Swift

    func advancementForGlyph(_ aGlyph: NSGlyph) -> NSSize

    Objective-C

    - (NSSize)advancementForGlyph:(NSGlyph)aGlyph

    Parameters

    aGlyph

    The glyph whose advancement is returned.

    Return Value

    The advancement spacing in points.

    Discussion

    This spacing is given according to the glyph’s movement direction, which is either strictly horizontal or strictly vertical.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • ascender ascender Property

    The top y-coordinate, offset from the baseline, of the font’s longest ascender. (read-only)

    Declaration

    Swift

    var ascender: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat ascender

    Discussion

    The value of this property is the distance of the longest ascender’s top y-coordinate from the baseline, measured in points.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The font’s bounding rectangle, scaled to the font’s size. (read-only)

    Declaration

    Swift

    var boundingRectForFont: NSRect { get }

    Objective-C

    @property(readonly) NSRect boundingRectForFont

    Discussion

    The bounding rectangle is the union of the bounding rectangles of every glyph in the font.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the bounding rectangle for the specified glyph, scaled to the receiver’s size.

    Declaration

    Swift

    func boundingRectForGlyph(_ aGlyph: NSGlyph) -> NSRect

    Objective-C

    - (NSRect)boundingRectForGlyph:(NSGlyph)aGlyph

    Discussion

    Japanese fonts encoded with the scheme “EUC12-NJE-CFEncoding” do not have individual metrics or bounding boxes available for the glyphs above 127. For those glyphs, this method returns the bounding rectangle for the font instead.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • capHeight capHeight Property

    The cap height of the font. (read-only)

    Declaration

    Swift

    var capHeight: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat capHeight

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • descender descender Property

    The bottom y-coordinate, offset from the baseline, of the font’s longest descender. (read-only)

    Declaration

    Swift

    var descender: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat descender

    Discussion

    For example, if the longest descender extends 2 points below the baseline, the value in this property is –2.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an array of the advancements for the specified glyphs rendered by the receiver.

    Declaration

    Swift

    func getAdvancements(_ advancements: NSSizeArray, forGlyphs glyphs: UnsafePointer<NSGlyph>, count glyphCount: Int)

    Objective-C

    - (void)getAdvancements:(NSSizeArray)advancements forGlyphs:(const NSGlyph *)glyphs count:(NSUInteger)glyphCount

    Discussion

    Returns in advancements an array of the advancements for the glyphs specified by glyphs and rendered by the receiver. The glyphCount must specify the count of glyphs passed in glyphs.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns an array of the advancements for the specified packed glyphs and rendered by the receiver.

    Declaration

    Swift

    func getAdvancements(_ advancements: NSSizeArray, forPackedGlyphs packedGlyphs: UnsafePointer<Void>, length length: Int)

    Objective-C

    - (void)getAdvancements:(NSSizeArray)advancements forPackedGlyphs:(const void *)packedGlyphs length:(NSUInteger)length

    Discussion

    Returns in advancements an array of the advancements for the packed glyphs specified by packedGlyphs and rendered by the receiver. The glyphCount must specify the count of glyphs passed in packedGlyphs.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns an array of the bounding rectangles for the specified glyphs rendered by the receiver.

    Declaration

    Swift

    func getBoundingRects(_ bounds: NSRectArray, forGlyphs glyphs: UnsafePointer<NSGlyph>, count glyphCount: Int)

    Objective-C

    - (void)getBoundingRects:(NSRectArray)bounds forGlyphs:(const NSGlyph *)glyphs count:(NSUInteger)glyphCount

    Discussion

    Returns in bounds an array of the bounding rectangles for the glyphs specified by glyphs and rendered by the receiver. The glyphCount must specify the count of glyphs passed in glyphs.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The number of degrees that the font is slanted counterclockwise from the vertical. (read-only)

    Declaration

    Swift

    var italicAngle: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat italicAngle

    Discussion

    The italic angle value is read from the font’s AFM file. Because the slant is measured counterclockwise, English italic fonts typically return a negative value.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • leading leading Property

    The leading value of the font. (read-only)

    Declaration

    Swift

    var leading: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat leading

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • matrix matrix Property

    The transformation matrix associated with the font. (read-only)

    Declaration

    Swift

    var matrix: UnsafePointer<CGFloat> { get }

    Objective-C

    @property(readonly) const CGFloat *matrix

    Discussion

    This property contains a standard six-element transformation matrix as used in the PostScript language, specifically with the makefont operator. In most cases, with a font of fontSize, this matrix is [fontSize 0 0 fontSize 0 0].

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The maximum advance of any of the font’s glyphs. (read-only)

    Declaration

    Swift

    var maximumAdvancement: NSSize { get }

    Objective-C

    @property(readonly) NSSize maximumAdvancement

    Discussion

    The advancement is always either strictly horizontal or strictly vertical.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The number of glyphs in the font. (read-only)

    Declaration

    Swift

    var numberOfGlyphs: Int { get }

    Objective-C

    @property(readonly) NSUInteger numberOfGlyphs

    Discussion

    Glyphs are numbered starting at 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • pointSize pointSize Property

    The point size of the font. (read-only)

    Declaration

    Swift

    var pointSize: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat pointSize

    Discussion

    If the font has a nonstandard matrix, the point size is the effective vertical point size.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The current transformation matrix of the font. (read-only)

    Declaration

    Swift

    @NSCopying var textTransform: NSAffineTransform { get }

    Objective-C

    @property(readonly, copy) NSAffineTransform *textTransform

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The baseline offset to use when drawing underlines with the font. (read-only)

    Declaration

    Swift

    var underlinePosition: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat underlinePosition

    Discussion

    The value in this property is determined by the font’s AFM file. The value is usually negative, which must be considered when drawing in a flipped coordinate system.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The thickness to use when drawing underlines with the font. (read-only)

    Declaration

    Swift

    var underlineThickness: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat underlineThickness

    Discussion

    The value in this property is determined by the font’s AFM file.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • xHeight xHeight Property

    The x-height of the font. (read-only)

    Declaration

    Swift

    var xHeight: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat xHeight

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The name of the font, including family and face names, to use when displaying the font information to the user. (read-only)

    Declaration

    Swift

    var displayName: String? { get }

    Objective-C

    @property(readonly, copy) NSString *displayName

    Discussion

    The font’s display name is typically localized for the user’s language.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The family name of the font—for example, “Times” or “Helvetica.” (read-only)

    Declaration

    Swift

    var familyName: String? { get }

    Objective-C

    @property(readonly, copy) NSString *familyName

    Discussion

    This name is the one that NSFontManager uses and may differ slightly from the AFM name.

    The value in this property is intended for an application’s internal usage and not for display. To get a name that you can display to the user, use the displayName property instead.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    fontName

  • fontName fontName Property

    The full name of the font, as used in PostScript language code—for example, “Times-Roman” or “Helvetica-Oblique.” (read-only)

    Declaration

    Swift

    var fontName: String { get }

    Objective-C

    @property(readonly, copy) NSString *fontName

    Discussion

    The value in this property is intended for an application’s internal usage and not for display. To get a name that you can display to the user, use the displayName property instead.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    familyName

  • Sets the font used by default for documents and other text under the user’s control to the specified font.

    Declaration

    Swift

    class func setUserFont(_ aFont: NSFont?)

    Objective-C

    + (void)setUserFont:(NSFont *)aFont

    Discussion

    Specifying aFont as nil causes the default to be removed from the application domain.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the font used by default for documents and other text under the user’s control, when that font should be fixed-pitch, to the specified font.

    Declaration

    Swift

    class func setUserFixedPitchFont(_ aFont: NSFont?)

    Objective-C

    + (void)setUserFixedPitchFont:(NSFont *)aFont

    Discussion

    Specifying aFont as nil causes the default to be removed from the application domain.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The scalable PostScript font corresponding to current font. (read-only)

    Declaration

    Swift

    @NSCopying var printerFont: NSFont { get }

    Objective-C

    @property(readonly, copy) NSFont *printerFont

    Discussion

    For a font that already represents a scalable PostScript font, the value in this property is self. For a bitmapped screen font, the value is the corresponding scalable PostScript font.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    screenFont

  • The bitmapped screen font for the current font. (read-only)

    Declaration

    Swift

    @NSCopying var screenFont: NSFont { get }

    Objective-C

    @property(readonly, copy) NSFont *screenFont

    Discussion

    For a font object that represents a scalable PostScript font, this property contains a bitmapped screen font matching the receiver in typeface and matrix (or size), or nil if such a font cannot be found. For a bitmapped screen font, the value in this property is nil.

    Screen fonts are for direct use with the window server only. Never use them with Application Kit objects, such as in setFont: methods. Internally, the Application Kit automatically uses the corresponding screen font for a font object as long as the view is not rotated or scaled.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a bitmapped screen font, when sent to a font object representing a scalable PostScript font, with the specified rendering mode, matching the receiver in typeface and matrix (or size), or nil if such a font can’t be found.

    Declaration

    Swift

    func screenFontWithRenderingMode(_ renderingMode: NSFontRenderingMode) -> NSFont

    Objective-C

    - (NSFont *)screenFontWithRenderingMode:(NSFontRenderingMode)renderingMode

    Discussion

    For valid rendering modes, see NSFontRenderingMode.

    Screen fonts are for direct use with the window server only. Never use them with Application Kit objects, such as in setFont: methods. Internally, the Application Kit automatically uses the corresponding screen font for a font object as long as the view is not rotated or scaled.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • vertical vertical Property

    A Boolean value indicating whether the font is a vertical font. (read-only)

    Declaration

    Swift

    var vertical: Bool { get }

    Objective-C

    @property(getter=isVertical, readonly) BOOL vertical

    Discussion

    The value in this property is YEStrue for a vertical font or NOfalse otherwise.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

    See Also

    verticalFont

  • A vertical version of the font. (read-only)

    Declaration

    Swift

    @NSCopying var verticalFont: NSFont { get }

    Objective-C

    @property(readonly, copy) NSFont *verticalFont

    Discussion

    The value in this property is a vertical version of the font, if such a configuration is supported. If a vertical configuration is not supported, the value in the property is self.

    A vertical font applies appropriate rotation to the text matrix in setInContext:, returns vertical metrics, and enables the vertical glyph substitution feature by default.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

    See Also

    vertical

  • Returns the names of fonts that the Application Kit tries first when a character has no font specified.

    Deprecation Statement

    The NSFontDescriptor constant NSFontCascadeListAttribute offers more powerful font substitution management.

    Declaration

    Objective-C

    + (NSArray *)preferredFontNames

    Discussion

    Returns the names of fonts that the Application Kit tries first when a character has no font specified or when the font specified doesn’t have a glyph for that character. If none of these fonts provides a glyph, the remaining fonts on the system are searched for a glyph.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Sets the list of preferred font names.

    Deprecation Statement

    The NSFontDescriptor constant NSFontCascadeListAttribute offers more powerful font substitution management.

    Declaration

    Objective-C

    + (void)setPreferredFontNames:(NSArray *)fontNameArray

    Discussion

    Sets the list of preferred font names to fontNames and records them in the user defaults database for all applications. The Application Kit tries these fonts first when a character has no font specified or when the font specified doesn’t have a glyph for that character. If none of these fonts provides a glyph, the remaining fonts on the system are searched for a glyph.

    This method is useful for optimizing glyph rendering for uncommon scripts, by guaranteeing that appropriate fonts are searched first. For example, suppose you have three hundred Latin alphabet fonts and one Cyrillic alphabet font. When you read a document in Russian, you want it to find the Cyrillic font quickly. Ordinarily, the Application Kit will search for the Cyrillic font among all 301 fonts. But if it is in the list of preferred fonts, the Cyrillic font will be one of the first searched.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • useFont: + useFont: (OS X v10.4)

    Records the given font name as one used in the current print operation.

    Deprecation Statement

    This is now automatically handled by Quartz.

    Declaration

    Objective-C

    + (void)useFont:(NSString *)fontName

    Discussion

    Records fontName as one used in the current print operation.

    The NSFont class object keeps track of the fonts used in an NSView by recording each one that receives a set message. When the view is called upon to generate conforming PostScript language output (such as during printing), the NSFont class provides the list of fonts required for the %%DocumentFonts comment, as required by Adobe’s document structuring conventions.

    The useFont: argument augments this system by providing a way to register fonts that are included in the document but not set using NSFont’s set method. For example, you might set a font by executing the setfont operator within a function created by the pswrap utility. In such a case, be sure to pair the use of the font with a useFont: message to register the font for listing in the document comments.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Returns the AFM font’s dictionary.

    Deprecation Statement

    Use accessor functions listed in “Keys to the AFM Dictionary” instead.

    Declaration

    Objective-C

    - (NSDictionary *)afmDictionary

    Discussion

    Always returns nil.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Returns the default line height for the receiver.

    Deprecation Statement

    Use the NSLayoutManager method defaultLineHeightForFont: instead.

    Declaration

    Objective-C

    - (CGFloat)defaultLineHeightForFont

    Discussion

    Equivalent to ascent plus descent plus linegap.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Returns the name of the receiver’s encoding scheme.

    Deprecation Statement

    Use mostCompatibleStringEncoding instead.

    Declaration

    Objective-C

    - (NSString *)encodingScheme

    Discussion

    Returns the name of the receiver’s encoding scheme, such as “AdobeStandardEncoding,” “ISOLatin1Encoding,” “FontSpecific,” and so on.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Returns a Boolean value indicating whether the receiver encodes the given glyph.

    Deprecation Statement

    The value can be deduced by aGlyph < [NSFont numberOfGlyphs] since only NSNativeShortGlyphPacking is supported.

    Declaration

    Objective-C

    - (BOOL)glyphIsEncoded:(NSGlyph)aGlyph

    Discussion

    Returns YEStrue if the receiver encodes aGlyph, NOfalse if it doesn’t contain it.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Returns the best way to encode the receiver’s glyphs into an array of bytes.

    Deprecation Statement

    Only NSNativeShortGlyphPacking is supported.

    Declaration

    Objective-C

    - (NSMultibyteGlyphPacking)glyphPacking

    Discussion

    Returns the best way to encode the receiver’s glyphs into an array of bytes. The return value is one of values described in Constants.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • isBaseFont - isBaseFont (OS X v10.4)

    Returns a Boolean value indicating whether the receiver is a PostScript base font.

    Deprecation Statement

    This information is not relevant to OS X.

    Declaration

    Objective-C

    - (BOOL)isBaseFont

    Discussion

    Returns YEStrue if the receiver is a PostScript base font, NOfalse if it’s a PostScript composite font composed of other base fonts.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Calculates and returns a suitable location for the given glyph to be drawn.

    Deprecation Statement

    Context-sensitive interglyph spacing is now performed at the typesetting stage.

    Declaration

    Objective-C

    - (NSPoint)positionOfGlyph:(NSGlyph)aGlyph forCharacter:(unichar)aChar struckOverRect:(NSRect)aRect

    Discussion

    Calculates and returns a suitable location for aGlyph to be drawn as a diacritic or nonspacing mark relative to aRect, assuming that aGlyph represents aChar. Returns NSZeroPoint if the location can’t be calculated. The nature of aChar as one appearing above or below its base character determines the location returned. For example, in the first figure below, the gray tilde and box represent aGlyph and aRect, and the black dot is the point returned (defined relative to the origin of the aRect).

    image: ../Art/nsfont-glyphoverrect.gif

    To place multiple glyphs with respect to a rectangle, work from the innermost glyphs to the outermost. As you calculate the position of each glyph, enlarge the rectangle to include the bounding rectangle of the glyph in preparation for the next glyph. The second figure shows a tilde, acute accent, and cedilla all placed in their appropriate positions with respect to a rectangle, with the acute accent placed relative to the expanded bounding box of the base rectangle and the tilde.

    This method is the last fallback mechanism for performing minimally legible typography when metrics aren’t available. Use it when positionOfGlyph:struckOverGlyph:metricsExist: indicates that metrics don’t exist for the base glyph specified, or when you are combining glyphs from different fonts (for example, the base glyph is in a different font than the accent). It can account for the layout and placement of most Latin, Greek, and Cyrillic nonspacing marks. You should draw the glyph at the returned location, even if it’s NSZeroRect.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Calculates and returns the location of a glyph.

    Deprecation Statement

    Context-sensitive interglyph spacing is now performed at the typesetting stage.

    Declaration

    Objective-C

    - (NSPoint)positionOfGlyph:(NSGlyph)curGlyph precededByGlyph:(NSGlyph)prevGlyph isNominal:(BOOL *)nominal

    Discussion

    Calculates and returns the location of aGlyph relative to prevGlyph, assuming that prevGlyph precedes it in the layout (not necessarily in the character stream). The point returned should be used relative to whatever location is used for prevGlyph. If flag is non-nil, it’s filled with NOfalse if kerning tables are available and were used in the calculation; it is filled with YEStrue if the default spacing is used.

    Returns NSZeroPoint if either aGlyph or prevGlyph is NSControlGlyph or is invalid. Returns the nominal advancement of prevGlyph if aGlyph is NSNullGlyph.

    This method is useful for sequential glyph placement when glyphs aren’t drawn with a single PostScript operation.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Calculates and returns a suitable location for the given glyph to be drawn.

    Deprecation Statement

    Context-sensitive interglyph spacing is now performed at the typesetting stage.

    Declaration

    Objective-C

    - (NSPoint)positionOfGlyph:(NSGlyph)curGlyph struckOverGlyph:(NSGlyph)prevGlyph metricsExist:(BOOL *)exist

    Discussion

    Calculates and returns a suitable location for aGlyph to be drawn as a diacritic or nonspacing mark relative to baseGlyph. The point returned should be used relative to whatever location is used for baseGlyph. If flag is non-nil it’s filled with YEStrue if font metrics are available, NOfalse if they’re not. If flag is returned as NOfalse, the result isn’t valid and shouldn’t be used. In that case, use positionOfGlyph:struckOverRect:metricsExist: or positionOfGlyph:forCharacter:struckOverRect: to calculate a reasonable offset.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Overridden by subclasses to calculate and return a suitable location for a glyph to be drawn.

    Deprecation Statement

    Context-sensitive interglyph spacing is now performed at the typesetting stage.

    Declaration

    Objective-C

    - (NSPoint)positionOfGlyph:(NSGlyph)aGlyph struckOverRect:(NSRect)aRect metricsExist:(BOOL *)exist

    Discussion

    Overridden by subclasses to calculate and return a suitable location for aGlyph to be drawn as a diacritic or nonspacing mark relative to aRect, provided metrics exist. Returns NSZeroRect if the location can’t be determined. If flag is non-nil it’s filled with YEStrue if font metrics are available, NOfalse if they’re not. If flag is returned as NOfalse, the result isn’t valid and shouldn’t be used. In that case, use positionOfGlyph:forCharacter:struckOverRect: to calculate a reasonable offset.

    Because current PostScript font metrics don’t include support for generic placement relative to rectangles, NSFont’s implementation of this method always returns NSZeroPoint and returns flag as NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Calculates and returns a suitable location for a glyph to be drawn.

    Deprecation Statement

    Context-sensitive interglyph spacing is now performed at the typesetting stage.

    Declaration

    Objective-C

    - (NSPoint)positionOfGlyph:(NSGlyph)thisGlyph withRelation:(NSGlyphRelation)rel toBaseGlyph:(NSGlyph)baseGlyph totalAdvancement:(NSSizePointer)adv metricsExist:(BOOL *)exist

    Discussion

    Calculates and returns a suitable location for aGlyph to be drawn relative to baseGlyph, where relation is NSGlyphBelow or NSGlyphAbove. The point returned should be used relative to whatever location is used for baseGlyph. This method is useful for calculating the layout of stacked glyphs, found in some non-Western scripts.

    If offset is non-NULL, this method sets it to the larger of the two glyphs’ advancements, allowing for reasonable layout of following glyphs.

    If flag is non-nil, this method sets it to whether font metrics are available: YEStrue if they are, NOfalse if they’re not. If metrics aren’t available, the location is calculated as a simple stacking with no gap between baseGlyph and aGlyph. Current Postscript fonts do not contain appropriate font metrics, so this method always sets flag to NOfalse. If you subclass NSFont to handle fonts that do contain metrics, override this method.

    This method supports only horizontally laid out base glyphs.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Calculates glyph locations.

    Deprecation Statement

    Context-sensitive interglyph spacing is now performed at the typesetting stage.

    Declaration

    Objective-C

    - (NSInteger)positionsForCompositeSequence:(NSGlyph *)someGlyphs numberOfGlyphs:(NSInteger)numGlyphs pointArray:(NSPointArray)points

    Discussion

    Calculates and fills points with the locations for glyphs, assuming the first glyph is a base character and those following are nonspacing marks. These points should all be interpreted as relative to the location of the first glyph in glyphs. The storage block points points to should be large enough for at least numGlyphs points. Returns the number of points that could be calculated.

    If the number of points calculated is less than numGlyphs, the number of glyphs provided, you can use positionOfGlyph:struckOverRect:metricsExist: to determine the positions for the remaining glyphs. When using that method, calculate the base rectangle for each glyph from the bounding rectangles and positions of all preceding glyphs.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Returns the x-axis offset of the current point when the specified string is drawn with a show operator in the receiving font.

    Deprecation Statement

    Use the Application Kit string-drawing methods, as described in NSString Additions.

    Declaration

    Objective-C

    - (CGFloat)widthOfString:(NSString *)string

    Discussion

    This method is for backward compatibility only. This method performs lossy conversion of aString to the most compatible encoding for the receiving font. Use this method only when you’re sure all of aString can be rendered with the receiving font.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

Data Types

  • This type is used to specify glyphs in such methods as glyphWithName:.

    Declaration

    Swift

    typealias NSGlyph = UInt32

    Objective-C

    typedef unsigned int NSGlyph;

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • These constants are used for calculating the layout of stacked glyphs.

    Context-sensitive interglyph spacing is now performed at the typesetting stage

    Declaration

    Objective-C

    typedef enum _NSGlyphRelation { NSGlyphBelow = 1, NSGlyphAbove = 2 } NSGlyphRelation;

    Constants

    • NSGlyphBelow

      NSGlyphBelow

      The glyph is located below the base glyph.

      Context-sensitive interglyph spacing is now performed at the typesetting stage.

      Available in OS X v10.0 through OS X v10.4.

      Not available to 64-bit applications.

    • NSGlyphAbove

      NSGlyphAbove

      The glyph is located above the base glyph.

      Context-sensitive interglyph spacing is now performed at the typesetting stage.

      Available in OS X v10.0 through OS X v10.4.

      Not available to 64-bit applications.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

    Not available to 64-bit applications.

  • Glyph packing constants are used to extract glyphs from a font for making a multibyte (or single-byte) array of glyphs for passing to an interpreter, such as the window server. With Quartz, the engine always expects the format to be in 2-byte short array, so NSNativeShortGlyphPacking is the only format currently in use.

    Use NSNativeShortGlyphPacking instead.

    Declaration

    Objective-C

    enum { NSOneByteGlyphPacking, NSJapaneseEUCGlyphPacking, NSAsciiWithDoubleByteEUCGlyphPacking, NSTwoByteGlyphPacking, NSFourByteGlyphPacking, }

    Constants

    • NSOneByteGlyphPacking

      NSOneByteGlyphPacking

      One-byte storage format.

      Use NSNativeShortGlyphPacking instead.

      Available in OS X v10.0 through OS X v10.4.

      Not available to 64-bit applications.

    • NSJapaneseEUCGlyphPacking

      NSJapaneseEUCGlyphPacking

      Extended Unix Code for Japanese format.

      Use NSNativeShortGlyphPacking instead.

      Available in OS X v10.0 through OS X v10.4.

      Not available to 64-bit applications.

    • NSAsciiWithDoubleByteEUCGlyphPacking

      NSAsciiWithDoubleByteEUCGlyphPacking

      Two-byte Extended Unix Code format.

      Use NSNativeShortGlyphPacking instead.

      Available in OS X v10.0 through OS X v10.4.

      Not available to 64-bit applications.

    • NSTwoByteGlyphPacking

      NSTwoByteGlyphPacking

      Two-byte storage format.

      Use NSNativeShortGlyphPacking instead.

      Available in OS X v10.0 through OS X v10.4.

      Not available to 64-bit applications.

    • NSFourByteGlyphPacking

      NSFourByteGlyphPacking

      Four-byte storage format.

      Use NSNativeShortGlyphPacking instead.

      Available in OS X v10.0 through OS X v10.4.

      Not available to 64-bit applications.

    Import Statement

  • These constants specify the font rendering mode.

    Declaration

    Swift

    enum NSFontRenderingMode : UInt { case DefaultRenderingMode case AntialiasedRenderingMode case IntegerAdvancementsRenderingMode case AntialiasedIntegerAdvancementsRenderingMode }

    Objective-C

    typedef enum NSFontRenderingMode : NSUInteger { NSFontDefaultRenderingMode = 0, NSFontAntialiasedRenderingMode = 1, NSFontIntegerAdvancementsRenderingMode = 2, NSFontAntialiasedIntegerAdvancementsRenderingMode = 3 } NSFontRenderingMode;

    Constants

    • DefaultRenderingMode

      NSFontDefaultRenderingMode

      Determines the actual mode based on the user preference settings.

      Available in OS X v10.4 and later.

    • AntialiasedRenderingMode

      NSFontAntialiasedRenderingMode

      Specifies antialiased, floating-point advancements rendering mode (synonymous with printerFont).

      Available in OS X v10.4 and later.

    • IntegerAdvancementsRenderingMode

      NSFontIntegerAdvancementsRenderingMode

      Specifies integer advancements rendering mode.

      Available in OS X v10.4 and later.

    • AntialiasedIntegerAdvancementsRenderingMode

      NSFontAntialiasedIntegerAdvancementsRenderingMode

      Specifies antialiased, integer advancements rendering mode.

      Available in OS X v10.4 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • The identity matrix.

    Declaration

    Swift

    var NSFontIdentityMatrix: UnsafePointer<CGFloat>

    Objective-C

    const float *NSFontIdentityMatrix;

    Constants

    • NSFontIdentityMatrix

      NSFontIdentityMatrix

      A transformation matrix useful as a parameter to fontWithDescriptor:size:.

      Available in OS X v10.0 and later.

  • A constant for glyph packing.

    Declaration

    Swift

    enum NSMultibyteGlyphPacking : UInt { case NativeShortGlyphPacking }

    Objective-C

    typedef enum NSMultibyteGlyphPacking : NSUInteger { NSNativeShortGlyphPacking = 5 } NSMultibyteGlyphPacking;

    Constants

    • NativeShortGlyphPacking

      NSNativeShortGlyphPacking

      The native format for OS X.

      Available in OS X v10.0 and later.

    Discussion

    Cocoa stores all text data as Unicode. The text system converts Unicode into glyph IDs and places them in 1-, 2-, or 4-byte storage depending on the context. To render text, you must convert the storage into a format the text engine understands. The following constants describe the glyph packing schemes the text rendering engine can use. They are used to extract glyphs from a font for making a multibyte (or single-byte) array of glyphs for passing to an interpreter, such as the window server, which expects a big-endian multibyte stream (that is, “packed glyphs”) instead of a pure NSGlyph stream. They’re used by glyphPacking. With Quartz, the engine always expects the format to be in 2-byte short array, so NSNativeShortGlyphPacking is the only format currently in use.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • These constants define reserved glyph codes.

    Declaration

    Swift

    var NSControlGlyph: Int { get } var NSNullGlyph: Int { get }

    Objective-C

    enum { NSControlGlyph = 0x00FFFFFF, NSNullGlyph = 0x0 };

    Constants

    • NSControlGlyph

      NSControlGlyph

      NSGlyphGenerator generates NSControlGlyph for all characters in the Unicode General Category C* and U200B (ZERO WIDTH SPACE).

      Available in OS X v10.0 and later.

    • NSNullGlyph

      NSNullGlyph

      A null glyph.

      Available in OS X v10.0 and later.

  • These constants are used as keys retrieve information from an AFM dictionary.

    The AFM dictionary is no longer used in OS X. Use the font metrics accessor methods listed with the individual constants instead.

    Declaration

    Objective-C

    NSString *NSAFMFamilyName; NSString *NSAFMFontName; NSString *NSAFMFormatVersion; NSString *NSAFMFullName; NSString *NSAFMNotice; NSString *NSAFMVersion; NSString *NSAFMWeight; NSString *NSAFMEncodingScheme; NSString *NSAFMCharacterSet; NSString *NSAFMCapHeight; NSString *NSAFMXHeight; NSString *NSAFMAscender; NSString *NSAFMDescender; NSString *NSAFMUnderlinePosition; NSString *NSAFMUnderlineThickness; NSString *NSAFMItalicAngle; NSString *NSAFMMappingScheme;

    Constants

    • NSAFMFamilyName

      NSAFMFamilyName

      Font family name key.

      Use familyName instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMFontName

      NSAFMFontName

      Font name key.

      Use displayName instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMFormatVersion

      NSAFMFormatVersion

      Format version name key.

      This information is not relevant to OS X.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMFullName

      NSAFMFullName

      Full font name key.

      Use fontName instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMNotice

      NSAFMNotice

      Font notice key.

      Use Apple Type Services instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMVersion

      NSAFMVersion

      Font version key.

      Use Apple Type Services instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMWeight

      NSAFMWeight

      Font weight key.

      Use the NSFontManager method weightOfFont: instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMEncodingScheme

      NSAFMEncodingScheme

      Font encoding scheme key.

      Use mostCompatibleStringEncoding instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMCharacterSet

      NSAFMCharacterSet

      Font character set key.

      Use coveredCharacterSet instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMCapHeight

      NSAFMCapHeight

      Font cap-height key.

      Use capHeight instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMXHeight

      NSAFMXHeight

      Font x-height key.

      Use xHeight instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMAscender

      NSAFMAscender

      Font ascender height key.

      Use ascender instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMDescender

      NSAFMDescender

      Font descender depth key.

      Use descender instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMUnderlinePosition

      NSAFMUnderlinePosition

      Font underline rule position key.

      Use underlinePosition instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMUnderlineThickness

      NSAFMUnderlineThickness

      Font underline rule thickness key.

      Use underlineThickness instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMItalicAngle

      NSAFMItalicAngle

      Font italic angle key.

      Use italicAngle instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.

    • NSAFMMappingScheme

      NSAFMMappingScheme

      Font mapping scheme key.

      This information is irrelevant to OS X.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.4.

      Not available to 64-bit applications.