Mac Developer Library

Developer

Core Text Reference Collection Core Text Font Manager Reference

Options
Deployment Target:

On This Page
Language:

Core Text Font Manager Reference

This reference document describes the functions and constants used to manage fonts in Core Text.

Functions

  • Returns an array of unique PostScript font names for the fonts.

    Declaration

    Swift

    func CTFontManagerCopyAvailablePostScriptNames() -> CFArray

    Objective-C

    CFArrayRef CTFontManagerCopyAvailablePostScriptNames ( void );

    Return Value

    This function returns a retained reference to a CFArray of CFStringRef objects representing the PostScript names of the available fonts, or NULL on error. The caller is responsible for releasing the array.

    Availability

    Available in OS X v10.6 and later.

  • Returns an array of visible font family names sorted for user interface display.

    Declaration

    Swift

    func CTFontManagerCopyAvailableFontFamilyNames() -> CFArray

    Objective-C

    CFArrayRef CTFontManagerCopyAvailableFontFamilyNames ( void );

    Return Value

    This function returns a retained reference to a CFArray of CFStringRef objects representing the visible font family names of the available fonts, or NULL on error. The caller is responsible for releasing the array.

    Availability

    Available in OS X v10.6 and later.

  • Returns an array of font URLs.

    Declaration

    Swift

    func CTFontManagerCopyAvailableFontURLs() -> CFArray

    Objective-C

    CFArrayRef CTFontManagerCopyAvailableFontURLs ( void );

    Return Value

    This function returns a retained reference to a CFArray of CFStringRef objects representing the URLs of the available fonts, or NULL on error. The caller is responsible for releasing the array.

    Availability

    Available in OS X v10.6 and later.

  • A comparator function to compare font family names and sort them according to Apple guidelines.

    Declaration

    Swift

    func CTFontManagerCompareFontFamilyNames(_ family1: UnsafePointer<Void>, _ family2: UnsafePointer<Void>, _ context: UnsafeMutablePointer<Void>) -> CFComparisonResult

    Objective-C

    CFComparisonResult CTFontManagerCompareFontFamilyNames ( const void *family1, const void *family2, void *context );

    Parameters

    family1

    The first localized font family name to compare, as a CFStringRef object.

    family2

    The second localized font family name to compare, as a CFStringRef object.

    context

    Unused. Can be NULL.

    Return Value

    A CFComparisonResult value indicating the sort order for the two family names. kCFComparisonResultGreatherThan if family1 is greater than family2, kCFComparisonResultLessThan if family1 is less than family2, and kCFComparisonResultEqualTo if they are equal.

    Discussion

    This CFComparatorFunction function compares font family names and sorts them in the Apple preferred order, accounting for foundry prefix. Family names with recognized prefixes are sorted after the unprefixed names in prefix order.

    Availability

    Available in OS X v10.6 and later.

  • Returns an array of font descriptors representing each of the fonts in the specified URL.

    Declaration

    Swift

    func CTFontManagerCreateFontDescriptorsFromURL(_ fileURL: CFURL) -> CFArray?

    Objective-C

    CFArrayRef CTFontManagerCreateFontDescriptorsFromURL ( CFURLRef fileURL );

    Parameters

    fileURL

    A file system URL referencing a valid font file.

    Return Value

    This function returns a retained reference to a CFArray of CTFontDescriptorRef objects, or NULL on error. The caller is responsible for releasing the array.

    Availability

    Available in OS X v10.6 and later.

  • Enables or disables the matching font descriptors for font descriptor matching.

    Declaration

    Swift

    func CTFontManagerEnableFontDescriptors(_ descriptors: CFArray, _ enable: Bool)

    Objective-C

    void CTFontManagerEnableFontDescriptors ( CFArrayRef descriptors, bool enable );

    Parameters

    descriptors

    Array of font descriptors.

    enable

    If true, the fonts matching the given descriptors are enabled for font descriptor matching; if false, they are not enabled.

    Availability

    Available in OS X v10.6 and later.

  • Determines whether the referenced font data (usually by file URL) is supported on the current platform.

    Declaration

    Objective-C

    bool CTFontManagerIsSupportedFont( CFURLRef fontURL );

    Parameters

    fontURL

    A URL referring to font data.

    Return Value

    Returns true if the URL refers to a valid font that can be used on the current platform; false otherwise.

  • Creates a reference to a run loop source used to convey font requests from the Font Manager.

    Declaration

    Swift

    func CTFontManagerCreateFontRequestRunLoopSource(_ sourceOrder: CFIndex, _ createMatchesCallback: (CFDictionary, pid_t) -> Unmanaged<CFArray>) -> CFRunLoopSource?

    Objective-C

    CFRunLoopSourceRef CTFontManagerCreateFontRequestRunLoopSource ( CFIndex sourceOrder, CFArrayRef _Nonnull (^createMatchesCallback)( CFDictionaryRef requestAttributes, pid_t requestingProcess) );

    Parameters

    sourceOrder

    The order of the created run loop source.

    createMatchesCallback

    A block to handle the font request.

    Return Value

    A reference to a CFRunLoopSource object that should be added to the run loop. To stop receiving requests, invalidate this run loop source. Returns NULL on error, in the case of a duplicate requestPortName, or invalid context structure.

    Availability

    Available in OS X v10.6 and later.

