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 ///
68 /// # Safety
69 ///
70 /// - `family1` must be a valid pointer.
71 /// - `family2` must be a valid pointer.
72 /// - `context` must be a valid pointer or null.
73 pub fn CTFontManagerCompareFontFamilyNames(
74 family1: NonNull<c_void>,
75 family2: NonNull<c_void>,
76 context: *mut c_void,
77 ) -> CFComparisonResult;
78}
79
80/// Returns an array of font descriptors representing each of the fonts in the specified URL.
81/// Note: these font descriptors are not available through font descriptor matching.
82///
83///
84/// Parameter `fileURL`: A file system URL referencing a valid font file.
85///
86///
87/// Returns: An array of CTFontDescriptors or NULL if there are no valid fonts.
88#[inline]
89pub unsafe extern "C-unwind" fn CTFontManagerCreateFontDescriptorsFromURL(
90 file_url: &CFURL,
91) -> Option<CFRetained<CFArray>> {
92 extern "C-unwind" {
93 fn CTFontManagerCreateFontDescriptorsFromURL(file_url: &CFURL) -> Option<NonNull<CFArray>>;
94 }
95 let ret = unsafe { CTFontManagerCreateFontDescriptorsFromURL(file_url) };
96 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
97}
98
99/// Returns a font descriptor representing the font in the supplied data.
100/// Note: the font descriptor is not available through font descriptor matching.
101///
102///
103/// If the data contains a font collection (TTC or OTC), only the first font in the collection will be returned.
104///
105///
106/// Parameter `data`: A CFData containing font data.
107///
108///
109/// Returns: A font descriptor created from the data or NULL if it is not a valid font.
110#[cfg(feature = "CTFontDescriptor")]
111#[inline]
112pub unsafe extern "C-unwind" fn CTFontManagerCreateFontDescriptorFromData(
113 data: &CFData,
114) -> Option<CFRetained<CTFontDescriptor>> {
115 extern "C-unwind" {
116 fn CTFontManagerCreateFontDescriptorFromData(
117 data: &CFData,
118 ) -> Option<NonNull<CTFontDescriptor>>;
119 }
120 let ret = unsafe { CTFontManagerCreateFontDescriptorFromData(data) };
121 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
122}
123
124/// Returns an array of font descriptors for the fonts in the supplied data.
125/// Note: the font descriptors are not available through font descriptor matching.
126///
127///
128/// Parameter `data`: A CFData containing font data.
129///
130///
131/// Returns: An array of font descriptors. This can be an empty array in the event of invalid or unsupported font data.
132#[inline]
133pub unsafe extern "C-unwind" fn CTFontManagerCreateFontDescriptorsFromData(
134 data: &CFData,
135) -> CFRetained<CFArray> {
136 extern "C-unwind" {
137 fn CTFontManagerCreateFontDescriptorsFromData(data: &CFData) -> Option<NonNull<CFArray>>;
138 }
139 let ret = unsafe { CTFontManagerCreateFontDescriptorsFromData(data) };
140 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
141 unsafe { CFRetained::from_raw(ret) }
142}
143
144/// Scope for font registration. A uses session refers to a login session in macOS, and the current booted session in iOS.
145///
146/// The font is not registered and does not participate in font descriptor matching. This isn't a valid scope to specify while registering fonts.
147///
148/// The font is available to the current process for the duration of the process unless directly unregistered.
149///
150/// The font is available to all processes for the current user session and will be available in subsequent sessions unless unregistered.
151///
152/// The font is available to the current user session, and will not be available in subsequent sessions.
153/// Session scope is only available in macOS.
154///
155/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctfontmanagerscope?language=objc)
156// NS_ENUM
157#[repr(transparent)]
158#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
159pub struct CTFontManagerScope(pub u32);
160impl CTFontManagerScope {
161 #[doc(alias = "kCTFontManagerScopeNone")]
162 pub const None: Self = Self(0);
163 #[doc(alias = "kCTFontManagerScopeProcess")]
164 pub const Process: Self = Self(1);
165 #[doc(alias = "kCTFontManagerScopePersistent")]
166 pub const Persistent: Self = Self(2);
167 #[doc(alias = "kCTFontManagerScopeSession")]
168 pub const Session: Self = Self(3);
169 #[doc(alias = "kCTFontManagerScopeUser")]
170 pub const User: Self = Self(2);
171}
172
173#[cfg(feature = "objc2")]
174unsafe impl Encode for CTFontManagerScope {
175 const ENCODING: Encoding = u32::ENCODING;
176}
177
178#[cfg(feature = "objc2")]
179unsafe impl RefEncode for CTFontManagerScope {
180 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
181}
182
183extern "C" {
184 /// kCTFontRegistrationUserInfoAttribute
185 ///
186 /// Optional user defined information that can be attached to an entry in the Font Manager registration catalog.
187 ///
188 /// 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.
189 ///
190 /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontregistrationuserinfoattribute?language=objc)
191 pub static kCTFontRegistrationUserInfoAttribute: &'static CFString;
192}
193
194extern "C-unwind" {
195 /// Registers fonts from the specified font URL with the font manager. Registered fonts participate in font descriptor matching.
196 ///
197 ///
198 /// 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.
199 ///
200 ///
201 /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
202 ///
203 ///
204 /// Parameter `error`: Pointer to receive CFError in the case of failed registration.
205 ///
206 ///
207 /// Returns: Returns true if registration of the fonts was successful.
208 ///
209 /// # Safety
210 ///
211 /// `error` must be a valid pointer or null.
212 pub fn CTFontManagerRegisterFontsForURL(
213 font_url: &CFURL,
214 scope: CTFontManagerScope,
215 error: *mut *mut CFError,
216 ) -> bool;
217}
218
219extern "C-unwind" {
220 /// Unregisters fonts from the specified font URL with the font manager. Unregistered fonts do not participate in font descriptor matching.
221 /// iOS note: only fonts registered with CTFontManagerRegisterFontsForURL or CTFontManagerRegisterFontsForURLs can be unregistered with this API.
222 ///
223 ///
224 /// Parameter `fontURL`: Font URL.
225 ///
226 ///
227 /// 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.
228 ///
229 ///
230 /// Parameter `error`: Pointer to receive CFError in the case of failed unregistration.
231 ///
232 ///
233 /// Returns: Returns true if unregistration of the fonts was successful.
234 ///
235 /// # Safety
236 ///
237 /// `error` must be a valid pointer or null.
238 pub fn CTFontManagerUnregisterFontsForURL(
239 font_url: &CFURL,
240 scope: CTFontManagerScope,
241 error: *mut *mut CFError,
242 ) -> bool;
243}
244
245extern "C-unwind" {
246 /// Registers the specified graphics font with the font manager. Registered fonts participate in font descriptor matching.
247 ///
248 ///
249 /// Attempts to register a font that is either already registered or contains the same PostScript name of an already registered font will fail.
250 /// This functionality is intended for fonts that may be embedded in documents or present/constructed in memory. A graphics font is obtained
251 /// by calling CGFontCreateWithDataProvider. Fonts that are backed by files should be registered using CTFontManagerRegisterFontsForURL.
252 ///
253 ///
254 /// Parameter `font`: Graphics font to be registered.
255 ///
256 ///
257 /// Parameter `error`: Pointer to receive CFError in the case of failed registration.
258 ///
259 ///
260 /// Returns: Returns true if registration of the fonts was successful.
261 ///
262 /// # Safety
263 ///
264 /// `error` must be a valid pointer or null.
265 #[cfg(feature = "objc2-core-graphics")]
266 #[deprecated = "Use CTFontManagerCreateFontDescriptorsFromData or CTFontManagerRegisterFontsForURL"]
267 pub fn CTFontManagerRegisterGraphicsFont(font: &CGFont, error: *mut *mut CFError) -> bool;
268}
269
270extern "C-unwind" {
271 /// Unregisters the specified graphics font with the font manager. Unregistered fonts do not participate in font descriptor matching.
272 ///
273 ///
274 /// Parameter `font`: Graphics font to be unregistered.
275 ///
276 ///
277 /// Parameter `error`: Pointer to receive CFError in the case of failed unregistration.
278 ///
279 ///
280 /// Returns: Returns true if unregistration of the font was successful.
281 ///
282 /// # Safety
283 ///
284 /// `error` must be a valid pointer or null.
285 #[cfg(feature = "objc2-core-graphics")]
286 #[deprecated = "Use the API corresponding to the one used to register the font"]
287 pub fn CTFontManagerUnregisterGraphicsFont(font: &CGFont, error: *mut *mut CFError) -> bool;
288}
289
290extern "C-unwind" {
291 /// Registers fonts from the specified font URLs with the font manager. Registered fonts are discoverable through font descriptor matching.
292 ///
293 ///
294 /// 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.
295 ///
296 ///
297 /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
298 ///
299 ///
300 /// 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.
301 ///
302 ///
303 /// Returns: Returns true if registration of all font URLs was successful. Otherwise false.
304 ///
305 /// # Safety
306 ///
307 /// - `font_ur_ls` generic must be of the correct type.
308 /// - `errors` must be a valid pointer or null.
309 #[deprecated]
310 pub fn CTFontManagerRegisterFontsForURLs(
311 font_ur_ls: &CFArray,
312 scope: CTFontManagerScope,
313 errors: *mut *const CFArray,
314 ) -> bool;
315}
316
317extern "C-unwind" {
318 /// Unregisters fonts from the specified font URLs with the font manager. Unregistered fonts do not participate in font descriptor matching.
319 /// iOS note: only fonts registered with CTFontManagerRegisterFontsForURL or CTFontManagerRegisterFontsForURLs can be unregistered with this API.
320 ///
321 ///
322 /// Parameter `fontURLs`: Array of font URLs.
323 ///
324 ///
325 /// 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.
326 ///
327 ///
328 /// 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.
329 ///
330 ///
331 /// Returns: Returns true if unregistration of all font URLs was successful. Otherwise false.
332 ///
333 /// # Safety
334 ///
335 /// - `font_ur_ls` generic must be of the correct type.
336 /// - `errors` must be a valid pointer or null.
337 #[deprecated]
338 pub fn CTFontManagerUnregisterFontsForURLs(
339 font_ur_ls: &CFArray,
340 scope: CTFontManagerScope,
341 errors: *mut *const CFArray,
342 ) -> bool;
343}
344
345extern "C-unwind" {
346 /// Registers fonts from the specified font URLs with the font manager. Registered fonts are discoverable through font descriptor matching in the calling process
347 ///
348 ///
349 /// 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.
350 ///
351 ///
352 /// 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.
353 ///
354 ///
355 /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
356 ///
357 ///
358 /// Parameter `enabled`: Boolean value indicating whether the font derived from the URL should be enabled for font descriptor matching and/or discoverable via CTFontManagerRequestFonts.
359 ///
360 ///
361 /// 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.
362 ///
363 /// # Safety
364 ///
365 /// `font_ur_ls` generic must be of the correct type.
366 #[cfg(feature = "block2")]
367 pub fn CTFontManagerRegisterFontURLs(
368 font_ur_ls: &CFArray,
369 scope: CTFontManagerScope,
370 enabled: bool,
371 registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
372 );
373}
374
375extern "C-unwind" {
376 /// Unregisters fonts from the specified font URLs with the font manager. Unregistered fonts do not participate in font descriptor matching.
377 /// iOS note: only fonts registered with CTFontManagerRegisterFontsForURL or CTFontManagerRegisterFontsForURLs can be unregistered with this API.
378 ///
379 ///
380 /// Parameter `fontURLs`: Array of font URLs.
381 ///
382 ///
383 /// 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.
384 ///
385 ///
386 /// 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.
387 ///
388 /// # Safety
389 ///
390 /// `font_ur_ls` generic must be of the correct type.
391 #[cfg(feature = "block2")]
392 pub fn CTFontManagerUnregisterFontURLs(
393 font_ur_ls: &CFArray,
394 scope: CTFontManagerScope,
395 registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
396 );
397}
398
399extern "C-unwind" {
400 /// Registers font descriptors with the font manager. Registered fonts are discoverable through font descriptor matching in the calling process.
401 ///
402 ///
403 /// 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.
404 ///
405 ///
406 /// Parameter `fontDescriptors`: Array of font descriptors to register. Font descriptor keys used for registration are: kCTFontURLAttribute, kCTFontNameAttribute, kCTFontFamilyNameAttribute, or kCTFontRegistrationUserInfoAttribute.
407 ///
408 ///
409 /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
410 ///
411 ///
412 /// Parameter `enabled`: Boolean value indicating whether the font descriptors should be enabled for font descriptor matching and/or discoverable via CTFontManagerRequestFonts.
413 ///
414 ///
415 /// 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.
416 ///
417 /// # Safety
418 ///
419 /// `font_descriptors` generic must be of the correct type.
420 #[cfg(feature = "block2")]
421 pub fn CTFontManagerRegisterFontDescriptors(
422 font_descriptors: &CFArray,
423 scope: CTFontManagerScope,
424 enabled: bool,
425 registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
426 );
427}
428
429extern "C-unwind" {
430 /// Unregisters font descriptors with the font manager. Unregistered fonts do not participate in font descriptor matching.
431 ///
432 ///
433 /// Parameter `fontDescriptors`: Array of font descriptors to unregister.
434 ///
435 ///
436 /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
437 ///
438 ///
439 /// 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.
440 ///
441 /// # Safety
442 ///
443 /// `font_descriptors` generic must be of the correct type.
444 #[cfg(feature = "block2")]
445 pub fn CTFontManagerUnregisterFontDescriptors(
446 font_descriptors: &CFArray,
447 scope: CTFontManagerScope,
448 registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
449 );
450}
451
452extern "C-unwind" {
453 /// Registers named font assets in the specified bundle with the font manager. Registered fonts are discoverable through font descriptor matching in the calling process.
454 ///
455 ///
456 /// 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.
457 /// 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.
458 ///
459 ///
460 /// Parameter `fontAssetNames`: Array of font name assets in asset catalog.
461 ///
462 ///
463 /// Parameter `bundle`: Bundle containing asset catalog. A null value resolves to the main bundle.
464 ///
465 ///
466 /// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. kCTFontManagerScopePersistent is the only supported scope for iOS.
467 ///
468 ///
469 /// Parameter `enabled`: Boolean value indicating whether the font assets should be enabled for font descriptor matching and/or discoverable via CTFontManagerRequestFonts.
470 ///
471 ///
472 /// 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.
473 ///
474 /// # Safety
475 ///
476 /// `font_asset_names` generic must be of the correct type.
477 #[cfg(feature = "block2")]
478 pub fn CTFontManagerRegisterFontsWithAssetNames(
479 font_asset_names: &CFArray,
480 bundle: Option<&CFBundle>,
481 scope: CTFontManagerScope,
482 enabled: bool,
483 registration_handler: Option<&block2::DynBlock<dyn Fn(NonNull<CFArray>, bool) -> bool>>,
484 );
485}
486
487extern "C-unwind" {
488 /// Enables or disables the matching font descriptors for font descriptor matching.
489 ///
490 ///
491 /// Parameter `descriptors`: Array of font descriptors.
492 ///
493 ///
494 /// Parameter `enable`: Boolean value indicating whether the fonts matching descriptors should be enabled for font descriptor matching.
495 ///
496 /// # Safety
497 ///
498 /// `descriptors` generic must be of the correct type.
499 pub fn CTFontManagerEnableFontDescriptors(descriptors: &CFArray, enable: bool);
500}
501
502extern "C-unwind" {
503 /// Returns the registration scope of the specified URL.
504 ///
505 ///
506 /// Parameter `fontURL`: Font URL.
507 ///
508 ///
509 /// Returns: Returns the registration scope of the specified URL, will return kCTFontManagerScopeNone if not currently registered.
510 pub fn CTFontManagerGetScopeForURL(font_url: &CFURL) -> CTFontManagerScope;
511}
512
513/// Returns the font descriptors that were registered with the font manager.
514///
515///
516/// 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.
517///
518///
519/// Parameter `scope`: Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
520///
521///
522/// Parameter `enabled`: Boolean value indicating if the caller is interested in registered font descriptors that are enabled or disabled.
523///
524///
525/// Returns: Array of of font descriptors registered by the application. Array may be empty if nothing is registered.
526#[inline]
527pub unsafe extern "C-unwind" fn CTFontManagerCopyRegisteredFontDescriptors(
528 scope: CTFontManagerScope,
529 enabled: bool,
530) -> CFRetained<CFArray> {
531 extern "C-unwind" {
532 fn CTFontManagerCopyRegisteredFontDescriptors(
533 scope: CTFontManagerScope,
534 enabled: bool,
535 ) -> Option<NonNull<CFArray>>;
536 }
537 let ret = unsafe { CTFontManagerCopyRegisteredFontDescriptors(scope, enabled) };
538 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
539 unsafe { CFRetained::from_raw(ret) }
540}
541
542extern "C-unwind" {
543 /// 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.
544 ///
545 ///
546 /// 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.
547 ///
548 ///
549 /// 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.
550 ///
551 ///
552 /// 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.
553 ///
554 /// # Safety
555 ///
556 /// `font_descriptors` generic must be of the correct type.
557 #[cfg(feature = "block2")]
558 pub fn CTFontManagerRequestFonts(
559 font_descriptors: &CFArray,
560 completion_handler: &block2::DynBlock<dyn Fn(NonNull<CFArray>)>,
561 );
562}
563
564extern "C-unwind" {
565 /// Determines whether a file is in a supported font format.
566 ///
567 ///
568 /// This function does not validate any font data, so clients using it must still be prepared to handle failed registration or font descriptor creation.
569 ///
570 ///
571 /// Parameter `fontURL`: A file URL.
572 ///
573 ///
574 /// Returns: This function returns true if the file is in a supported font format.
575 pub fn CTFontManagerIsSupportedFont(font_url: &CFURL) -> bool;
576}
577
578/// Creates a CFRunLoopSourceRef that will be used to convey font requests from CTFontManager.
579///
580/// Parameter `sourceOrder`: The order of the created run loop source.
581///
582/// Parameter `createMatchesCallback`: A block to handle the font request.
583///
584/// 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.
585///
586/// # Safety
587///
588/// `create_matches_callback` block's return must be a valid pointer.
589#[cfg(all(feature = "block2", feature = "libc"))]
590#[deprecated = "This functionality will be removed in a future release"]
591#[inline]
592pub unsafe extern "C-unwind" fn CTFontManagerCreateFontRequestRunLoopSource(
593 source_order: CFIndex,
594 create_matches_callback: &block2::DynBlock<
595 dyn Fn(NonNull<CFDictionary>, libc::pid_t) -> NonNull<CFArray>,
596 >,
597) -> Option<CFRetained<CFRunLoopSource>> {
598 extern "C-unwind" {
599 fn CTFontManagerCreateFontRequestRunLoopSource(
600 source_order: CFIndex,
601 create_matches_callback: &block2::DynBlock<
602 dyn Fn(NonNull<CFDictionary>, libc::pid_t) -> NonNull<CFArray>,
603 >,
604 ) -> Option<NonNull<CFRunLoopSource>>;
605 }
606 let ret = unsafe {
607 CTFontManagerCreateFontRequestRunLoopSource(source_order, create_matches_callback)
608 };
609 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
610}
611
612extern "C" {
613 /// CTFontManage bundle identifier
614 ///
615 /// The CTFontManager bundle identifier to be used with get or set global auto-activation settings.
616 ///
617 /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontmanagerbundleidentifier?language=objc)
618 pub static kCTFontManagerBundleIdentifier: &'static CFString;
619}
620
621/// Auto-activation settings.
622///
623/// Default auto-activation setting. When specified, the application will use the global setting.
624///
625/// Disables auto-activation.
626///
627/// Enables auto-activation.
628///
629/// Requires user input for auto-activation. A dialog will be presented to the user to confirm auto
630/// activation of the font.
631///
632/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctfontmanagerautoactivationsetting?language=objc)
633// NS_ENUM
634#[repr(transparent)]
635#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
636pub struct CTFontManagerAutoActivationSetting(pub u32);
637impl CTFontManagerAutoActivationSetting {
638 #[doc(alias = "kCTFontManagerAutoActivationDefault")]
639 pub const Default: Self = Self(0);
640 #[doc(alias = "kCTFontManagerAutoActivationDisabled")]
641 pub const Disabled: Self = Self(1);
642 #[doc(alias = "kCTFontManagerAutoActivationEnabled")]
643 pub const Enabled: Self = Self(2);
644 #[doc(alias = "kCTFontManagerAutoActivationPromptUser")]
645 #[deprecated = "Deprecated"]
646 pub const PromptUser: Self = Self(3);
647}
648
649#[cfg(feature = "objc2")]
650unsafe impl Encode for CTFontManagerAutoActivationSetting {
651 const ENCODING: Encoding = u32::ENCODING;
652}
653
654#[cfg(feature = "objc2")]
655unsafe impl RefEncode for CTFontManagerAutoActivationSetting {
656 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
657}
658
659extern "C-unwind" {
660 /// Sets the auto-activation for the specified bundle identifier.
661 ///
662 /// Parameter `bundleIdentifier`: The bundle identifier. Used to specify a particular application bundle. If NULL,
663 /// the current application bundle will be used. If kCTFontManagerBundleIdentifier is specified,
664 /// will set the global auto-activation settings.
665 ///
666 /// Parameter `setting`: The new setting.
667 ///
668 /// Function will apply the setting to the appropriate preferences location.
669 pub fn CTFontManagerSetAutoActivationSetting(
670 bundle_identifier: Option<&CFString>,
671 setting: CTFontManagerAutoActivationSetting,
672 );
673}
674
675extern "C-unwind" {
676 /// Accessor for the auto-activation setting.
677 ///
678 /// Parameter `bundleIdentifier`: The bundle identifier. Used to specify a particular application bundle. If NULL,
679 /// the current application bundle will be used. If kCTFontManagerBundleIdentifier is specified,
680 /// will set the global auto-activation settings.
681 ///
682 /// Returns: Will return the auto-activation setting for specified bundle identifier.
683 pub fn CTFontManagerGetAutoActivationSetting(
684 bundle_identifier: Option<&CFString>,
685 ) -> CTFontManagerAutoActivationSetting;
686}
687
688extern "C" {
689 /// Notification name for font registry changes.
690 ///
691 /// This is the string to use as the notification name when subscribing
692 /// to CTFontManager notifications. This notification will be posted when fonts are added or removed.
693 /// OS X clients should register as an observer of the notification with the distributed notification center
694 /// for changes in session or persistent scopes and with the local notification center for changes in process scope.
695 /// iOS clients should register as an observer of the notification with the local notification center for all changes.
696 ///
697 /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontmanagerregisteredfontschangednotification?language=objc)
698 pub static kCTFontManagerRegisteredFontsChangedNotification: &'static CFString;
699}