Class

NSFont

The representation of a font in an app.

Declaration

@interface NSFont : NSObject

Overview

NSFont objects represent fonts to an app, 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 macOS Human Interface Guidelines for more information about system fonts.

Topics

Creating Arbitrary Fonts

+ fontWithName:size:

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

+ fontWithDescriptor:size:

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

+ fontWithDescriptor:textTransform:

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

+ fontWithName:matrix:

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

Creating User Fonts

+ userFontOfSize:

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.

+ userFixedPitchFontOfSize:

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.

Creating System Fonts

+ systemFontOfSize:

Returns the standard system font with the specified size.

+ systemFontOfSize:weight:

Returns the standard system font with the specified size and weight.

+ boldSystemFontOfSize:

Returns the standard system font in boldface type with the specified size.

+ monospacedSystemFontOfSize:weight:

Returns a monospace version of the system font with the specified size and weight.

+ monospacedDigitSystemFontOfSize:weight:

Returns a version of the standard system font that contains monospaced digit glyphs.

systemFontSize

Returns the size of the standard system font.

smallSystemFontSize

Returns the size of the standard small system font.

NSFontWeight

System-defined font-weight values.

Creating UI Element Fonts

+ labelFontOfSize:

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

+ messageFontOfSize:

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

+ menuBarFontOfSize:

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

+ menuFontOfSize:

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

+ controlContentFontOfSize:

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

+ titleBarFontOfSize:

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

+ paletteFontOfSize:

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

+ toolTipsFontOfSize:

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

labelFontSize

Returns the size of the standard label font.

+ systemFontSizeForControlSize:

Returns the font size used for the specified control size.

Using a Font to Draw

- set

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

- setInContext:

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

Getting Font Metrics and Information

pointSize

The point size of the font.

coveredCharacterSet

The character set containing all of the nominal characters that the font can render.

fontDescriptor

The font descriptor object for the font.

fixedPitch

A Boolean value indicating whether all glyphs in the font have the same advancement.

mostCompatibleStringEncoding

The string encoding that works best with the font.

Advanced Font Metrics

Retrieve details about ascender and descender heights, glyph bounding rectangles, glyph advancements, and more.

Getting Information About Glyphs

numberOfGlyphs

The number of glyphs in the font.

NSGlyph

The type used to specify glyphs.

NSControlGlyph

The reserved code for a control glyph.

NSNullGlyph

The reserved code for a null glyph.

Getting Font Names

displayName

The name of the font, including family and face names, to use when displaying the font information to the user.

familyName

The family name of the font—for example, “Times” or “Helvetica.”

fontName

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

Setting User Fonts

+ setUserFont:

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

+ setUserFixedPitchFont:

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.

Vertical Fonts

vertical

A Boolean value indicating whether the font is a vertical font.

verticalFont

A vertical version of the font.

Responding to Font-Related Notifications

NSAntialiasThresholdChangedNotification

Posted after the threshold for antialiasing changes.

NSFontSetChangedNotification

Posted after the currently-set font changes.

Deprecated

Deprecated Symbols

Review unsupported symbols and their replacements.

Relationships

Inherits From

See Also

Font Data

NSFontDescriptor

A dictionary of attributes that describe a font.

NSFontTraitMask

Constants for isolating specific traits of a font.

NSFontFamilyClass

Constants that classify certain stylistic qualities of the font.

NSFontDescriptorSymbolicTraits

Stylistic aspects of a font.

NSFontSymbolicTraits

A symbolic description of stylistic aspects of a font.