Constants

  • These constants define the scope for font registration.

    Declaration

    Swift

    enum CTFontManagerScope : UInt32 { case None case Process case User case Session }

    Objective-C

    enum { kCTFontManagerScopeNone = 0, kCTFontManagerScopeProcess = 1, kCTFontManagerScopeUser = 2, kCTFontManagerScopeSession = 3 }; typedef uint32_t CTFontManagerScope;

    Constants

    • None

      kCTFontManagerScopeNone

      No scope is defined.

      Available in OS X v10.6 and later.

    • Process

      kCTFontManagerScopeProcess

      The font is available to the current process for the duration of the process unless directly unregistered.

      Available in OS X v10.6 and later.

    • User

      kCTFontManagerScopeUser

      The font is available to all processes for the current user session and will be available in subsequent sessions unless unregistered.

      Available in OS X v10.6 and later.

    • Session

      kCTFontManagerScopeSession

      The font is available to the current user session but will not be available in subsequent sessions.

      Available in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import CoreText;

    Swift

    import CoreText

    Availability

    Available in OS X v10.6 and later.

  • Sets the auto-activation for the specified bundle identifier.

    Declaration

    Swift

    enum CTFontManagerAutoActivationSetting : UInt32 { case Default case Disabled case Enabled case PromptUser }

    Objective-C

    enum { kCTFontManagerAutoActivationDefault = 0, kCTFontManagerAutoActivationDisabled = 1, kCTFontManagerAutoActivationEnabled = 2, kCTFontManagerAutoActivationPromptUser = 3 }; typedef uint32_t CTFontManagerAutoActivationSetting;

    Constants

    • Default

      kCTFontManagerAutoActivationDefault

      Default auto-activation setting. When specified, the application uses the global setting.

      Available in OS X v10.6 and later.

    • Disabled

      kCTFontManagerAutoActivationDisabled

      Disables auto-activation.

      Available in OS X v10.6 and later.

    • Enabled

      kCTFontManagerAutoActivationEnabled

      Enables auto-activation.

      Available in OS X v10.6 and later.

    • PromptUser

      kCTFontManagerAutoActivationPromptUser

      Requires user input for auto-activation. A dialog is presented to the user to confirm auto-activation of the font.

      Available in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import CoreText;

    Swift

    import CoreText

    Availability

    Available in OS X v10.6 and later.

  • This constant is the font manager bundle identifier.

    Declaration

    Swift

    let kCTFontManagerBundleIdentifier: CFString

    Objective-C

    const CFStringRef kCTFontManagerBundleIdentifier;

    Constants

  • Notification name for font registry changes.

    Declaration

    Swift

    let kCTFontManagerRegisteredFontsChangedNotification: CFString

    Objective-C

    const CFStringRef kCTFontManagerRegisteredFontsChangedNotification

    Constants

    • kCTFontManagerRegisteredFontsChangedNotification

      kCTFontManagerRegisteredFontsChangedNotification

      This is the string to use as the notification name when subscribing to Core Text Font Manager notifications. This notification is posted when fonts are added to the font registry. The client is responsible for registered with the distributed notification center to receive notifications for changes to the session or user scopes, and with a local notification center for changes to the process scope.

      Available in OS X v10.6 and later.

  • CFError domain and user info key for Font Manager errors.

    Declaration

    Swift

    let kCTFontManagerErrorDomain: CFString let kCTFontManagerErrorFontURLsKey: CFString

    Objective-C

    const CFStringRef kCTFontManagerErrorDomain; const CFStringRef kCTFontManagerErrorFontURLsKey;

    Constants

    • kCTFontManagerErrorDomain

      kCTFontManagerErrorDomain

      CFError objects with this domain have error codes corresponding to one of the CTFontManagerError errors listed in Font Registration Errors and Font Unregistration Errors.

      Available in OS X v10.6 and later.

    • kCTFontManagerErrorFontURLsKey

      kCTFontManagerErrorFontURLsKey

      User info key to be used with CFError references returned from registration functions. The value associated with this key in the user info dictionary of a CFError object is a CFArray of font URLs that failed with the given error.

      Available in OS X v10.6 and later.

  • Errors that would prevent registration of fonts for a specified font file URL.

    Declaration

    Swift

    enum CTFontManagerError : CFIndex { case FileNotFound case InsufficientPermissions case UnrecognizedFormat case InvalidFontData case AlreadyRegistered case NotRegistered case InUse case SystemRequired }

    Objective-C

    enum { kCTFontManagerErrorFileNotFound = 101, kCTFontManagerErrorInsufficientPermissions = 102, kCTFontManagerErrorUnrecognizedFormat = 103, kCTFontManagerErrorInvalidFontData = 104, kCTFontManagerErrorAlreadyRegistered = 105, };

    Constants

    • FileNotFound

      kCTFontManagerErrorFileNotFound

      The file does not exist at the specified URL.

      Available in OS X v10.6 and later.

    • InsufficientPermissions

      kCTFontManagerErrorInsufficientPermissions

      Cannot access the file due to insufficient permissions.

      Available in OS X v10.6 and later.

    • UnrecognizedFormat

      kCTFontManagerErrorUnrecognizedFormat

      The file is not a recognized or supported font file format.

      Available in OS X v10.6 and later.

    • InvalidFontData

      kCTFontManagerErrorInvalidFontData

      The file contains invalid font data that could cause system problems.

      Available in OS X v10.6 and later.

    • AlreadyRegistered

      kCTFontManagerErrorAlreadyRegistered

      The file has already been registered in the specified scope.

      Available in OS X v10.6 and later.

  • Errors that would prevent unregistration of fonts for a specified font file URL.

    Declaration

    Swift

    enum CTFontManagerError : CFIndex { case FileNotFound case InsufficientPermissions case UnrecognizedFormat case InvalidFontData case AlreadyRegistered case NotRegistered case InUse case SystemRequired }

    Objective-C

    enum { kCTFontManagerErrorNotRegistered = 201, kCTFontManagerErrorInUse = 202, kCTFontManagerErrorSystemRequired = 202, }; typedef CFIndex CTFontManagerError;

    Constants

    • NotRegistered

      kCTFontManagerErrorNotRegistered

      The file is not registered in the specified scope.

      Available in OS X v10.6 and later.

    • InUse

      kCTFontManagerErrorInUse

      The font file is actively in use and cannot be unregistered.

      Available in OS X v10.6 and later.

    • SystemRequired

      kCTFontManagerErrorSystemRequired

      The file is required by the system and cannot be unregistered.

      Available in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import CoreText;

    Swift

    import CoreText

    Availability

    Available in OS X v10.6 and later.