Mac Developer Library

Developer

AppKit Framework Reference NSFontCollection Class Reference

Options
Deployment Target:

On This Page
Language:

NSFontCollection

The NSFontCollection class represents a font collection, that is, a group of font descriptors taken together as a single object. You can publicize the font collection as a named collection and it is presented through the System user interface such as the font panel & Font Book. The queries can be modifed using the NSMutableFontCollection subclass.

Inheritance


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.7 and later.
  • Returns a font collection matching the given descriptors.

    Declaration

    Swift

    init(descriptors queryDescriptors: [AnyObject]) -> NSFontCollection

    Objective-C

    + (NSFontCollection *)fontCollectionWithDescriptors:(NSArray *)queryDescriptors

    Parameters

    queryDescriptors

    The descriptors used to match the returned collection.

    Return Value

    The font collection matching the given descriptors.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns a font collection matching all registered fonts.

    Declaration

    Swift

    class func fontCollectionWithAllAvailableDescriptors() -> NSFontCollection

    Objective-C

    + (NSFontCollection *)fontCollectionWithAllAvailableDescriptors

    Return Value

    The collection of all fonts available to the current application.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns a collection of fonts matching the given locale.

    Declaration

    Swift

    init?(locale locale: NSLocale) -> NSFontCollection

    Objective-C

    + (NSFontCollection *)fontCollectionWithLocale:(NSLocale *)locale

    Parameters

    locale

    The locale to match.

    Return Value

    A collection of fonts matching the given locale.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Renames the font collection with the specified name and visibility to the second name specified.

    Declaration

    Swift

    class func renameFontCollectionWithName(_ name: String, visibility visibility: NSFontCollectionVisibility, toName name: String, error error: NSErrorPointer) -> Bool

    Objective-C

    + (BOOL)renameFontCollectionWithName:(NSString *)name visibility:(NSFontCollectionVisibility)visibility toName:(NSString *)name error:(NSError **)error

    Parameters

    name

    The collection to rename.

    visibility

    The visibility of the collection to rename.

    name

    The new name to give to the collection.

    error

    If unsuccessful, a reference to an NSFileManager error object that encapsulates the reason the font collection could not be renamed.

    Return Value

    YEStrue if the method was successful; NOfalse otherwise.

    Discussion

    Named collections are shown by user interfaces such as the Font panel. When you change the collection, you must show it again to see the changes reflected on disk or in the Font panel.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Make the given font collection visible by giving it a name.

    Declaration

    Swift

    class func showFontCollection(_ collection: NSFontCollection, withName name: String, visibility visibility: NSFontCollectionVisibility, error error: NSErrorPointer) -> Bool

    Objective-C

    + (BOOL)showFontCollection:(NSFontCollection *)collection withName:(NSString *)name visibility:(NSFontCollectionVisibility)visibility error:(NSError **)error

    Parameters

    collection

    The font collection to make visible.

    name

    The name to associate with the collection.

    visibility

    The visibility of the collection to show.

    error

    If unsuccessful, a reference to an NSFileManager error object that encapsulates the reason the font collection could not be renamed.

    Return Value

    YEStrue if the method was successful; NOfalse otherwise.

    Discussion

    Named collections are shown by user interfaces such as the Font panel. When you change the collection, you must show it again to see the changes reflected on disk or in the Font panel.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Remove from view the named font collection with the specified visibility.

    Declaration

    Swift

    class func hideFontCollectionWithName(_ name: String, visibility visibility: NSFontCollectionVisibility, error error: NSErrorPointer) -> Bool

    Objective-C

    + (BOOL)hideFontCollectionWithName:(NSString *)name visibility:(NSFontCollectionVisibility)visibility error:(NSError **)error

    Parameters

    name

    The name of the collection.

    visibility

    The visibility of the collection.

    error

    If unsuccessful, a reference to an NSFileManager error object that encapsulates the reason the font collection could not be returned.

    Return Value

    YEStrue if the method was successful; NOfalse otherwise.

    Discussion

    For a persistent font collection, this method deletes the named font collection from disk.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns all named collections visible to this process.

    Declaration

    Swift

    class func allFontCollectionNames() -> [AnyObject]

    Objective-C

    + (NSArray *)allFontCollectionNames

    Return Value

    NSString objects containing the names of all the named collections.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns the font collection with the specified name.

    Declaration

    Swift

    init?(name name: String) -> NSFontCollection

    Objective-C

    + (NSFontCollection *)fontCollectionWithName:(NSString *)name

    Parameters

    name

    The name of the collection.

    Return Value

    The named font collection.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns the font collection with the specified name and visibility.

    Declaration

    Swift

    init?(name name: String, visibility visibility: NSFontCollectionVisibility) -> NSFontCollection

    Objective-C

    + (NSFontCollection *)fontCollectionWithName:(NSString *)name visibility:(NSFontCollectionVisibility)visibility

    Parameters

    name

    The name of the collection.

    visibility

    The visibility of the collection.

    Return Value

    The font collection with the specified nam and visibility.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an array of font descriptors matching the logical descriptors.

    Declaration

    Swift

    var matchingDescriptors: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *matchingDescriptors

    Return Value

    The font descriptors matching queryDescriptors minus those matching exclusionDescriptors.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an array of font descriptors matching the logical descriptors for the given font family.

    Declaration

    Swift

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

    Objective-C

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

    Parameters

    family

    The font family whose descriptors are matched.

    Return Value

    The matchingDescriptors for the given family.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an array of font descriptors matching the logical descriptors for the given font family and options.

    Declaration

    Swift

    func matchingDescriptorsForFamily(_ family: String, options options: [NSObject : AnyObject]?) -> [AnyObject]?

    Objective-C

    - (NSArray *)matchingDescriptorsForFamily:(NSString *)family options:(NSDictionary *)options

    Parameters

    family

    The font family whose descriptors are matched.

    options

    A dictionary containing any combination of the Matching Descriptors Options keys or nil.

    Return Value

    The matchingDescriptors for the given family and options.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an array of font descriptors matching the logical descriptors with the given options.

    Declaration

    Swift

    func matchingDescriptorsWithOptions(_ options: [NSObject : AnyObject]?) -> [AnyObject]?

    Objective-C

    - (NSArray *)matchingDescriptorsWithOptions:(NSDictionary *)options

    Parameters

    options

    A dictionary containing any combination of the Matching Descriptors Options keys or nil.

    Return Value

    The matchingDescriptors for the given options.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an array of font descriptors whose matching results produce the collection’s matching descriptors.

    Declaration

    Swift

    var queryDescriptors: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *queryDescriptors

    Return Value

    The font descriptors matched at runtime to produce matchingDescriptors.

    Discussion

    The font descriptors matching exclusionDescriptors are removed from matchingDescriptors.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns a list of query font descriptors whose matching results are excluded from the list of matching descriptors.

    Declaration

    Swift

    var exclusionDescriptors: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *exclusionDescriptors

    Return Value

    The font descriptors used to match for exclusion descriptors.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • The constants represent the standard mutable collection names—these names are included in the list of allFontCollectionNames--they have special meaning to the Cocoa font system and should not be hidden or renamed.

    Declaration

    Swift

    let NSFontCollectionAllFonts: NSString! let NSFontCollectionUser: NSString! let NSFontCollectionFavorites: NSString! let NSFontCollectionRecentlyUsed: NSString!

    Objective-C

    NSString * const NSFontCollectionAllFonts; NSString * const NSFontCollectionUser; NSString * const NSFontCollectionFavorites; NSString * const NSFontCollectionRecentlyUsed;

    Constants

    • NSFontCollectionAllFonts

      NSFontCollectionAllFonts

      All fonts in the system.

      Available in OS X v10.7 and later.

    • NSFontCollectionUser

      NSFontCollectionUser

      Per-user unmodifiable collection.

      Available in OS X v10.7 and later.

    • NSFontCollectionFavorites

      NSFontCollectionFavorites

      Font collection of the user's preferred font descriptors.

      Available in OS X v10.7 and later.

    • NSFontCollectionRecentlyUsed

      NSFontCollectionRecentlyUsed

      Font collection automatically maintained by NSFontManager.

      Available in OS X v10.7 and later.

  • These constants are used by the matchingDescriptorsWithOptions: and matchingDescriptorsForFamily:options: options dictionary parameters.

    Declaration

    Swift

    let NSFontCollectionIncludeDisabledFontsOption: NSString! let NSFontCollectionRemoveDuplicatesOption: NSString! let NSFontCollectionDisallowAutoActivationOption: NSString!

    Objective-C

    NSString * const NSFontCollectionIncludeDisabledFontsOption; NSString * const NSFontCollectionRemoveDuplicatesOption; NSString * const NSFontCollectionDisallowAutoActivationOption;

    Constants

    • NSFontCollectionIncludeDisabledFontsOption

      NSFontCollectionIncludeDisabledFontsOption

      An NSNumber object containing a Boolean value specifying whether disabled fonts should be included in the list of matching descriptors; YEStrue if they should be included, NOfalse otherwise.. When unspecified, CoreText assumes NOfalse. This option is intended only for font management applications. This option will make descriptor matching slower.

      Available in OS X v10.7 and later.

    • NSFontCollectionRemoveDuplicatesOption

      NSFontCollectionRemoveDuplicatesOption

      An NSNumber object containing a Boolean value controlling whether more than one copy of a font with the same PostScript name should be included in the list of matching descriptors.

      Available in OS X v10.7 and later.

    • NSFontCollectionDisallowAutoActivationOption

      NSFontCollectionDisallowAutoActivationOption

      An NSNumber object containing a Boolean value specifying that auto-activation should not be used to find missing fonts.

      Available in OS X v10.7 and later.

  • These constants specify the visibility of font collections.

    Declaration

    Swift

    struct NSFontCollectionVisibility : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var Process: NSFontCollectionVisibility { get } static var User: NSFontCollectionVisibility { get } static var Computer: NSFontCollectionVisibility { get } }

    Objective-C

    enum { NSFontCollectionVisibilityProcess = (1UL << 0), NSFontCollectionVisibilityUser = (1UL << 1), NSFontCollectionVisibilityComputer = (1UL << 2) }; typedef NSUInteger NSFontCollectionVisibility;

    Constants

    • Process

      NSFontCollectionVisibilityProcess

      The font collection is visible within this process and is not persistent.

      Available in OS X v10.7 and later.

    • User

      NSFontCollectionVisibilityUser

      The font collection is visible to all processes and is stored persistently.

      Available in OS X v10.7 and later.

    • Computer

      NSFontCollectionVisibilityComputer

      The font collection is visible to all users and is stored persistently.

      Available in OS X v10.7 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • These constants are used as keys in the NSFontCollectionDidChangeNotification userInfo dictionary to indicate the changes that have taken place.

    Declaration

    Swift

    let NSFontCollectionActionKey: NSString! let NSFontCollectionNameKey: NSString! let NSFontCollectionOldNameKey: NSString! let NSFontCollectionVisibilityKey: NSString!

    Objective-C

    NSString * const NSFontCollectionActionKey; NSString * const NSFontCollectionNameKey; NSString * const NSFontCollectionOldNameKey; NSString * const NSFontCollectionVisibilityKey;

    Constants

    • NSFontCollectionActionKey

      NSFontCollectionActionKey

      An action was taken. See NSFontCollectionAction Key Values for the possible values. An NSString.

      Available in OS X v10.7 and later.

    • NSFontCollectionNameKey

      NSFontCollectionNameKey

      The font collection’s name. If renamed, this is the new name. An NSString.

      Available in OS X v10.7 and later.

    • NSFontCollectionOldNameKey

      NSFontCollectionOldNameKey

      Included as a value for the NSFontCollectionOldNameKey key, if present. This is the previous name. An NSString.

      Available in OS X v10.7 and later.

    • NSFontCollectionVisibilityKey

      NSFontCollectionVisibilityKey

      The visibly of the font collection. An NSNumber containing a value from the NSFontCollectionVisibility enum.

      Available in OS X v10.7 and later.

  • The following actions are possible values of the NSFontCollectionActionKey in the NSFontCollectionDidChangeNotification userInfo method.

    Declaration

    Swift

    let NSFontCollectionWasShown: NSString! let NSFontCollectionWasHidden: NSString! let NSFontCollectionWasRenamed: NSString!

    Objective-C

    NSString * const NSFontCollectionWasShown; NSString * const NSFontCollectionWasHidden; NSString * const NSFontCollectionWasRenamed;

    Constants

    • NSFontCollectionWasShown

      NSFontCollectionWasShown

      The font collection was shown.

      Available in OS X v10.7 and later.

    • NSFontCollectionWasHidden

      NSFontCollectionWasHidden

      The font collection was hidden.

      Available in OS X v10.7 and later.

    • NSFontCollectionWasRenamed

      NSFontCollectionWasRenamed

      The font collection was renamed.

      Available in OS X v10.7 and later.