objc2_core_text/generated/CTFontCollection.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctfontcollection?language=objc)
14#[repr(C)]
15pub struct CTFontCollection {
16 inner: [u8; 0],
17 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
18}
19
20cf_type!(
21 #[encoding_name = "__CTFontCollection"]
22 unsafe impl CTFontCollection {}
23);
24
25/// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctmutablefontcollection?language=objc)
26#[repr(C)]
27pub struct CTMutableFontCollection {
28 inner: [u8; 0],
29 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
30}
31
32cf_type!(
33 #[encoding_name = "__CTFontCollection"]
34 unsafe impl CTMutableFontCollection: CTFontCollection {}
35);
36
37unsafe impl ConcreteType for CTFontCollection {
38 /// Returns the type identifier for Core Text font collection references.
39 ///
40 /// Returns: The identifier for the opaque types CTFontCollectionRef or CTMutableFontCollectionRef.
41 #[doc(alias = "CTFontCollectionGetTypeID")]
42 #[inline]
43 fn type_id() -> CFTypeID {
44 extern "C-unwind" {
45 fn CTFontCollectionGetTypeID() -> CFTypeID;
46 }
47 unsafe { CTFontCollectionGetTypeID() }
48 }
49}
50
51/// Collection sorting callback.
52///
53/// This callback can be specified to obtain the matching font descriptors of a collection in sorted order. Return the appropriate comparison result of first descriptor to second descriptor.
54///
55/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctfontcollectionsortdescriptorscallback?language=objc)
56#[cfg(feature = "CTFontDescriptor")]
57pub type CTFontCollectionSortDescriptorsCallback = Option<
58 unsafe extern "C-unwind" fn(
59 NonNull<CTFontDescriptor>,
60 NonNull<CTFontDescriptor>,
61 NonNull<c_void>,
62 ) -> CFComparisonResult,
63>;
64
65extern "C" {
66 /// kCTFontCollectionRemoveDuplicatesOption
67 ///
68 /// Option key to specify filtering of duplicates.
69 ///
70 /// Specify this option key in the options dictionary with a non- zero value to enable automatic filtering of duplicate font descriptors.
71 ///
72 /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontcollectionremoveduplicatesoption?language=objc)
73 pub static kCTFontCollectionRemoveDuplicatesOption: &'static CFString;
74}
75
76extern "C" {
77 /// kCTFontCollectionIncludeDisabledFontsOption
78 ///
79 /// Option key to include disabled fonts in the matching results.
80 ///
81 /// Specify this option key in the options dictionary with a non-zero value to enable matching of disabled fonts. You can pass font descriptors specifying disabled fonts to CTFontManagerEnableFontDescriptors, but you cannot use such a font descriptor to query font attributes from the system database or create a CTFontRef.
82 ///
83 /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontcollectionincludedisabledfontsoption?language=objc)
84 pub static kCTFontCollectionIncludeDisabledFontsOption: &'static CFString;
85}
86
87extern "C" {
88 /// kCTFontCollectionDisallowAutoActivationOption
89 ///
90 /// Option key to avoid auto-activating fonts.
91 ///
92 /// Specify this option key in the options dictionary with a non-zero value to disallow searches for missing fonts (font descriptors returning no results).
93 ///
94 /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctfontcollectiondisallowautoactivationoption?language=objc)
95 pub static kCTFontCollectionDisallowAutoActivationOption: &'static CFString;
96}
97
98/// Returns a new font collection matching all available fonts.
99///
100///
101/// Parameter `options`: The options dictionary. See constant option keys.
102///
103///
104/// Returns: This function creates a new collection containing all fonts available to the current application.
105#[inline]
106pub unsafe extern "C-unwind" fn CTFontCollectionCreateFromAvailableFonts(
107 options: Option<&CFDictionary>,
108) -> CFRetained<CTFontCollection> {
109 extern "C-unwind" {
110 fn CTFontCollectionCreateFromAvailableFonts(
111 options: Option<&CFDictionary>,
112 ) -> Option<NonNull<CTFontCollection>>;
113 }
114 let ret = unsafe { CTFontCollectionCreateFromAvailableFonts(options) };
115 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
116 unsafe { CFRetained::from_raw(ret) }
117}
118
119/// Returns a new collection based on the array of font descriptors.
120///
121///
122/// Parameter `queryDescriptors`: An array of font descriptors to use for matching. May be NULL, in which case the matching descriptors will be NULL.
123///
124///
125/// Parameter `options`: The options dictionary. See constant option keys.
126///
127///
128/// Returns: This function creates a new collection based on the provided font descriptors. The contents of this collection is defined by matching the provided descriptors against all available font descriptors.
129#[inline]
130pub unsafe extern "C-unwind" fn CTFontCollectionCreateWithFontDescriptors(
131 query_descriptors: Option<&CFArray>,
132 options: Option<&CFDictionary>,
133) -> CFRetained<CTFontCollection> {
134 extern "C-unwind" {
135 fn CTFontCollectionCreateWithFontDescriptors(
136 query_descriptors: Option<&CFArray>,
137 options: Option<&CFDictionary>,
138 ) -> Option<NonNull<CTFontCollection>>;
139 }
140 let ret = unsafe { CTFontCollectionCreateWithFontDescriptors(query_descriptors, options) };
141 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
142 unsafe { CFRetained::from_raw(ret) }
143}
144
145/// Returns a copy of the original collection augmented with the new font descriptors.
146///
147///
148/// Parameter `original`: The original font collection reference.
149///
150///
151/// Parameter `queryDescriptors`: An array of font descriptors to augment those of the original collection.
152///
153///
154/// Parameter `options`: The options dictionary. See constant option keys.
155///
156///
157/// Returns: This function creates a copy of the original font collection augmented by the new font descriptors and options. The new font descriptors are merged with the existing descriptors to create a single set.
158#[inline]
159pub unsafe extern "C-unwind" fn CTFontCollectionCreateCopyWithFontDescriptors(
160 original: &CTFontCollection,
161 query_descriptors: Option<&CFArray>,
162 options: Option<&CFDictionary>,
163) -> CFRetained<CTFontCollection> {
164 extern "C-unwind" {
165 fn CTFontCollectionCreateCopyWithFontDescriptors(
166 original: &CTFontCollection,
167 query_descriptors: Option<&CFArray>,
168 options: Option<&CFDictionary>,
169 ) -> Option<NonNull<CTFontCollection>>;
170 }
171 let ret = unsafe {
172 CTFontCollectionCreateCopyWithFontDescriptors(original, query_descriptors, options)
173 };
174 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
175 unsafe { CFRetained::from_raw(ret) }
176}
177
178/// Returns a mutable copy of the original collection.
179///
180///
181/// Parameter `original`: The original font collection reference.
182///
183///
184/// Returns: This function creates a mutable copy of the original font collection.
185#[inline]
186pub unsafe extern "C-unwind" fn CTFontCollectionCreateMutableCopy(
187 original: &CTFontCollection,
188) -> CFRetained<CTMutableFontCollection> {
189 extern "C-unwind" {
190 fn CTFontCollectionCreateMutableCopy(
191 original: &CTFontCollection,
192 ) -> Option<NonNull<CTMutableFontCollection>>;
193 }
194 let ret = unsafe { CTFontCollectionCreateMutableCopy(original) };
195 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
196 unsafe { CFRetained::from_raw(ret) }
197}
198
199/// Returns the array of descriptors to match.
200///
201///
202/// Parameter `collection`: The font collection reference.
203///
204///
205/// Returns: This function returns a retained reference to the array of descriptors to be used to query (match) the system font database. The return value is undefined if CTFontCollectionCreateFromAvailableFonts was used to create the collection.
206#[inline]
207pub unsafe extern "C-unwind" fn CTFontCollectionCopyQueryDescriptors(
208 collection: &CTFontCollection,
209) -> Option<CFRetained<CFArray>> {
210 extern "C-unwind" {
211 fn CTFontCollectionCopyQueryDescriptors(
212 collection: &CTFontCollection,
213 ) -> Option<NonNull<CFArray>>;
214 }
215 let ret = unsafe { CTFontCollectionCopyQueryDescriptors(collection) };
216 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
217}
218
219extern "C-unwind" {
220 /// Replaces the array of descriptors to match.
221 ///
222 ///
223 /// Parameter `collection`: The font collection reference.
224 ///
225 ///
226 /// Parameter `descriptors`: An array of CTFontDescriptorRef. May be NULL to represent an empty collection, in which case the matching descriptors will also be NULL.
227 pub fn CTFontCollectionSetQueryDescriptors(
228 collection: &CTMutableFontCollection,
229 descriptors: Option<&CFArray>,
230 );
231}
232
233/// Returns the array of descriptors to exclude from the match.
234///
235///
236/// Parameter `collection`: The font collection reference.
237///
238///
239/// Returns: This function returns a retained reference to the array of descriptors to be used to query (match) the system font database.
240#[inline]
241pub unsafe extern "C-unwind" fn CTFontCollectionCopyExclusionDescriptors(
242 collection: &CTFontCollection,
243) -> Option<CFRetained<CFArray>> {
244 extern "C-unwind" {
245 fn CTFontCollectionCopyExclusionDescriptors(
246 collection: &CTFontCollection,
247 ) -> Option<NonNull<CFArray>>;
248 }
249 let ret = unsafe { CTFontCollectionCopyExclusionDescriptors(collection) };
250 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
251}
252
253extern "C-unwind" {
254 /// Replaces the array of descriptors to exclude from the match.
255 ///
256 ///
257 /// Parameter `collection`: The font collection reference.
258 ///
259 ///
260 /// Parameter `descriptors`: An array of CTFontDescriptorRef. May be NULL.
261 pub fn CTFontCollectionSetExclusionDescriptors(
262 collection: &CTMutableFontCollection,
263 descriptors: Option<&CFArray>,
264 );
265}
266
267/// Returns an array of font descriptors matching the collection.
268///
269///
270/// Parameter `collection`: The font collection reference.
271///
272///
273/// Returns: An array of CTFontDescriptors matching the collection definition or NULL if there are none.
274#[inline]
275pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptors(
276 collection: &CTFontCollection,
277) -> Option<CFRetained<CFArray>> {
278 extern "C-unwind" {
279 fn CTFontCollectionCreateMatchingFontDescriptors(
280 collection: &CTFontCollection,
281 ) -> Option<NonNull<CFArray>>;
282 }
283 let ret = unsafe { CTFontCollectionCreateMatchingFontDescriptors(collection) };
284 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
285}
286
287/// Returns the array of matching font descriptors sorted with the callback function.
288///
289///
290/// Parameter `collection`: The collection reference.
291///
292///
293/// Parameter `sortCallback`: The sorting callback function that defines the sort order.
294///
295///
296/// Parameter `refCon`: Pointer to client data define context for the callback.
297///
298///
299/// Returns: An array of CTFontDescriptors matching the criteria of the collection, sorted by the results of the sorting callback function, or NULL if there are none.
300#[cfg(feature = "CTFontDescriptor")]
301#[inline]
302pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
303 collection: &CTFontCollection,
304 sort_callback: CTFontCollectionSortDescriptorsCallback,
305 ref_con: *mut c_void,
306) -> Option<CFRetained<CFArray>> {
307 extern "C-unwind" {
308 fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
309 collection: &CTFontCollection,
310 sort_callback: CTFontCollectionSortDescriptorsCallback,
311 ref_con: *mut c_void,
312 ) -> Option<NonNull<CFArray>>;
313 }
314 let ret = unsafe {
315 CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
316 collection,
317 sort_callback,
318 ref_con,
319 )
320 };
321 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
322}
323
324/// Returns an array of font descriptors matching the collection.
325///
326///
327/// Parameter `collection`: The font collection reference.
328///
329///
330/// Parameter `options`: The options dictionary. See constant option keys. May be NULL, in which case this call returns the same results as CTFontCollectionCreateMatchingFontDescriptors, using the options passed in when the collection was created.
331///
332///
333/// Returns: An array of CTFontDescriptors matching the collection definition or NULL if there are none.
334#[inline]
335pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
336 collection: &CTFontCollection,
337 options: Option<&CFDictionary>,
338) -> Option<CFRetained<CFArray>> {
339 extern "C-unwind" {
340 fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
341 collection: &CTFontCollection,
342 options: Option<&CFDictionary>,
343 ) -> Option<NonNull<CFArray>>;
344 }
345 let ret =
346 unsafe { CTFontCollectionCreateMatchingFontDescriptorsWithOptions(collection, options) };
347 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
348}
349
350/// Returns an array of font descriptors matching the specified family, one descriptor for each style in the collection.
351///
352///
353/// Parameter `collection`: The font collection reference.
354///
355///
356/// Parameter `familyName`: The font family name
357///
358///
359/// Returns: An array of CTFontDescriptors matching the specified family in the collection or NULL if there are none.
360#[inline]
361pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
362 collection: &CTFontCollection,
363 family_name: &CFString,
364 options: Option<&CFDictionary>,
365) -> Option<CFRetained<CFArray>> {
366 extern "C-unwind" {
367 fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
368 collection: &CTFontCollection,
369 family_name: &CFString,
370 options: Option<&CFDictionary>,
371 ) -> Option<NonNull<CFArray>>;
372 }
373 let ret = unsafe {
374 CTFontCollectionCreateMatchingFontDescriptorsForFamily(collection, family_name, options)
375 };
376 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
377}
378
379/// Option bits for use with CTFontCollectionCopyFontAttribute(s).
380///
381///
382/// Passing this option indicates that the return values should be sorted in standard UI order, suitable for display to the user. This is the same sorting behavior used by NSFontPanel and Font Book.
383///
384///
385/// Passing this option indicates that duplicate values should be removed from the results.
386///
387/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctfontcollectioncopyoptions?language=objc)
388// NS_OPTIONS
389#[repr(transparent)]
390#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
391pub struct CTFontCollectionCopyOptions(pub u32);
392bitflags::bitflags! {
393 impl CTFontCollectionCopyOptions: u32 {
394 #[doc(alias = "kCTFontCollectionCopyDefaultOptions")]
395 const DefaultOptions = 0;
396 #[doc(alias = "kCTFontCollectionCopyUnique")]
397 const Unique = 1<<0;
398 #[doc(alias = "kCTFontCollectionCopyStandardSort")]
399 const StandardSort = 1<<1;
400 }
401}
402
403#[cfg(feature = "objc2")]
404unsafe impl Encode for CTFontCollectionCopyOptions {
405 const ENCODING: Encoding = u32::ENCODING;
406}
407
408#[cfg(feature = "objc2")]
409unsafe impl RefEncode for CTFontCollectionCopyOptions {
410 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
411}
412
413/// Returns an array of font descriptor attribute values.
414///
415///
416/// Parameter `collection`: The font collection reference.
417///
418///
419/// Parameter `attributeName`: The attribute to retrieve for each descriptor in the collection.
420///
421///
422/// Parameter `options`: Options to alter the return value.
423///
424///
425/// Returns: An array containing one value for each descriptor. With kCTFontCollectionCopyDefaultOptions, the values will be in the same order as the results from CTFontCollectionCreateMatchingFontDescriptors and NULL values will be transformed to kCFNull. When the kCTFontCollectionCopyUnique is set, duplicate values will be removed. When kCTFontCollectionCopyStandardSort is set, the values will be sorted in standard UI order.
426#[inline]
427pub unsafe extern "C-unwind" fn CTFontCollectionCopyFontAttribute(
428 collection: &CTFontCollection,
429 attribute_name: &CFString,
430 options: CTFontCollectionCopyOptions,
431) -> CFRetained<CFArray> {
432 extern "C-unwind" {
433 fn CTFontCollectionCopyFontAttribute(
434 collection: &CTFontCollection,
435 attribute_name: &CFString,
436 options: CTFontCollectionCopyOptions,
437 ) -> Option<NonNull<CFArray>>;
438 }
439 let ret = unsafe { CTFontCollectionCopyFontAttribute(collection, attribute_name, options) };
440 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
441 unsafe { CFRetained::from_raw(ret) }
442}
443
444/// Returns an array of dictionaries containing font descriptor attribute values.
445///
446///
447/// Parameter `collection`: The font collection reference.
448///
449///
450/// Parameter `attributeNames`: The attributes to retrieve for each descriptor in the collection.
451///
452///
453/// Parameter `options`: Options to alter the return value.
454///
455///
456/// Returns: An array containing one CFDictionary value for each descriptor mapping the requested attribute names. With kCTFontCollectionCopyDefaultOptions, the values will be in the same order as the results from CTFontCollectionCreateMatchingFontDescriptors. When the kCTFontCollectionCopyUnique is set, duplicate values will be removed. When kCTFontCollectionCopyStandardSort is set, the values will be sorted in standard UI order.
457#[inline]
458pub unsafe extern "C-unwind" fn CTFontCollectionCopyFontAttributes(
459 collection: &CTFontCollection,
460 attribute_names: &CFSet,
461 options: CTFontCollectionCopyOptions,
462) -> CFRetained<CFArray> {
463 extern "C-unwind" {
464 fn CTFontCollectionCopyFontAttributes(
465 collection: &CTFontCollection,
466 attribute_names: &CFSet,
467 options: CTFontCollectionCopyOptions,
468 ) -> Option<NonNull<CFArray>>;
469 }
470 let ret = unsafe { CTFontCollectionCopyFontAttributes(collection, attribute_names, options) };
471 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
472 unsafe { CFRetained::from_raw(ret) }
473}