Class

NSFontManager

The center of activity for the font conversion system.

Declaration

@interface NSFontManager : NSObject

Overview

The font manager records the currently selected font, updates the Font panel and Font menu to reflect the selected font, initiates font changes, and converts fonts in response to requests from text-bearing objects. In a more prosaic role, NSFontManager can be queried for the fonts available to the application and for the particular attributes of a font, such as whether it’s condensed or extended.

You typically set up a font manager and the Font menu using Interface Builder. However, you can also do so programmatically by getting the shared font manager instance and having it create the standard Font menu at runtime:

NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSMenu *fontMenu = [fontManager fontMenu:YES];

You can then add the Font menu to your app’s main menu. After the Font menu is installed, your app automatically gains the functionality of both the Font menu and the Font panel.

Font collections are managed by NSFontManager.

Topics

Getting the Shared Font Manager

sharedFontManager

Returns the shared instance of the font manager for the application, creating it if necessary.

Changing the Default Font Conversion Classes

+ setFontManagerFactory:

Sets the class object used to create the font manager to the given class.

+ setFontPanelFactory:

Sets the class used to create the Font panel to the given class.

Getting Available Fonts

availableFonts

The names of the fonts available in the system (not the NSFont objects themselves).

availableFontFamilies

The names of the font families available in the system.

- availableFontNamesWithTraits:

Returns the names of the fonts available in the system whose traits are described exactly by the given font trait mask (not the NSFont objects themselves).

- availableMembersOfFontFamily:

Returns an array with one entry for each available member of a font family.

Setting and Examining the Selected Font

- setSelectedFont:isMultiple:

Records the given font as the currently selected font and updates the Font panel to reflect this.

selectedFont

The last font recorded.

multiple

A Boolean value that indicates if the last font selection recorded has multiple fonts.

- sendAction

A Boolean value that indicates if the font manager’s action message was handled.

- localizedNameForFamily:face:

Returns a localized string with the name of the specified font family and face, if one exists.

Sending Action Methods

- addFontTrait:

This action method causes the receiver to send its action message up the responder chain.

- removeFontTrait:

This action method causes the receiver to send its action message up the responder chain.

- modifyFont:

This action method causes the receiver to send its action message up the responder chain.

- modifyFontViaPanel:

This action method causes the receiver to send its action message up the responder chain.

- orderFrontStylesPanel:

This action method opens the Font styles panel.

- orderFrontFontPanel:

This action method opens the Font panel by sending it an orderFront: message, creating the Font panel if necessary.

Converting Fonts Automatically

- convertFont:

Converts the given font according to the object that initiated a font change, typically the Font panel or Font menu.

- changeFont:

Informs responders of a font change.

Deprecated

Converting Fonts Manually

- convertFont:toFace:

Returns a font whose traits are as similar as possible to those of the given font except for the typeface, which is changed to the given typeface.

- convertFont:toFamily:

Returns a font whose traits are as similar as possible to those of the given font except for the font family, which is changed to the given family.

- convertFont:toHaveTrait:

Returns a font whose traits are the same as those of the given font, except that the traits are changed to include the single specified trait.

- convertFont:toNotHaveTrait:

Returns an NSFont object with the same traits as the given font, except for the traits in the given font trait mask, which are removed.

- convertFont:toSize:

Returns an NSFont object whose traits are the same as those of the given font, except for the size, which is changed to the given size.

- convertWeight:ofFont:

Returns an NSFont object whose weight is greater or lesser than that of the given font, if possible.

currentFontAction

The current font conversion action.

- convertFontTraits:

Converts font traits to a new traits mask value.

Getting a Particular Font

- fontWithFamily:traits:weight:size:

Attempts to load a font with the specified characteristics.

Examining Fonts

- traitsOfFont:

Returns the traits of the given font.

- fontNamed:hasTraits:

Indicates whether the given font has all the specified traits.

- weightOfFont:

Returns an approximation of the weight of the given font.

Managing the Font Panel and Font Menu

enabled

A Boolean value that indicates if the font conversion system’s user interface items (the Font panel and Font menu items) are enabled.

- fontManager:willIncludeFont:

Requests permission from the Font panel delegate to display the given font name in the Font panel.

Deprecated
- fontPanel:

Returns the application’s shared Font panel object, optionally creating it if necessary.

- setFontMenu:

Records the given menu as the application’s Font menu.

- fontMenu:

Returns the menu that’s hooked up to the font conversion system, optionally creating it if necessary.

Accessing the Delegate

delegate

The font manager’s delegate.

Deprecated

Accessing the Action Property

action

The action sent to the first responder when the user selects a new font from the Font panel or chooses a command from the Font menu.

target

The target for the action associated with the sendAction property.

Setting Attributes

- setSelectedAttributes:isMultiple:

Informs the paragraph and character formatting panels when text in a selection has changed attributes.

- convertAttributes:

Converts attributes in response to an object initiating an attribute change, typically the Font panel or Font menu.

Working with Font Descriptors

- availableFontNamesMatchingFontDescriptor:

Returns the names of the fonts that match the attributes in the given font descriptor.

Deprecated
collectionNames

The names of the currently loaded font collections.

Deprecated
- fontDescriptorsInCollection:

Returns an array of the font descriptors in the collection specified by the given collection name.

Deprecated
- addCollection:options:

Adds a specified font collection to the font manager with a given set of options.

Deprecated
- removeCollection:

Removes the specified font collection.

Deprecated
- addFontDescriptors:toCollection:

Adds an array of font descriptors to the specified font collection.

Deprecated
- removeFontDescriptor:fromCollection:

Removes the specified font descriptor from the specified collection.

Deprecated

Constants

Font Collection Mask

This constant specifies options accepted by addCollection:options:.

NSFontTraitMask

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

Font traits

Font traits defined and supported by NSFontManager.

NSFontAction

The action that modifyFont: will take.

Relationships

Inherits From

See Also

Management

NSFontCollection

A font collection, which is a group of font descriptors taken together as a single object.

NSMutableFontCollection

A mutable collection of fonts used to create a modifiable version of the NSFontCollection class.

NSFontCollectionOptions

Constants that support font collection management.