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 that creates the shared font manager object.

+ setFontPanelFactory:

Sets the class that creates the shared Font panel object.

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 specified font as the currently selected font and updates the Font panel.

selectedFont

The currently selected font object.

multiple

A Boolean value that indicates whether the currently selected font has multiple fonts.

- sendAction

A Boolean value that indicates whether a responder handled the font manager’s action message.

- localizedNameForFamily:face:

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

Sending Action Methods

- addFontTrait:

Adds a trait to the font.

- removeFontTrait:

Removes a trait from the font.

- modifyFont:

Modifies a trait of the font.

- modifyFontViaPanel:

Modifies a font trait using input from the Font panel.

- orderFrontStylesPanel:

Opens the Font Styles panel.

- orderFrontFontPanel:

Opens the Font panel, creating it if necessary, and displays that panel in front of the app's windows.

NSFontAction

Actions that modify a font.

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 new version of the font object containing a single additional trait.

- convertFont:toNotHaveTrait:

Returns a new version of a font object without the specified traits.

- convertFont:toSize:

Returns a font 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 a font object whose weight is greater or lesser than that of the given font.

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.

NSFontTraitMask

Constants for isolating specific traits of a font.

- weightOfFont:

Returns an approximation of the specified font's weight.

Managing the Font Panel and Font Menu

enabled

A Boolean value that indicates whether the font conversion system’s Font panel and Font menu items are enabled.

- fontPanel:

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

- setFontMenu:

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

- fontMenu:

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

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 object that receives action messages related to the font manager.

Setting Attributes

- setSelectedAttributes:isMultiple:

Informs the Font panel that the specified font attributes changed for the selected text.

- convertAttributes:

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

Deprecated

Deprecated Symbols

Review unsupported symbols and their replacements.

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 font descriptors taken together as a single object.

NSFontCollectionOptions

Constants that support font collection management.