objc2_core_text/generated/
CTFontManager.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "objc2")]
6use objc2::__framework_prelude::*;
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-graphics")]
9use objc2_core_graphics::*;
10
11use crate::*;
12
13/// Returns an array of unique PostScript font names.
14///
15///
16/// Returns: An array of CFStrings.
17#[inline]
18pub unsafe extern "C-unwind" fn CTFontManagerCopyAvailablePostScriptNames() -> CFRetained<CFArray> {
19    extern "C-unwind" {
20        fn CTFontManagerCopyAvailablePostScriptNames() -> Option<NonNull<CFArray>>;
21    }
22    let ret = unsafe { CTFontManagerCopyAvailablePostScriptNames() };
23    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
24    unsafe { CFRetained::from_raw(ret) }
25}
26
27/// Returns an array of visible font family names sorted for UI display.
28///
29///
30/// Returns: An array of CFStrings.
31#[inline]
32pub unsafe extern "C-unwind" fn CTFontManagerCopyAvailableFontFamilyNames() -> CFRetained<CFArray> {
33    extern "C-unwind" {
34        fn CTFontManagerCopyAvailableFontFamilyNames() -> Option<NonNull<CFArray>>;
35    }
36    let ret = unsafe { CTFontManagerCopyAvailableFontFamilyNames() };
37    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
38    unsafe { CFRetained::from_raw(ret) }
39}
40
41/// Returns an array of font URLs.
42///
43///
44/// Returns: An array of CFURLs.
45#[inline]
46pub unsafe extern "C-unwind" fn CTFontManagerCopyAvailableFontURLs() -> CFRetained<CFArray> {
47    extern "C-unwind" {
48        fn CTFontManagerCopyAvailableFontURLs() -> Option<NonNull<CFArray>>;
49    }
50    let ret = unsafe { CTFontManagerCopyAvailableFontURLs() };
51    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
52    unsafe { CFRetained::from_raw(ret) }
53}
54
55extern "C-unwind" {
56    /// A CFComparatorFunction to compare font family names and sort them according to Apple guidelines.
57    ///
58    /// This function compares font family names and sorts them in the preferred order for display in user interfaces.
59    ///
60    /// Parameter `family1`: The first localized font family name, as CFStringRef.
61    ///
62    /// Parameter `family2`: The second localized font family name, as CFStringRef.
63    ///
64    /// Parameter `context`: Unused. Can be NULL.
65    ///
66    /// Returns: A CFComparisonResult value indicating the sort order for the two family names. kCFComparisonResultGreaterThan if family1 is greater than family2, kCFComparisonResultLessThan if family1 is less than family2, and kCFComparisonResultEqualTo if they are equal.
67    pub fn CTFontManagerCompareFontFamilyNames(
68        family1: NonNull<c_void>,
69        family2: NonNull<c_void>,
70        context: *mut c_void,
71    ) -> CFComparisonResult;
72}
73
74/// Returns an array of font descriptors representing each of the fonts in the specified URL.
75/// Note: these font descriptors are not available through font descriptor matching.
76///
77///
78/// Parameter `fileURL`: A file system URL referencing a valid font file.
79///
80///
81/// Returns: An array of CTFontDescriptors or NULL if there are no valid fonts.
82#[inline]
83pub unsafe extern "C-unwind" fn CTFontManagerCreateFontDescriptorsFromURL(
84    file_url: &CFURL,
85) -> Option<CFRetained<CFArray>> {
86    extern "C-unwind" {
87        fn CTFontManagerCreateFontDescriptorsFromURL(file_url: &CFURL) -> Option<NonNull<CFArray>>;
88    }
89    let ret = unsafe { CTFontManagerCreateFontDescriptorsFromURL(file_url) };
90    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
91}
92
93/// Returns a font descriptor representing the font in the supplied data.
94/// Note: the font descriptor is not available through font descriptor matching.
95///
96///
97/// If the data contains a font collection (TTC or OTC), only the first font in the collection will be returned.
98///
99///
100/// Parameter `data`: A CFData containing font data.
101///
102///
103/// Returns: A font descriptor created from the data or NULL if it is not a valid font.
104#[cfg(feature = "CTFontDescriptor")]
105#[inline]
106pub unsafe extern "C-unwind" fn CTFontManagerCreateFontDescriptorFromData(
107    data: &CFData,
108) -> Option<CFRetained<CTFontDescriptor>> {
109    extern "C-unwind" {
110        fn CTFontManagerCreateFontDescriptorFromData(
111            data: &CFData,
112        ) -> Option<NonNull<CTFontDescriptor>>;
113    }
114    let ret = unsafe { CTFontManagerCreateFontDescriptorFromData(data) };
115    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
116}
117
118/// Returns an array of font descriptors for the fonts in the supplied data.
119/// Note: the font descriptors are not available through font descriptor matching.
120///
121///
122/// Parameter `data`: A CFData containing font data.
123///
124///
125/// Returns: An array of font descriptors. This can be an empty array in the event of invalid or unsupported font data.
126#[inline]
127pub unsafe extern "C-unwind" fn CTFontManagerCreateFontDescriptorsFromData(
128    data: &CFData,
129) -> CFRetained<CFArray> {
130    extern "C-unwind" {
131        fn CTFontManagerCreateFontDescriptorsFromData(data: &CFData) -> Option<NonNull<CFArray>>;
132    }
133    let ret = unsafe { CTFontManagerCreateFontDescriptorsFromData(data) };
134    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
135    unsafe { CFRetained::from_raw(ret) }
136}
137
138/// Scope for font registration. A uses session refers to a login session in macOS, and the current booted session in iOS.
139///
140/// The font is not registered and does not participate in font descriptor matching. This isn't a valid scope to specify while registering fonts.
141///
142/// The font is available to the current process for the duration of the process unless directly unregistered.
143///
144/// The font is available to all processes for the current user session and will be available in subsequent sessions unless unregistered.
145///
146/// The font is available to the current user session, and will not be available in subsequent sessions.
147/// Session scope is only available in macOS.
148///
149/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctfontmanagerscope?language=objc)
150// NS_ENUM
151#[repr(transparent)]
152#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
153pub struct CTFontManagerScope(pub u32);
154impl CTFontManagerScope {
155    #[doc(alias = "kCTFontManagerScopeNone")]
156    pub const None: Self = Self(0);
157    #[doc(alias = "kCTFontManagerScopeProcess")]
158    pub const Process: Self = Self(1);
159    #[doc(alias = "kCTFontManagerScopePersistent")]
160    pub const Persistent: Self = Self(2);
161    #[doc(alias = "kCTFontManagerScopeSession")]
162    pub const Session: Self = Self(3);
163    #[doc(alias = "kCTFontManagerScopeUser")]
164    pub const User: Self = Self(2);
165}
166
167#[cfg(feature = "objc2")]
168unsafe impl Encode for CTFontManagerScope {
169    const ENCODING: Encoding = u32::ENCODING;
170}
171
172#[cfg(feature = "objc2")]
173unsafe impl RefEncode for CTFontManagerScope {
174    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
175}
176
177extern "C" {
178    /// kCTFontRegistrationUserInfoAttribute
179    ///
180    /// Optional user defined information that can be attached to an entry in the Font Manager registration catalog.
181    ///
182    /// This is the key for accessing font registration user information for the font descriptor. This information can be used in descriptor matching to disambiguate between two fonts with equivalent Postscript names. The value associated with this key is a CFStringRef.
183    ///
184    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontregistrationuserinfoattribute?language=objc)
185    pub static kCTFontRegistrationUserInfoAttribute: &'static CFString;
186}
187
188extern "C-unwind" {
189    /// Registers fonts from the specified font URL with the font manager. Registered fonts participate in font descriptor matching.
190    ///
191    ///
192    /// Parameter `fontURL`: A file URL for the font or collection (TTC or OTC) to be registered. Once fonts have been registered from a file, it shouldn't be moved or renamed.
193    ///
194    ///
195    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
196    ///
197    ///
198    /// Parameter `error`: Pointer to receive CFError in the case of failed registration.
199    ///
200    ///
201    /// Returns: Returns true if registration of the fonts was successful.
202    pub fn CTFontManagerRegisterFontsForURL(
203        font_url: &CFURL,
204        scope: CTFontManagerScope,
205        error: *mut *mut CFError,
206    ) -> bool;
207}
208
209extern "C-unwind" {
210    /// Unregisters fonts from the specified font URL with the font manager. Unregistered fonts do not participate in font descriptor matching.
211    /// iOS note: only fonts registered with CTFontManagerRegisterFontsForURL or CTFontManagerRegisterFontsForURLs can be unregistered with this API.
212    ///
213    ///
214    /// Parameter `fontURL`: Font URL.
215    ///
216    ///
217    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. Should match the scope the fonts are registered in. See scope constants for more details.
218    ///
219    ///
220    /// Parameter `error`: Pointer to receive CFError in the case of failed unregistration.
221    ///
222    ///
223    /// Returns: Returns true if unregistration of the fonts was successful.
224    pub fn CTFontManagerUnregisterFontsForURL(
225        font_url: &CFURL,
226        scope: CTFontManagerScope,
227        error: *mut *mut CFError,
228    ) -> bool;
229}
230
231extern "C-unwind" {
232    /// Registers the specified graphics font with the font manager. Registered fonts participate in font descriptor matching.
233    ///
234    ///
235    /// Attempts to register a font that is either already registered or contains the same PostScript name of an already registered font will fail.
236    /// This functionality is intended for fonts that may be embedded in documents or present/constructed in memory. A graphics font is obtained
237    /// by calling CGFontCreateWithDataProvider. Fonts that are backed by files should be registered using CTFontManagerRegisterFontsForURL.
238    ///
239    ///
240    /// Parameter `font`: Graphics font to be registered.
241    ///
242    ///
243    /// Parameter `error`: Pointer to receive CFError in the case of failed registration.
244    ///
245    ///
246    /// Returns: Returns true if registration of the fonts was successful.
247    #[cfg(feature = "objc2-core-graphics")]
248    #[deprecated = "Use CTFontManagerCreateFontDescriptorsFromData or CTFontManagerRegisterFontsForURL"]
249    pub fn CTFontManagerRegisterGraphicsFont(font: &CGFont, error: *mut *mut CFError) -> bool;
250}
251
252extern "C-unwind" {
253    /// Unregisters the specified graphics font with the font manager. Unregistered fonts do not participate in font descriptor matching.
254    ///
255    ///
256    /// Parameter `font`: Graphics font to be unregistered.
257    ///
258    ///
259    /// Parameter `error`: Pointer to receive CFError in the case of failed unregistration.
260    ///
261    ///
262    /// Returns: Returns true if unregistration of the font was successful.
263    #[cfg(feature = "objc2-core-graphics")]
264    #[deprecated = "Use the API corresponding to the one used to register the font"]
265    pub fn CTFontManagerUnregisterGraphicsFont(font: &CGFont, error: *mut *mut CFError) -> bool;
266}
267
268extern "C-unwind" {
269    /// Registers fonts from the specified font URLs with the font manager. Registered fonts are discoverable through font descriptor matching.
270    ///
271    ///
272    /// Parameter `fontURLs`: An array of file URLs for the fonts or collections (TTC or OTC) to be registered. Once fonts have been registered from a file, it shouldn't be moved or renamed.
273    ///
274    ///
275    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
276    ///
277    ///
278    /// Parameter `errors`: Pointer to CFArrayRef to receive array of CFError references. Each error will contain a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error, and were not successfully registered. Must be released by caller. Can be NULL.
279    ///
280    ///
281    /// Returns: Returns true if registration of all font URLs was successful. Otherwise false.
282    #[deprecated]
283    pub fn CTFontManagerRegisterFontsForURLs(
284        font_ur_ls: &CFArray,
285        scope: CTFontManagerScope,
286        errors: *mut *const CFArray,
287    ) -> bool;
288}
289
290extern "C-unwind" {
291    /// Unregisters fonts from the specified font URLs with the font manager. Unregistered fonts do not participate in font descriptor matching.
292    /// iOS note: only fonts registered with CTFontManagerRegisterFontsForURL or CTFontManagerRegisterFontsForURLs can be unregistered with this API.
293    ///
294    ///
295    /// Parameter `fontURLs`: Array of font URLs.
296    ///
297    ///
298    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. Should match the scope the fonts are registered in. See scope constants for more details.
299    ///
300    ///
301    /// Parameter `errors`: Pointer to CFArrayRef to receive array of CFError references. Each error will contain a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error, and were not successfully unregistered. Must be released by caller. Can be NULL.
302    ///
303    ///
304    /// Returns: Returns true if unregistration of all font URLs was successful. Otherwise false.
305    #[deprecated]
306    pub fn CTFontManagerUnregisterFontsForURLs(
307        font_ur_ls: &CFArray,
308        scope: CTFontManagerScope,
309        errors: *mut *const CFArray,
310    ) -> bool;
311}
312
313extern "C-unwind" {
314    /// Registers fonts from the specified font URLs with the font manager. Registered fonts are discoverable through font descriptor matching in the calling process
315    ///
316    ///
317    /// In iOS, fonts registered with the persistent scope are not automatically available to other processes. Other process may call CTFontManagerRequestFonts to get access to these fonts.
318    ///
319    ///
320    /// Parameter `fontURLs`: A file URL for the fonts or collections (TTC or OTC) to be registered. Once fonts have been registered from a file, it shouldn't be moved or renamed.
321    ///
322    ///
323    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
324    ///
325    ///
326    /// Parameter `enabled`: Boolean value indicating whether the font derived from the URL should be enabled for font descriptor matching and/or discoverable via CTFontManagerRequestFonts.
327    ///
328    ///
329    /// Parameter `registrationHandler`: Block called as errors are discovered or upon completion. The errors parameter contains an array of CFError references. An empty array indicates no errors. Each error reference will contain a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error, and were not successfully registered. Note, the handler may be called multiple times during the registration process. The done parameter will be set to true when the registration process has completed. The handler should return false if the operation is to be stopped. This may be desirable after receiving an error.
330    #[cfg(feature = "block2")]
331    pub fn CTFontManagerRegisterFontURLs(
332        font_ur_ls: &CFArray,
333        scope: CTFontManagerScope,
334        enabled: bool,
335        registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
336    );
337}
338
339extern "C-unwind" {
340    /// Unregisters fonts from the specified font URLs with the font manager. Unregistered fonts do not participate in font descriptor matching.
341    /// iOS note: only fonts registered with CTFontManagerRegisterFontsForURL or CTFontManagerRegisterFontsForURLs can be unregistered with this API.
342    ///
343    ///
344    /// Parameter `fontURLs`: Array of font URLs.
345    ///
346    ///
347    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. Should match the scope the fonts are registered in. See scope constants for more details.
348    ///
349    ///
350    /// Parameter `registrationHandler`: Block called as errors are discovered or upon completion. The errors parameter will be an empty array if all files are unregistered. Otherwise, it will contain an array of CFError references. Each error reference will contain a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error, and were not successfully unregistered. Note, the handler may be called multiple times during the unregistration process. The done parameter will be set to true when the unregistration process has completed. The handler should return false if the operation is to be stopped. This may be desirable after receiving an error.
351    #[cfg(feature = "block2")]
352    pub fn CTFontManagerUnregisterFontURLs(
353        font_ur_ls: &CFArray,
354        scope: CTFontManagerScope,
355        registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
356    );
357}
358
359extern "C-unwind" {
360    /// Registers font descriptors with the font manager. Registered fonts are discoverable through font descriptor matching in the calling process.
361    ///
362    ///
363    /// Fonts descriptors registered in disabled state are not immediately available for descriptor matching but the font manager will know the descriptors could be made available if necessary. These decriptors can be enabled by making this called again with the enabled parameter set to true. This operation may fail if there is another font registered and enabled with the same Postscript name. In iOS, fonts registered with the persistent scope are not automatically available to other processes. Other process may call CTFontManagerRequestFonts to get access to these fonts.
364    ///
365    ///
366    /// Parameter `fontDescriptors`: Array of font descriptors to register. Font descriptor keys used for registration are: kCTFontURLAttribute, kCTFontNameAttribute, kCTFontFamilyNameAttribute, or kCTFontRegistrationUserInfoAttribute.
367    ///
368    ///
369    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
370    ///
371    ///
372    /// Parameter `enabled`: Boolean value indicating whether the font descriptors should be enabled for font descriptor matching and/or discoverable via CTFontManagerRequestFonts.
373    ///
374    ///
375    /// Parameter `registrationHandler`: Block called as errors are discovered or upon completion. The errors parameter contains an array of CFError references. An empty array indicates no errors. Each error reference will contain a CFArray of font descriptors corresponding to kCTFontManagerErrorFontDescriptorsKey. These represent the font descriptors that caused the error, and were not successfully registered. Note, the handler may be called multiple times during the registration process. The done parameter will be set to true when the registration process has completed. The handler should return false if the operation is to be stopped. This may be desirable after receiving an error.
376    #[cfg(feature = "block2")]
377    pub fn CTFontManagerRegisterFontDescriptors(
378        font_descriptors: &CFArray,
379        scope: CTFontManagerScope,
380        enabled: bool,
381        registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
382    );
383}
384
385extern "C-unwind" {
386    /// Unregisters font descriptors with the font manager. Unregistered fonts do not participate in font descriptor matching.
387    ///
388    ///
389    /// Parameter `fontDescriptors`: Array of font descriptors to unregister.
390    ///
391    ///
392    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
393    ///
394    ///
395    /// Parameter `registrationHandler`: Block called as errors are discovered or upon completion. The errors parameter will be an empty array if all font descriptors are unregistered. Otherwise, it will contain an array of CFError references. Each error reference will contain a CFArray of font descriptors corresponding to kCTFontManagerErrorFontDescriptorsKey. These represent the font descriptors that caused the error, and were not successfully unregistered. Note, the handler may be called multiple times during the unregistration process. The done parameter will be set to true when the unregistration process has completed. The handler should return false if the operation is to be stopped. This may be desirable after receiving an error.
396    #[cfg(feature = "block2")]
397    pub fn CTFontManagerUnregisterFontDescriptors(
398        font_descriptors: &CFArray,
399        scope: CTFontManagerScope,
400        registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
401    );
402}
403
404extern "C-unwind" {
405    /// Registers named font assets in the specified bundle with the font manager. Registered fonts are discoverable through font descriptor matching in the calling process.
406    ///
407    ///
408    /// Font assets are extracted from the asset catalog and registered. This call must be made after the completion handler of either NSBundleResourceRequest beginAccessingResourcesWithCompletionHandler: or conditionallyBeginAccessingResourcesWithCompletionHandler: is called successfully.
409    /// Name the assets using Postscript names for individual faces, or family names for variable/collection fonts. The same names can be used to unregister the fonts with CTFontManagerUnregisterFontDescriptors. In iOS, fonts registered with the persistent scope are not automatically available to other processes. Other process may call CTFontManagerRequestFonts to get access to these fonts.
410    ///
411    ///
412    /// Parameter `fontAssetNames`: Array of font name assets in asset catalog.
413    ///
414    ///
415    /// Parameter `bundle`: Bundle containing asset catalog. A null value resolves to the main bundle.
416    ///
417    ///
418    /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. kCTFontManagerScopePersistent is the only supported scope for iOS.
419    ///
420    ///
421    /// Parameter `enabled`: Boolean value indicating whether the font assets should be enabled for font descriptor matching and/or discoverable via CTFontManagerRequestFonts.
422    ///
423    ///
424    /// Parameter `registrationHandler`: Block called as errors are discovered, or upon completion. The errors parameter contains an array of CFError references. An empty array indicates no errors. Each error reference will contain a CFArray of font asset names corresponding to kCTFontManagerErrorFontAssetNameKey. These represent the font asset names that were not successfully registered. Note, the handler may be called multiple times during the registration process. The done parameter will be set to true when the registration process has completed. The handler should return false if the operation is to be stopped. This may be desirable after receiving an error.
425    #[cfg(feature = "block2")]
426    pub fn CTFontManagerRegisterFontsWithAssetNames(
427        font_asset_names: &CFArray,
428        bundle: Option<&CFBundle>,
429        scope: CTFontManagerScope,
430        enabled: bool,
431        registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
432    );
433}
434
435extern "C-unwind" {
436    /// Enables or disables the matching font descriptors for font descriptor matching.
437    ///
438    ///
439    /// Parameter `descriptors`: Array of font descriptors.
440    ///
441    ///
442    /// Parameter `enable`: Boolean value indicating whether the fonts matching descriptors should be enabled for font descriptor matching.
443    pub fn CTFontManagerEnableFontDescriptors(descriptors: &CFArray, enable: bool);
444}
445
446extern "C-unwind" {
447    /// Returns the registration scope of the specified URL.
448    ///
449    ///
450    /// Parameter `fontURL`: Font URL.
451    ///
452    ///
453    /// Returns: Returns the registration scope of the specified URL, will return kCTFontManagerScopeNone if not currently registered.
454    pub fn CTFontManagerGetScopeForURL(font_url: &CFURL) -> CTFontManagerScope;
455}
456
457/// Returns the font descriptors that were registered with the font manager.
458///
459///
460/// In the case the persistent scope is specified, only macOS can return fonts registered by any process. Other platforms can only return font descriptors registered by the application's process.
461///
462///
463/// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
464///
465///
466/// Parameter `enabled`: Boolean value indicating if the caller is interested in registered font descriptors that are enabled or disabled.
467///
468///
469/// Returns: Array of of font descriptors registered by the application. Array may be empty if nothing is registered.
470#[inline]
471pub unsafe extern "C-unwind" fn CTFontManagerCopyRegisteredFontDescriptors(
472    scope: CTFontManagerScope,
473    enabled: bool,
474) -> CFRetained<CFArray> {
475    extern "C-unwind" {
476        fn CTFontManagerCopyRegisteredFontDescriptors(
477            scope: CTFontManagerScope,
478            enabled: bool,
479        ) -> Option<NonNull<CFArray>>;
480    }
481    let ret = unsafe { CTFontManagerCopyRegisteredFontDescriptors(scope, enabled) };
482    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
483    unsafe { CFRetained::from_raw(ret) }
484}
485
486extern "C-unwind" {
487    /// Resolves font descriptors specified on input. On iOS only, if the font descriptors cannot be found, the user is presented with a dialog indicating fonts that could not be resolved. The user may optionally be provided with a way to resolve the missing fonts if the font manager has a way to enable them.
488    ///
489    ///
490    /// On iOS, fonts registered by font provider applications in the persistent scope are not automatically available to other applications. Client applications must call this function to make the requested fonts available for font descriptor matching.
491    ///
492    ///
493    /// Parameter `fontDescriptors`: Array of font descriptors to make available to the process.  Keys used to describe the fonts may be a combination of: kCTFontNameAttribute, kCTFontFamilyNameAttribute, or kCTFontRegistrationUserInfoAttribute.
494    ///
495    ///
496    /// Parameter `completionHandler`: Block called after request operation completes. Block takes a single parameter containing an array of those descriptors that could not be resolved/found. The array can be empty if all descriptors were resolved.
497    #[cfg(feature = "block2")]
498    pub fn CTFontManagerRequestFonts(
499        font_descriptors: &CFArray,
500        completion_handler: &block2::DynBlock<dyn Fn(NonNull<CFArray>)>,
501    );
502}
503
504extern "C-unwind" {
505    /// Determines whether a file is in a supported font format.
506    ///
507    ///
508    /// This function does not validate any font data, so clients using it must still be prepared to handle failed registration or font descriptor creation.
509    ///
510    ///
511    /// Parameter `fontURL`: A file URL.
512    ///
513    ///
514    /// Returns: This function returns true if the file is in a supported font format.
515    pub fn CTFontManagerIsSupportedFont(font_url: &CFURL) -> bool;
516}
517
518/// Creates a CFRunLoopSourceRef that will be used to convey font requests from CTFontManager.
519///
520/// Parameter `sourceOrder`: The order of the created run loop source.
521///
522/// Parameter `createMatchesCallback`: A block to handle the font request.
523///
524/// Returns: A CFRunLoopSourceRef that should be added to the run loop. To stop receiving requests, invalidate this run loop source. Will return NULL on error, in the case of a duplicate requestPortName or invalid context structure.
525#[cfg(all(feature = "block2", feature = "libc"))]
526#[deprecated = "This functionality will be removed in a future release"]
527#[inline]
528pub unsafe extern "C-unwind" fn CTFontManagerCreateFontRequestRunLoopSource(
529    source_order: CFIndex,
530    create_matches_callback: &block2::DynBlock<
531        dyn Fn(NonNull<CFDictionary>, libc::pid_t) -> NonNull<CFArray>,
532    >,
533) -> Option<CFRetained<CFRunLoopSource>> {
534    extern "C-unwind" {
535        fn CTFontManagerCreateFontRequestRunLoopSource(
536            source_order: CFIndex,
537            create_matches_callback: &block2::DynBlock<
538                dyn Fn(NonNull<CFDictionary>, libc::pid_t) -> NonNull<CFArray>,
539            >,
540        ) -> Option<NonNull<CFRunLoopSource>>;
541    }
542    let ret = unsafe {
543        CTFontManagerCreateFontRequestRunLoopSource(source_order, create_matches_callback)
544    };
545    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
546}
547
548extern "C" {
549    /// CTFontManage bundle identifier
550    ///
551    /// The CTFontManager bundle identifier to be used with get or set global auto-activation settings.
552    ///
553    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontmanagerbundleidentifier?language=objc)
554    pub static kCTFontManagerBundleIdentifier: &'static CFString;
555}
556
557/// Auto-activation settings.
558///
559/// Default auto-activation setting. When specified, the application will use the global setting.
560///
561/// Disables auto-activation.
562///
563/// Enables auto-activation.
564///
565/// Requires user input for auto-activation. A dialog will be presented to the user to confirm auto
566/// activation of the font.
567///
568/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctfontmanagerautoactivationsetting?language=objc)
569// NS_ENUM
570#[repr(transparent)]
571#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
572pub struct CTFontManagerAutoActivationSetting(pub u32);
573impl CTFontManagerAutoActivationSetting {
574    #[doc(alias = "kCTFontManagerAutoActivationDefault")]
575    pub const Default: Self = Self(0);
576    #[doc(alias = "kCTFontManagerAutoActivationDisabled")]
577    pub const Disabled: Self = Self(1);
578    #[doc(alias = "kCTFontManagerAutoActivationEnabled")]
579    pub const Enabled: Self = Self(2);
580    #[doc(alias = "kCTFontManagerAutoActivationPromptUser")]
581    #[deprecated = "Deprecated"]
582    pub const PromptUser: Self = Self(3);
583}
584
585#[cfg(feature = "objc2")]
586unsafe impl Encode for CTFontManagerAutoActivationSetting {
587    const ENCODING: Encoding = u32::ENCODING;
588}
589
590#[cfg(feature = "objc2")]
591unsafe impl RefEncode for CTFontManagerAutoActivationSetting {
592    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
593}
594
595extern "C-unwind" {
596    /// Sets the auto-activation for the specified bundle identifier.
597    ///
598    /// Parameter `bundleIdentifier`: The bundle identifier. Used to specify a particular application bundle. If NULL,
599    /// the current application bundle will be used. If kCTFontManagerBundleIdentifier is specified,
600    /// will set the global auto-activation settings.
601    ///
602    /// Parameter `setting`: The new setting.
603    ///
604    /// Function will apply the setting to the appropriate preferences location.
605    pub fn CTFontManagerSetAutoActivationSetting(
606        bundle_identifier: Option<&CFString>,
607        setting: CTFontManagerAutoActivationSetting,
608    );
609}
610
611extern "C-unwind" {
612    /// Accessor for the auto-activation setting.
613    ///
614    /// Parameter `bundleIdentifier`: The bundle identifier. Used to specify a particular application bundle. If NULL,
615    /// the current application bundle will be used. If kCTFontManagerBundleIdentifier is specified,
616    /// will set the global auto-activation settings.
617    ///
618    /// Returns: Will return the auto-activation setting for specified bundle identifier.
619    pub fn CTFontManagerGetAutoActivationSetting(
620        bundle_identifier: Option<&CFString>,
621    ) -> CTFontManagerAutoActivationSetting;
622}
623
624extern "C" {
625    /// Notification name for font registry changes.
626    ///
627    /// This is the string to use as the notification name when subscribing
628    /// to CTFontManager notifications.  This notification will be posted when fonts are added or removed.
629    /// OS X clients should register as an observer of the notification with the distributed notification center
630    /// for changes in session or persistent scopes and with the local notification center for changes in process scope.
631    /// iOS clients should register as an observer of the notification with the local notification center for all changes.
632    ///
633    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontmanagerregisteredfontschangednotification?language=objc)
634    pub static kCTFontManagerRegisteredFontsChangedNotification: &'static CFString;
635}