iOS Developer Library

Developer

ApplicationServices Framework Reference 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 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.

    Import Statement

    import CoreText

    Availability

    Available in iOS 7.0 and later.

  • Registers fonts from the specified font URL with the Font Manager. Registered fonts are discoverable through font descriptor matching.

    Declaration

    Swift

    func CTFontManagerRegisterFontsForURL(_ fontURL: CFURL!, _ scope: CTFontManagerScope, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>) -> Bool

    Objective-C

    bool CTFontManagerRegisterFontsForURL ( CFURLRef fontURL, CTFontManagerScope scope, CFErrorRef *error );

    Parameters

    fontURL

    The font URL.

    scope

    Scope constant defining the availability and lifetime of the registration. See Font Registration Scope for values to pass for this parameter.

    error

    Pointer to a CFError object which, in case of failed registration, contains error information.

    Return Value

    Returns true if registration of the fonts was successful, otherwise false.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 and later.

  • Unregisters fonts from the specified font URL with the Font Manager. Unregistered fonts are no longer discoverable through font descriptor matching.

    Declaration

    Swift

    func CTFontManagerUnregisterFontsForURL(_ fontURL: CFURL!, _ scope: CTFontManagerScope, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>) -> Bool

    Objective-C

    bool CTFontManagerUnregisterFontsForURL ( CFURLRef fontURL, CTFontManagerScope scope, CFErrorRef *error );

    Parameters

    fontURL

    The font URL.

    scope

    Scope constant defining the availability and lifetime of the registration. See Font Registration Scope for values to pass for this parameter.

    error

    Pointer to a CFError object which, in case of failed registration, contains error information.

    Return Value

    Returns true if unregistration of the fonts was successful, otherwise false.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 and later.

  • Registers fonts from the specified array of font URLs with the Font Manager. Registered fonts are discoverable through font descriptor matching.

    Declaration

    Swift

    func CTFontManagerRegisterFontsForURLs(_ fontURLs: CFArray!, _ scope: CTFontManagerScope, _ errors: UnsafeMutablePointer<Unmanaged<CFArray>?>) -> Bool

    Objective-C

    bool CTFontManagerRegisterFontsForURLs ( CFArrayRef fontURLs, CTFontManagerScope scope, CFArrayRef *errors );

    Parameters

    fontURLs

    Array of font URLs.

    scope

    Scope constant defining the availability and lifetime of the registration. See Font Registration Scope for values to pass for this parameter.

    errors

    Pointer to an array of CFError objects which, in case of failed registration, contain error information. Each error contains a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error and were not successfully registered. The array must be released by the caller. Can be NULL.

    Return Value

    Returns true if registration of all font URLs was successful, otherwise false.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 and later.

  • Unregisters fonts from the specified array of font URLs with the Font Manager. Unregistered fonts are no longer discoverable through font descriptor matching.

    Declaration

    Swift

    func CTFontManagerUnregisterFontsForURLs(_ fontURLs: CFArray!, _ scope: CTFontManagerScope, _ errors: UnsafeMutablePointer<Unmanaged<CFArray>?>) -> Bool

    Objective-C

    bool CTFontManagerUnregisterFontsForURLs ( CFArrayRef fontURLs, CTFontManagerScope scope, CFArrayRef *errors );

    Parameters

    fontURLs

    Array of font URLs.

    scope

    Scope constant defining the availability and lifetime of the registration. See Font Registration Scope for values to pass for this parameter.

    errors

    Pointer to an array of CFError objects which, in case of failed registration, contain error information. Each error contains a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error and were not successfully registered. The array must be released by the caller. Can be NULL.

    Return Value

    Returns true if unregistration of all font URLs was successful, otherwise false.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 and later.

  • Registers the specified graphics font with the font manager.

    Declaration

    Swift

    func CTFontManagerRegisterGraphicsFont(_ font: CGFont!, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>) -> Bool

    Objective-C

    bool CTFontManagerRegisterGraphicsFont ( CGFontRef font, CFErrorRef *error );

    Parameters

    font

    The graphics font to be registered.

    error

    Returns by indirection an error object in the case of failed registration.

    Return Value

    true if registration of the font was successful, otherwise false.

    Discussion

    Registered fonts are discoverable through font descriptor matching. Any attempt to register a font that is either already registered or contains the same Postscript of an already registered font will fail. This behavior is useful for fonts that may be embedded in documents or constructed in memory. A graphics font is obtained by calling CGFontCreateWithDataProvider. Fonts that are backed by files should be registered using CTFontManagerRegisterFontsForURL.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 and later.

  • Unregisters the specified graphics font with the font manager.

    Declaration

    Swift

    func CTFontManagerUnregisterGraphicsFont(_ font: CGFont!, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>) -> Bool

    Objective-C

    bool CTFontManagerUnregisterGraphicsFont ( CGFontRef font, CFErrorRef *error );

    Parameters

    font

    The graphics font to be unregistered.

    error

    Returns by indirection an error object in the case of failed unregistration.

    Return Value

    true if unregistration of the font was successful, otherwise false.

    Discussion

    Unregistered fonts are no longer discoverable through font descriptor matching. Fonts that are backed by files should be unregistered using CTFontManagerUnregisterFontsForURL.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 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.

    Import Statement

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 iOS 4.1 and later.

    • Process

      kCTFontManagerScopeProcess

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

      Available in iOS 4.1 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 iOS 4.1 and later.

    • Session

      kCTFontManagerScopeSession

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

      Available in iOS 4.1 and later.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 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 iOS 4.1 and later.

    • Disabled

      kCTFontManagerAutoActivationDisabled

      Disables auto-activation.

      Available in iOS 4.1 and later.

    • Enabled

      kCTFontManagerAutoActivationEnabled

      Enables auto-activation.

      Available in iOS 4.1 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 iOS 4.1 and later.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 and later.

  • 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 iOS 7.0 and later.

    Import Statement

  • 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 iOS 3.2 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 iOS 3.2 and later.

    Import Statement

  • 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 iOS 4.1 and later.

    • InsufficientPermissions

      kCTFontManagerErrorInsufficientPermissions

      Cannot access the file due to insufficient permissions.

      Available in iOS 4.1 and later.

    • UnrecognizedFormat

      kCTFontManagerErrorUnrecognizedFormat

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

      Available in iOS 4.1 and later.

    • InvalidFontData

      kCTFontManagerErrorInvalidFontData

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

      Available in iOS 4.1 and later.

    • AlreadyRegistered

      kCTFontManagerErrorAlreadyRegistered

      The file has already been registered in the specified scope.

      Available in iOS 4.1 and later.

    Import Statement

  • 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 iOS 4.1 and later.

    • InUse

      kCTFontManagerErrorInUse

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

      Available in iOS 4.1 and later.

    • SystemRequired

      kCTFontManagerErrorSystemRequired

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

      Available in iOS 4.1 and later.

    Import Statement

    import CoreText

    Availability

    Available in iOS 4.1 and later.