Mac Developer Library

Developer

AppKit Framework Reference NSFontManager Class Reference

Options
Deployment Target:

On This Page
Language:

NSFontManager

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

NSFontManager 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, 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 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. Once the Font menu is installed, your application automatically gains the functionality of both the Font menu and the Font panel.

As of OS X version 10.3, font collections are managed by NSFontManager.

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

    Declaration

    Swift

    class func sharedFontManager() -> NSFontManager

    Objective-C

    + (NSFontManager *)sharedFontManager

    Return Value

    The shared font manager.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    class func setFontManagerFactory(_ aClass: AnyClass?)

    Objective-C

    + (void)setFontManagerFactory:(Class)aClass

    Parameters

    aClass

    The new font manager factory class, which should be a subclass of NSFontManager.

    Discussion

    When the NSFontManager class object receives a sharedFontManager message, it creates an instance of aClass, if no instance already exists. Your font manager class should implement init as its designated initializer. The default font manager factory is NSFontManager.

    This method must be invoked before your application’s main nib file is loaded, such as in the application delegate’s applicationWillFinishLaunching: method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    class func setFontPanelFactory(_ factoryId: AnyClass?)

    Objective-C

    + (void)setFontPanelFactory:(Class)factoryId

    Parameters

    factoryId

    The new font panel factory class, which should be a subclass of NSFontPanel.

    Discussion

    Invoke this method before accessing the Font panel in any way, such as in the application delegate’s applicationWillFinishLaunching: method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    var availableFonts: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *availableFonts

    Return Value

    The names of the available fonts.

    Discussion

    These fonts are in various system font directories.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the names of the font families available in the system.

    Declaration

    Swift

    var availableFontFamilies: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *availableFontFamilies

    Return Value

    The names of the available font families.

    Discussion

    These fonts are in various system font directories.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func availableFontNamesWithTraits(_ fontTraitMask: NSFontTraitMask) -> [AnyObject]?

    Objective-C

    - (NSArray *)availableFontNamesWithTraits:(NSFontTraitMask)fontTraitMask

    Parameters

    fontTraitMask

    The font traits for which to return font names. You specify the desired traits by combining the font trait mask values described in Constants using the C bitwise OR operator.

    Return Value

    The names of the corresponding fonts.

    Discussion

    These fonts are in various system font directories.

    If fontTraitMask is 0, this method returns all fonts that are neither italic nor bold. This result is the same one you’d get if fontTraitMask were NSUnitalicFontMask | NSUnboldFontMask.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func availableMembersOfFontFamily(_ family: String) -> [AnyObject]?

    Objective-C

    - (NSArray *)availableMembersOfFontFamily:(NSString *)family

    Parameters

    family

    The name of a font family, like one that availableFontFamilies returns.

    Return Value

    The available members of family. See the following discussion for a specific description.

    Discussion

    Each entry of the returned NSArray is another NSArray with four members, as follows:

    • 0. The PostScript font name, as an NSString object.

    • 1. The part of the font name used in the font panel that’s not the font name, as an NSString object. This value is not localized—for example, "Roman", "Italic", or "Bold".

    • 2. The font’s weight, as an NSNumber.

    • 3. The font’s traits, as an NSNumber.

    The members of the family are arranged in the font panel order (narrowest to widest, lightest to boldest, plain to italic).

    For example, if you call availableMembersOfFontFamily:@"Times", it might return an array like this:

    • (("Times-Roman", "Roman", 5, 4),
    • ("Times-Italic", "Italic", 6, 5),
    • ("Times-Bold", "Bold", 9, 2),
    • ("Times-BoldItalic", "Bold Italic", 9, 3)
    • )

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func setSelectedFont(_ aFont: NSFont, isMultiple flag: Bool)

    Objective-C

    - (void)setSelectedFont:(NSFont *)aFont isMultiple:(BOOL)flag

    Parameters

    aFont

    The font to set as selected.

    flag

    If YEStrue, the Font panel indicates that more than one font is contained in the selection; if NOfalse, it does not.

    Discussion

    An object that manipulates fonts should invoke this method whenever it becomes first responder and whenever its selection changes. It shouldn’t invoke this method in the process of handling a changeFont: message, as this causes the font manager to lose the information necessary to effect the change. After all fonts have been converted, the font manager itself records the new selected font.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the last font recorded.

    Declaration

    Swift

    var selectedFont: NSFont? { get }

    Objective-C

    @property(readonly, strong) NSFont *selectedFont

    Return Value

    The last font recorded with a setSelectedFont:isMultiple: message

    Discussion

    While fonts are being converted in response to a convertFont: message, you can determine the font selected in the Font panel like this:

    • NSFontManager *fontManager = [NSFontManager sharedFontManager];
    • panelFont = [fontManager convertFont:[fontManager selectedFont]];

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – isMultiple

  • isMultiple - isMultiple Available in OS X v10.0 through OS X v10.9

    Indicates whether the last font selection recorded has multiple fonts.

    Declaration

    Objective-C

    - (BOOL)isMultiple

    Return Value

    YEStrue if the last font selection recorded has multiple fonts; NOfalse if it’s a single font.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Sends the receiver’s action message up the responder chain, initiating a font change for whatever conversion and trait to change were last requested.

    Declaration

    Swift

    var sendAction: Bool { get }

    Objective-C

    @property(readonly) BOOL sendAction

    Return Value

    YEStrue if some object handled the changeFont: message; NOfalse if the message went unheard.

    Discussion

    By default, the receiver’s action message is changeFont:.

    This method is used internally by the font conversion system. You should never need to invoke it directly. Instead, use the action methods such as addFontTrait: or modifyFontViaPanel:.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setAction:

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

    Declaration

    Swift

    func localizedNameForFamily(_ family: String, face face: String?) -> String

    Objective-C

    - (NSString *)localizedNameForFamily:(NSString *)family face:(NSString *)face

    Parameters

    family

    The font family, for example, @"Times".

    face

    The font face, for example, @"Roman".

    Return Value

    A localized string with the name of the specified font family and face, or, if face is nil, the font family only.

    Discussion

    The user’s locale is determined from the user’s NSLanguages default setting. The method also loads the localized strings for the font, if they aren’t already loaded.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func addFontTrait(_ sender: AnyObject?)

    Objective-C

    - (void)addFontTrait:(id)sender

    Parameters

    sender

    The control that sent the message.

    Discussion

    By default, the action message is changeFont:.

    When a responder replies by providing a font to convert in a convertFont: message, the receiver converts the font by adding the trait specified by sender. This trait is determined by sending a tag message to sender and interpreting it as a font trait mask for a convertFont:toHaveTrait: message.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func removeFontTrait(_ sender: AnyObject?)

    Objective-C

    - (void)removeFontTrait:(id)sender

    Parameters

    sender

    The control that sent the message.

    Discussion

    By default, the action message is changeFont:.

    When a responder replies by providing a font to convert in a convertFont: message, the receiver converts the font by removing the trait specified by sender. This trait is determined by sending a tag message to sender and interpreting it as a font trait mask for a convertFont:toNotHaveTrait: message.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func modifyFont(_ sender: AnyObject?)

    Objective-C

    - (void)modifyFont:(id)sender

    Parameters

    sender

    The control that sent the message.

    Discussion

    By default, the action message is changeFont:.

    When a responder replies by providing a font to convert in a convertFont: message, the receiver converts the font in the manner specified by sender. The conversion is determined by sending a tag message to sender and invoking a corresponding method:

    Sender’s Tag

    Method Used

    NSNoFontChangeAction

    None; the font is returned unchanged.

    NSViaPanelFontAction

    The Font panel’s panelConvertFont:.

    NSAddTraitFontAction

    convertFont:toHaveTrait:.

    NSRemoveTraitFontAction

    convertFont:toNotHaveTrait:.

    NSSizeUpFontAction

    convertFont:toSize:.

    NSSizeDownFontAction

    convertFont:toSize:.

    NSHeavierFontAction

    convertWeight:ofFont:.

    NSLighterFontAction

    convertWeight:ofFont:.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func modifyFontViaPanel(_ sender: AnyObject?)

    Objective-C

    - (void)modifyFontViaPanel:(id)sender

    Parameters

    sender

    The control that sent the message.

    Discussion

    By default, the action message is changeFont:.

    When a responder replies by providing a font to convert in a convertFont: message, the receiver converts the font by sending a panelConvertFont: message to the Font panel. The panel in turn may send convertFont:toFamily:, convertFont:toHaveTrait:, and other specific conversion methods to make its change.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This action method opens the Font styles panel.

    Declaration

    Swift

    func orderFrontStylesPanel(_ sender: AnyObject?)

    Objective-C

    - (void)orderFrontStylesPanel:(id)sender

    Parameters

    sender

    The control that sent the message.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

    func orderFrontFontPanel(_ sender: AnyObject?)

    Objective-C

    - (void)orderFrontFontPanel:(id)sender

    Parameters

    sender

    The control that sent the message.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func convertFont(_ aFont: NSFont, toFace typeface: String) -> NSFont?

    Objective-C

    - (NSFont *)convertFont:(NSFont *)aFont toFace:(NSString *)typeface

    Parameters

    aFont

    The font whose traits are matched.

    typeface

    The new typeface; a fully specified family-face name, such as Helvetica-BoldOblique or Times-Roman.

    Return Value

    A font with matching traits and the given typeface, or aFont if it can’t be converted.

    Discussion

    This method attempts to match the weight and posture of aFont as closely as possible. Italic is mapped to Oblique, for example. Weights are mapped based on an approximate numeric scale of 0 to 15.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func convertFont(_ aFont: NSFont, toFamily family: String) -> NSFont

    Objective-C

    - (NSFont *)convertFont:(NSFont *)aFont toFamily:(NSString *)family

    Parameters

    aFont

    The font whose traits are matched.

    family

    The new font family; a generic font name, such as Helvetica or Times.

    Return Value

    A font with matching traits and the given family, or aFont if it can’t be converted.

    Discussion

    This method attempts to match the weight and posture of aFont as closely as possible. Italic is mapped to Oblique, for example. Weights are mapped based on an approximate numeric scale of 0 to 15.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func convertFont(_ aFont: NSFont, toHaveTrait fontTrait: NSFontTraitMask) -> NSFont

    Objective-C

    - (NSFont *)convertFont:(NSFont *)aFont toHaveTrait:(NSFontTraitMask)fontTrait

    Parameters

    aFont

    The font whose traits are matched.

    fontTrait

    The new trait; may be any one of the traits described in Constants. Using NSUnboldFontMask or NSUnitalicFontMask removes the bold or italic trait, respectively.

    Return Value

    A font with matching traits including the given trait, or aFont if it can’t be converted.

    Discussion

    Using NSUnboldFontMask or NSUnitalicFontMask removes the bold or italic trait, respectively.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func convertFont(_ aFont: NSFont, toNotHaveTrait fontTraitMask: NSFontTraitMask) -> NSFont

    Objective-C

    - (NSFont *)convertFont:(NSFont *)aFont toNotHaveTrait:(NSFontTraitMask)fontTraitMask

    Parameters

    aFont

    The font whose traits are matched.

    fontTraitMask

    The mask for the traits to remove, created using the C bitwise OR operator to combine the traits described in Constants. Using NSBoldFontMask or NSItalicFontMask removes the bold or italic trait, respectively.

    Return Value

    A font with matching traits minus the given traits, or aFont if it can’t be converted.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func convertFont(_ aFont: NSFont, toSize size: CGFloat) -> NSFont

    Objective-C

    - (NSFont *)convertFont:(NSFont *)aFont toSize:(CGFloat)size

    Parameters

    aFont

    The font whose traits are matched.

    size

    The new font size.

    Return Value

    A font with matching traits except in the new size, or aFont if it can’t be converted.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func convertWeight(_ increaseFlag: Bool, ofFont aFont: NSFont) -> NSFont

    Objective-C

    - (NSFont *)convertWeight:(BOOL)increaseFlag ofFont:(NSFont *)aFont

    Parameters

    increaseFlag

    If YEStrue, a heavier font is returned; if it’s NOfalse, a lighter font is returned.

    aFont

    The font whose weight is increased or decreased.

    Return Value

    A font with matching traits except for the new weight, or aFont if it can’t be converted.

    Discussion

    Weights are graded along the following scale. The list on the left gives Apple’s terminology, and the list on the right gives the ISO equivalents. Names on the same line are treated as identical:

    Apple Terminology

    ISO Equivalent

    1. ultralight

    2. thin

    W1. ultralight

    3. light, extralight

    W2. extralight

    4. book

    W3. light

    5. regular, plain, display, roman

    W4. semilight

    6. medium

    W5. medium

    7. demi, demibold

    8. semi, semibold

    W6. semibold

    9. bold

    W7. bold

    10. extra, extrabold

    W8. extrabold

    11. heavy, heavyface

    12. black, super

    W9. ultrabold

    13. ultra, ultrablack, fat

    14. extrablack, obese, nord

    The NSFontManager implementation of this method refuses to convert a font’s weight if it can’t maintain all other traits, such as italic and condensed. You might wish to override this method to allow a looser interpretation of weight conversion.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the current font conversion action.

    Declaration

    Swift

    var currentFontAction: NSFontAction { get }

    Objective-C

    @property(readonly) NSFontAction currentFontAction

    Return Value

    The current font action used by the convertFont: method.

    Discussion

    This method is intended to be invoked to query the font conversion action while the action message (usually changeFont:) is being invoked.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Converts font traits to a new traits mask value.

    Declaration

    Swift

    func convertFontTraits(_ traits: NSFontTraitMask) -> NSFontTraitMask

    Objective-C

    - (NSFontTraitMask)convertFontTraits:(NSFontTraitMask)traits

    Parameters

    traits

    The current font traits.

    Return Value

    The new traits mask value to be used by convertFont:.

    Discussion

    This method is intended to be invoked to query the font traits while the action message (usually changeFont:) is being invoked when the current font action is either NSAddTraitFontAction or NSRemoveTraitFontAction.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Attempts to load a font with the specified characteristics.

    Declaration

    Swift

    func fontWithFamily(_ family: String, traits fontTraitMask: NSFontTraitMask, weight weight: Int, size size: CGFloat) -> NSFont?

    Objective-C

    - (NSFont *)fontWithFamily:(NSString *)family traits:(NSFontTraitMask)fontTraitMask weight:(NSInteger)weight size:(CGFloat)size

    Parameters

    family

    The generic name of the desired font, such as Times or Helvetica.

    fontTraitMask

    The font traits, specified by combining the font trait mask values described in Constants using the C bitwise OR operator. Using NSUnboldFontMask or NSUnitalicFontMask loads a font that doesn’t have either the bold or italic trait, respectively.

    weight

    A hint for the weight desired, on a scale of 0 to 15: a value of 5 indicates a normal or book weight, and 9 or more a bold or heavier weight. The weight is ignored if fontTraitMask includes NSBoldFontMask.

    size

    The point size of the desired font.

    Return Value

    A font with the specified characteristics if successful, or nil if not.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the traits of the given font.

    Declaration

    Swift

    func traitsOfFont(_ aFont: NSFont) -> NSFontTraitMask

    Objective-C

    - (NSFontTraitMask)traitsOfFont:(NSFont *)aFont

    Parameters

    aFont

    The font whose traits are returned.

    Return Value

    The font traits, returned as a mask created by combining values listed in Constants with the C bitwise OR operator.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Indicates whether the given font has all the specified traits.

    Declaration

    Swift

    func fontNamed(_ typeface: String, hasTraits fontTraitMask: NSFontTraitMask) -> Bool

    Objective-C

    - (BOOL)fontNamed:(NSString *)typeface hasTraits:(NSFontTraitMask)fontTraitMask

    Parameters

    typeface

    The name of the font.

    fontTraitMask

    The font traits to test, specified by combining the font trait mask values described in Constants using the C bitwise OR operator.

    Return Value

    YEStrue if the font named typeface has all the traits specified in fontTraitMask; NOfalse if it doesn’t.

    Discussion

    Using NSUnboldFontMask returns YEStrue if the font is not bold, NOfalse otherwise. Using NSUnitalicFontMask returns YEStrue if the font is not italic, NOfalse otherwise.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func weightOfFont(_ aFont: NSFont) -> Int

    Objective-C

    - (NSInteger)weightOfFont:(NSFont *)aFont

    Parameters

    aFont

    The font whose weight is returned.

    Return Value

    A rough numeric measure the weight of the given font, where 0 indicates the lightest possible weight, 5 indicates a normal or book weight, and 9 or more indicates a bold or heavier weight.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Controls whether the font conversion system’s user interface items (the Font panel and Font menu items) are enabled.

    Declaration

    Swift

    var enabled: Bool

    Objective-C

    @property(getter=isEnabled) BOOL enabled

    Parameters

    flag

    If YEStrue, they’re enabled; if NOfalse, they’re disabled.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    setEnabled: (NSFontPanel)
    – isEnabled

  • isEnabled - isEnabled Available in OS X v10.0 through OS X v10.9

    Indicates whether the font conversion system’s user interface items (the Font panel and Font menu items) are enabled.

    Declaration

    Objective-C

    - (BOOL)isEnabled

    Return Value

    YEStrue if the font conversion system’s user interface items (the Font panel and Font menu items) are enabled; NOfalse if they’re not.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

    See Also

    isEnabled (NSFontPanel)
    isEnabled (NSMenuItem)
    – setEnabled:

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

    Declaration

    Swift

    func fontManager(_ theFontManager: AnyObject, willIncludeFont fontName: String) -> Bool

    Objective-C

    - (BOOL)fontManager:(id)theFontManager willIncludeFont:(NSString *)fontName

    Discussion

    In OS X versions 10.2 and earlier, this method is invoked repeatedly as necessary whenever the Font panel needs updating, such as when the Font panel is first loaded, and when the user selects a family name to see which typefaces in that family are available. Your implementation should execute fairly quickly to ensure the responsiveness of the Font panel.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func fontPanel(_ createFlag: Bool) -> NSFontPanel?

    Objective-C

    - (NSFontPanel *)fontPanel:(BOOL)createFlag

    Parameters

    createFlag

    If YEStrue, the Font panel object is created if necessary; if NOfalse, it is not.

    Return Value

    The application’s shared Font panel object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func setFontMenu(_ aMenu: NSMenu)

    Objective-C

    - (void)setFontMenu:(NSMenu *)aMenu

    Parameters

    aMenu

    The new Font menu.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – fontMenu:

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

    Declaration

    Swift

    func fontMenu(_ createFlag: Bool) -> NSMenu?

    Objective-C

    - (NSMenu *)fontMenu:(BOOL)createFlag

    Parameters

    createFlag

    If YEStrue, the menu object is created if necessary; if NOfalse, it is not.

    Return Value

    The font conversion system menu.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s delegate to the given object.

    Declaration

    Swift

    unowned(unsafe) var delegate: AnyObject?

    Objective-C

    @property(assign) id delegate

    Parameters

    anObject

    The new delegate.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – delegate

  • Returns the receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: AnyObject?

    Objective-C

    @property(assign) id delegate

    Return Value

    The receiver’s delegate.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the action that’s sent to the first responder, when the user selects a new font from the Font panel or chooses a command from the Font menu, to the given selector.

    Declaration

    Swift

    var action: Selector

    Objective-C

    @property SEL action

    Parameters

    aSelector

    The selector to set.

    Discussion

    The default action is changeFont:. You should rarely need to change this setting.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – action

  • Returns 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.

    Declaration

    Swift

    var action: Selector

    Objective-C

    @property SEL action

    Return Value

    The selector for the action.

    Discussion

    The default action is changeFont:.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setAction:

  • Sets the target for the sendAction method.

    Declaration

    Swift

    weak var target: AnyObject?

    Objective-C

    @property(weak) id target

    Parameters

    aTarget

    The target to set.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    – target

  • Returns the target for the sendAction method.

    Declaration

    Swift

    weak var target: AnyObject?

    Objective-C

    @property(weak) id target

    Return Value

    The target for the receiver’s sendAction method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    – setTarget:

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

    Declaration

    Swift

    func setSelectedAttributes(_ attributes: [NSObject : AnyObject], isMultiple flag: Bool)

    Objective-C

    - (void)setSelectedAttributes:(NSDictionary *)attributes isMultiple:(BOOL)flag

    Parameters

    attributes

    The new attributes.

    flag

    If YEStrue, informs the panel that multiple fonts or attributes are enclosed within the selection.

    Discussion

    This method is used primarily by NSTextView.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

    func convertAttributes(_ attributes: [NSObject : AnyObject]) -> [NSObject : AnyObject]

    Objective-C

    - (NSDictionary *)convertAttributes:(NSDictionary *)attributes

    Parameters

    attributes

    The current attributes.

    Return Value

    The converted attributes, or attributes itself if the conversion isn’t possible.

    Discussion

    Attributes unused by the sender should not be changed or removed.

    This method is usually invoked on the sender of changeAttributes:. See Working with the Font Manager for more information.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

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

    Use NSFontDescriptor method matchingFontDescriptorsWithMandatoryKeys: instead.

    Declaration

    Swift

    func availableFontNamesMatchingFontDescriptor(_ descriptor: NSFontDescriptor) -> [AnyObject]?

    Objective-C

    - (NSArray *)availableFontNamesMatchingFontDescriptor:(NSFontDescriptor *)descriptor

    Parameters

    descriptor

    The font descriptor whose attributes are matched.

    Return Value

    The names of the matching fonts.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the names of the currently loaded font collections.

    Declaration

    Swift

    var collectionNames: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *collectionNames

    Return Value

    The names of the current font collections.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

    func fontDescriptorsInCollection(_ collectionName: String) -> [AnyObject]?

    Objective-C

    - (NSArray *)fontDescriptorsInCollection:(NSString *)collectionName

    Parameters

    collectionName

    The font collection for which to return descriptors.

    Return Value

    The font descriptors.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

    func addCollection(_ collectionName: String, options collectionOptions: NSFontCollectionOptions) -> Bool

    Objective-C

    - (BOOL)addCollection:(NSString *)collectionName options:(NSFontCollectionOptions)collectionOptions

    Parameters

    collectionName

    The collection to add.

    collectionOptions

    The option described in “Font Collection Mask”. This option is not yet implemented.

    Return Value

    YEStrue if the font collection was successfully added; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Removes the specified font collection.

    Declaration

    Swift

    func removeCollection(_ collectionName: String) -> Bool

    Objective-C

    - (BOOL)removeCollection:(NSString *)collectionName

    Parameters

    collectionName

    The collection to remove.

    Return Value

    YEStrue if the font collection was successfully removed; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

    func addFontDescriptors(_ descriptors: [AnyObject], toCollection collectionName: String)

    Objective-C

    - (void)addFontDescriptors:(NSArray *)descriptors toCollection:(NSString *)collectionName

    Parameters

    descriptors

    The font descriptors to add.

    collectionName

    The font collection to which descriptors are added.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Removes the specified font descriptor from the specified collection.

    Declaration

    Swift

    func removeFontDescriptor(_ descriptor: NSFontDescriptor, fromCollection collection: String)

    Objective-C

    - (void)removeFontDescriptor:(NSFontDescriptor *)descriptor fromCollection:(NSString *)collection

    Parameters

    descriptor

    The font descriptor to remove.

    collection

    The font collection from which to remove the descriptor.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

