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

+ boldSystemFontOfSize:

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

+ controlContentFontOfSize:

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

+ labelFontOfSize:

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

+ menuFontOfSize:

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

+ menuBarFontOfSize:

Returns the font used for menu bar items, 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.

+ paletteFontOfSize:

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

+ systemFontOfSize:

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

+ titleBarFontOfSize:

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

+ toolTipsFontOfSize:

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

NSFontWeight

System-defined font-weight values.

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 General Font Information

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.

renderingMode

The rendering mode of the font.

Deprecated

Getting Information About Glyphs

- glyphWithName:

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

Deprecated

Getting Metrics Information

labelFontSize

Returns the size of the standard label font.

smallSystemFontSize

Returns the size of the standard small system font.

systemFontSize

Returns the size of the standard system font.

+ systemFontSizeForControlSize:

Returns the font size used for the specified control size.

- advancementForCGGlyph:

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

ascender

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

boundingRectForFont

The font’s bounding rectangle, scaled to the font’s size.

- boundingRectForCGGlyph:

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

capHeight

The cap height of the font.

descender

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

- getAdvancements:forCGGlyphs:count:

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

- getBoundingRects:forCGGlyphs:count:

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

italicAngle

The number of degrees that the font is slanted counterclockwise from the vertical.

leading

The leading value of the font.

matrix

The transformation matrix associated with the font.

maximumAdvancement

The maximum advance of any of the font’s glyphs.

numberOfGlyphs

The number of glyphs in the font.

pointSize

The point size of the font.

textTransform

The current transformation matrix of the font.

underlinePosition

The baseline offset to use when drawing underlines with the font.

underlineThickness

The thickness to use when drawing underlines with the font.

xHeight

The x-height of the font.

- getAdvancements:forGlyphs:count:

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

Deprecated
- getAdvancements:forPackedGlyphs:length:

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

Deprecated
- advancementForGlyph:

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

Deprecated
- boundingRectForGlyph:

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

Deprecated
- getBoundingRects:forGlyphs:count:

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

Deprecated

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.

Getting Corresponding Device Fonts

printerFont

The scalable PostScript font corresponding to current font.

Deprecated
screenFont

The bitmapped screen font for the current font.

Deprecated
- screenFontWithRenderingMode:

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.

Deprecated

Vertical Fonts

vertical

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

verticalFont

A vertical version of the font.

Constants

NSFontRenderingMode

The font rendering mode.

NSMultibyteGlyphPacking

A constant for glyph packing.

Deprecated
Reserved Glyph Codes

These constants define reserved glyph codes.

NSGlyph

The type used to specify glyphs.

NSMultibyteGlyphPacking

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.

Notifications

NSAntialiasThresholdChangedNotification

Posted after the threshold for antialiasing changes.

NSFontSetChangedNotification

Posted after the currently-set font changes.

Relationships

Inherits From

See Also

Font Data

NSFontDescriptor

A dictionary of attributes that describe a font.

NSFontTraitMask

Mask of traits assigned to a font, assigned using the values in Font traits.

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.