Class

NSFont​Manager

NSFont​Manager is the center of activity for the font conversion system. It 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, NSFont​Manager 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.

Overview

You normally 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 application’s main menu. After the Font menu is installed, your application automatically gains the functionality of both the Font menu and the Font panel.

Font collections are managed by NSFont​Manager.

Symbols

Getting the Shared Font Manager

class func shared()

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

Changing the Default Font Conversion Classes

class func set​Font​Manager​Factory(Any​Class?)

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

class func set​Font​Panel​Factory(Any​Class?)

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

Getting Available Fonts

var available​Fonts:​ [String]

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

var available​Font​Families:​ [String]

The names of the font families available in the system.

func available​Font​Names(with:​ NSFont​Trait​Mask)

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).

func available​Members(of​Font​Family:​ String)

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

Setting and Examining the Selected Font

func set​Selected​Font(NSFont, is​Multiple:​ Bool)

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

var selected​Font:​ NSFont?

The last font recorded.

var is​Multiple:​ Bool

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

func send​Action()

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

func localized​Name(for​Family:​ String, face:​ String?)

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

Sending Action Methods

func add​Font​Trait(Any?)

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

func remove​Font​Trait(Any?)

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

func modify​Font(Any?)

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

func modify​Font​Via​Panel(Any?)

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

func order​Front​Styles​Panel(Any?)

This action method opens the Font styles panel.

func order​Front​Font​Panel(Any?)

This action method opens the Font panel by sending it an order​Front(_:​) message, creating the Font panel if necessary.

Converting Fonts Automatically

func convert(NSFont)

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

func change​Font(Any?)

Informs responders of a font change.

Converting Fonts Manually

func convert(NSFont, to​Face:​ String)

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.

func convert(NSFont, to​Family:​ String)

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.

func convert(NSFont, to​Have​Trait:​ NSFont​Trait​Mask)

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.

func convert(NSFont, to​Not​Have​Trait:​ NSFont​Trait​Mask)

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.

func convert(NSFont, to​Size:​ CGFloat)

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.

func convert​Weight(Bool, of:​ NSFont)

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

var current​Font​Action:​ NSFont​Action

The current font conversion action.

func convert​Font​Traits(NSFont​Trait​Mask)

Converts font traits to a new traits mask value.

Getting a Particular Font

Examining Fonts

func traits(of:​ NSFont)

Returns the traits of the given font.

func font​Named(String, has​Traits:​ NSFont​Trait​Mask)

Indicates whether the given font has all the specified traits.

func weight(of:​ NSFont)

Returns a rough numeric measure the weight of the given font.

Managing the Font Panel and Font Menu

var is​Enabled:​ Bool

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

func font​Manager(Any, will​Include​Font:​ String)

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

Deprecated
func font​Panel(Bool)

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

func set​Font​Menu(NSMenu)

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

func font​Menu(Bool)

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

Accessing the Delegate

var delegate:​ Any​Object?

The font manager’s delegate.

Deprecated

Accessing the Action Property

var action:​ Selector

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.

var target:​ Any​Object?

The target for the action associated with the send​Action() property.

Setting Attributes

func set​Selected​Attributes([String :​ Any], is​Multiple:​ Bool)

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

func convert​Attributes([String :​ Any] = [:​])

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

Working with Font Descriptors

func available​Font​Names(matching:​ NSFont​Descriptor)

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

Deprecated
var collection​Names:​ [Any]

The names of the currently loaded font collections.

Deprecated
func font​Descriptors(in​Collection:​ String)

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

Deprecated
func add​Collection(String, options:​ NSFont​Collection​Options = [])

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

Deprecated
func remove​Collection(String)

Removes the specified font collection.

Deprecated
func add​Font​Descriptors([Any], to​Collection:​ String)

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

Deprecated
func remove​Font​Descriptor(NSFont​Descriptor, from​Collection:​ String)

Removes the specified font descriptor from the specified collection.

Deprecated

Constants

Font Collection Mask

This constant specifies options accepted by add​Collection(_:​options:​).

NSFont​Trait​Mask

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

Font traits

Font traits defined and supported by NSFont​Manager.

NSFont​Action

These constants specify what action modify​Font(_:​) will take.

Relationships

Inherits From