Data Types

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

    Declaration

    Swift

    struct NSFontTraitMask : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var ItalicFontMask: NSFontTraitMask { get } static var BoldFontMask: NSFontTraitMask { get } static var UnboldFontMask: NSFontTraitMask { get } static var NonStandardCharacterSetFontMask: NSFontTraitMask { get } static var NarrowFontMask: NSFontTraitMask { get } static var ExpandedFontMask: NSFontTraitMask { get } static var CondensedFontMask: NSFontTraitMask { get } static var SmallCapsFontMask: NSFontTraitMask { get } static var PosterFontMask: NSFontTraitMask { get } static var CompressedFontMask: NSFontTraitMask { get } static var FixedPitchFontMask: NSFontTraitMask { get } static var UnitalicFontMask: NSFontTraitMask { get } }

    Objective-C

    typedef unsigned int NSFontTraitMask;

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • These constants specify what action modifyFont: will take.

    Declaration

    Swift

    enum NSFontAction : UInt { case NoFontChangeAction case ViaPanelFontAction case AddTraitFontAction case SizeUpFontAction case SizeDownFontAction case HeavierFontAction case LighterFontAction case RemoveTraitFontAction }

    Objective-C

    typedef enum _NSFontAction { NSNoFontChangeAction = 0, NSViaPanelFontAction = 1, NSAddTraitFontAction = 2, NSSizeUpFontAction = 3, NSSizeDownFontAction = 4, NSHeavierFontAction = 5, NSLighterFontAction = 6, NSRemoveTraitFontAction = 7 } NSFontAction;

    Constants

    • NoFontChangeAction

      NSNoFontChangeAction

      No action; the font is returned unchanged.

      Available in OS X v10.0 and later.

    • ViaPanelFontAction

      NSViaPanelFontAction

      Converts the font according to the NSFontPanel method panelConvertFont:.

      Available in OS X v10.0 and later.

    • AddTraitFontAction

      NSAddTraitFontAction

      Converts the font to have an additional trait using convertFont:toHaveTrait:.

      Available in OS X v10.0 and later.

    • SizeUpFontAction

      NSSizeUpFontAction

      Converts the font to a larger size using convertFont:toSize:.

      Available in OS X v10.0 and later.

    • SizeDownFontAction

      NSSizeDownFontAction

      Converts the font to a smaller size using convertFont:toSize:.

      Available in OS X v10.0 and later.

    • HeavierFontAction

      NSHeavierFontAction

      Converts the font to a heavier weight using convertWeight:ofFont:.

      Available in OS X v10.0 and later.

    • LighterFontAction

      NSLighterFontAction

      Converts the font to a lighter weight using convertWeight:ofFont:.

      Available in OS X v10.0 and later.

    • RemoveTraitFontAction

      NSRemoveTraitFontAction

      Converts the font to remove a trait using convertFont:toNotHaveTrait:.

      Available in OS X v10.0 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • This constant specifies options accepted by addCollection:options:.

    Declaration

    Swift

    static var ApplicationOnlyMask: NSFontCollectionOptions { get }

    Objective-C

    enum { NSFontCollectionApplicationOnlyMask = 1 << 0 };

    Constants

    • ApplicationOnlyMask

      NSFontCollectionApplicationOnlyMask

      Makes the collection available only to the application. This option is not yet implemented.

      Available in OS X v10.3 and later.

  • Font traits defined and supported by NSFontManager.

    Declaration

    Swift

    static var ItalicFontMask: NSFontTraitMask { get } static var BoldFontMask: NSFontTraitMask { get } static var UnboldFontMask: NSFontTraitMask { get } static var NonStandardCharacterSetFontMask: NSFontTraitMask { get } static var NarrowFontMask: NSFontTraitMask { get } static var ExpandedFontMask: NSFontTraitMask { get } static var CondensedFontMask: NSFontTraitMask { get } static var SmallCapsFontMask: NSFontTraitMask { get } static var PosterFontMask: NSFontTraitMask { get } static var CompressedFontMask: NSFontTraitMask { get } static var FixedPitchFontMask: NSFontTraitMask { get } static var UnitalicFontMask: NSFontTraitMask { get }

    Objective-C

    enum { NSItalicFontMask = 0x00000001, NSBoldFontMask = 0x00000002, NSUnboldFontMask = 0x00000004, NSNonStandardCharacterSetFontMask = 0x00000008, NSNarrowFontMask = 0x00000010, NSExpandedFontMask = 0x00000020, NSCondensedFontMask = 0x00000040, NSSmallCapsFontMask = 0x00000080, NSPosterFontMask = 0x00000100, NSCompressedFontMask = 0x00000200, NSFixedPitchFontMask = 0x00000400, NSUnitalicFontMask = 0x01000000 };

    Constants

    • ItalicFontMask

      NSItalicFontMask

      A mask that specifies an italic font.

      Available in OS X v10.0 and later.

    • BoldFontMask

      NSBoldFontMask

      A mask that specifies a bold font.

      Available in OS X v10.0 and later.

    • UnboldFontMask

      NSUnboldFontMask

      A mask that specifies a font that is not bold.

      Available in OS X v10.0 and later.

    • NonStandardCharacterSetFontMask

      NSNonStandardCharacterSetFontMask

      A mask that specifies a font that uses a non-standard character set.

      Available in OS X v10.0 and later.

    • NarrowFontMask

      NSNarrowFontMask

      A mask that specifies a narrow font.

      Available in OS X v10.0 and later.

    • ExpandedFontMask

      NSExpandedFontMask

      A mask that specifies an expanded font.

      Available in OS X v10.0 and later.

    • CondensedFontMask

      NSCondensedFontMask

      A mask that specifies a condensed font.

      Available in OS X v10.0 and later.

    • SmallCapsFontMask

      NSSmallCapsFontMask

      A mask that specifies a small-caps font.

      Available in OS X v10.0 and later.

    • PosterFontMask

      NSPosterFontMask

      A mask that specifies a poster-style font.

      Available in OS X v10.0 and later.

    • CompressedFontMask

      NSCompressedFontMask

      A mask that specifies a compressed font.

      Available in OS X v10.0 and later.

    • FixedPitchFontMask

      NSFixedPitchFontMask

      A mask that specifies a fixed pitch font.

      Available in OS X v10.0 and later.

    • UnitalicFontMask

      NSUnitalicFontMask

      A mask that specifies a font that is not italic.

      Available in OS X v10.0 and later.

    Discussion

    NSFontManager categorizes fonts according to a small set of traits. You can convert fonts by adding and removing individual traits, and you can get a font with a specific combination of traits.

    These pairs of traits are mutually exclusive:

    • NSCondensedFontMask and NSExpandedFontMask

    • NSBoldFontMask and NSUnboldFontMask

    • NSItalicFontMask and NSUnitalicFontMask