Class

NSFontDescriptor

A dictionary of attributes that describe a font.

Declaration

@interface NSFontDescriptor : NSObject

Overview

A font descriptor can be used to create or modify an NSFont object. The system provides a font matching capability, so that you can partially describe a font by creating a font descriptor with, for example, just a family name. You can then find all the available fonts on the system with a matching family name using matchingFontDescriptorsWithMandatoryKeys:.

There are several ways to create a new NSFontDescriptor object. You can use alloc and initWithFontAttributes:, fontDescriptorWithFontAttributes:, fontDescriptorWithName:matrix:, or fontDescriptorWithName:size:. to create a font descriptor based on either your custom attributes dictionary or on a specific font’s name and size. Alternatively you can use one of the fontDescriptor… instance methods (such as fontDescriptorWithFace:) to create a modified version of an existing descriptor. The latter methods are useful if you have an existing descriptor and simply want to change one aspect.

All attributes in the attributes dictionary are optional.

Topics

Creating a Font Descriptor

+ fontDescriptorWithFontAttributes:

Returns a font descriptor with a dictionary of attributes.

+ fontDescriptorWithName:matrix:

Returns a font descriptor with the NSFontNameAttribute and NSFontMatrixAttribute dictionary attributes set to the given values.

+ fontDescriptorWithName:size:

Returns a font descriptor with the NSFontNameAttribute and NSFontSizeAttribute dictionary attributes set to the given values.

- initWithFontAttributes:

Initializes and returns a new font descriptor with the specified attributes.

- fontDescriptorByAddingAttributes:

Returns a new font descriptor that is the same as the receiver but with the specified attributes taking precedence over the existing ones.

- fontDescriptorWithFace:

Returns a new font descriptor that is the same as the receiver but with the specified face.

- fontDescriptorWithFamily:

Returns a new font descriptor whose attributes are the same as the receiver but from the specified family.

- fontDescriptorWithMatrix:

Returns a new font descriptor that is the same as the receiver but with the specified matrix.

- fontDescriptorWithSize:

Returns a new font descriptor that is the same as the receiver but with the specified point size.

- fontDescriptorWithSymbolicTraits:

Returns a new font descriptor that is the same as the receiver but with the specified symbolic traits taking precedence over the existing ones.

Finding Fonts

- matchingFontDescriptorsWithMandatoryKeys:

Returns all the fonts available on the system whose specified attributes match those of the receiver.

- matchingFontDescriptorWithMandatoryKeys:

Returns a normalized font descriptor whose specified attributes match those of the receiver.

Getting the Font Attributes

fontAttributes

The receiver’s dictionary of attributes.

- objectForKey:

Returns the font attribute specified by the given key.

NSFontDescriptorAttributeName

These font attributes are defined by NSFontDescriptor.

matrix

The current transform matrix of the receiver.

pointSize

The point size of the receiver.

postscriptName

The PostScript name of the receiver.

Getting the Font Traits

symbolicTraits

A bit mask that describes the traits of the receiver.

NSFontDescriptorSymbolicTraits

Stylistic aspects of a font.

NSFontSymbolicTraits

A symbolic description of stylistic aspects of a font.

Requiring Font Assets

Constants

NSFontDescriptorFeatureKey

The following constants can be used as keys to retrieve information about a font descriptor from its feature dictionary.

NSFontDescriptorTraitKey

The following constants can be used as keys to retrieve information about a font descriptor from its trait dictionary.

NSFontDescriptorVariationKey

The following constants can be used as keys to retrieve information about a font descriptor from its variation axis dictionary.

NSFontFamilyClass

Constants that classify certain stylistic qualities of the font.

NSFontFamilyClassMask

Constant you use to access NSFontFamilyClass values in the upper four bits of NSFontSymbolicTraits.

Typeface Information

Typeface information is specified by the lower 16 bits of NSFontSymbolicTraits using the following constants.

Instance Methods

Relationships

Inherits From

See Also

Font Data

NSFont

The representation of a font in an app.

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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software