1use 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#[repr(C)]
15pub struct CTFontCollection {
16 inner: [u8; 0],
17 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
18}
19
20cf_type!(
21 unsafe impl CTFontCollection {}
22);
23#[cfg(feature = "objc2")]
24cf_objc2_type!(
25 unsafe impl RefEncode<"__CTFontCollection"> for CTFontCollection {}
26);
27
28#[repr(C)]
30pub struct CTMutableFontCollection {
31 inner: [u8; 0],
32 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
33}
34
35cf_type!(
36 unsafe impl CTMutableFontCollection: CTFontCollection {}
37);
38#[cfg(feature = "objc2")]
39cf_objc2_type!(
40 unsafe impl RefEncode<"__CTFontCollection"> for CTMutableFontCollection {}
41);
42
43unsafe impl ConcreteType for CTFontCollection {
44 #[doc(alias = "CTFontCollectionGetTypeID")]
48 #[inline]
49 fn type_id() -> CFTypeID {
50 extern "C-unwind" {
51 fn CTFontCollectionGetTypeID() -> CFTypeID;
52 }
53 unsafe { CTFontCollectionGetTypeID() }
54 }
55}
56
57#[cfg(feature = "CTFontDescriptor")]
63pub type CTFontCollectionSortDescriptorsCallback = Option<
64 unsafe extern "C-unwind" fn(
65 NonNull<CTFontDescriptor>,
66 NonNull<CTFontDescriptor>,
67 NonNull<c_void>,
68 ) -> CFComparisonResult,
69>;
70
71extern "C" {
72 pub static kCTFontCollectionRemoveDuplicatesOption: &'static CFString;
80}
81
82extern "C" {
83 pub static kCTFontCollectionIncludeDisabledFontsOption: &'static CFString;
91}
92
93extern "C" {
94 pub static kCTFontCollectionDisallowAutoActivationOption: &'static CFString;
102}
103
104impl CTFontCollection {
105 #[doc(alias = "CTFontCollectionCreateFromAvailableFonts")]
113 #[inline]
114 pub unsafe fn from_available_fonts(
115 options: Option<&CFDictionary>,
116 ) -> CFRetained<CTFontCollection> {
117 extern "C-unwind" {
118 fn CTFontCollectionCreateFromAvailableFonts(
119 options: Option<&CFDictionary>,
120 ) -> Option<NonNull<CTFontCollection>>;
121 }
122 let ret = unsafe { CTFontCollectionCreateFromAvailableFonts(options) };
123 let ret =
124 ret.expect("function was marked as returning non-null, but actually returned NULL");
125 unsafe { CFRetained::from_raw(ret) }
126 }
127
128 #[doc(alias = "CTFontCollectionCreateWithFontDescriptors")]
139 #[inline]
140 pub unsafe fn with_font_descriptors(
141 query_descriptors: Option<&CFArray>,
142 options: Option<&CFDictionary>,
143 ) -> CFRetained<CTFontCollection> {
144 extern "C-unwind" {
145 fn CTFontCollectionCreateWithFontDescriptors(
146 query_descriptors: Option<&CFArray>,
147 options: Option<&CFDictionary>,
148 ) -> Option<NonNull<CTFontCollection>>;
149 }
150 let ret = unsafe { CTFontCollectionCreateWithFontDescriptors(query_descriptors, options) };
151 let ret =
152 ret.expect("function was marked as returning non-null, but actually returned NULL");
153 unsafe { CFRetained::from_raw(ret) }
154 }
155
156 #[doc(alias = "CTFontCollectionCreateCopyWithFontDescriptors")]
170 #[inline]
171 pub unsafe fn copy_with_font_descriptors(
172 self: &CTFontCollection,
173 query_descriptors: Option<&CFArray>,
174 options: Option<&CFDictionary>,
175 ) -> CFRetained<CTFontCollection> {
176 extern "C-unwind" {
177 fn CTFontCollectionCreateCopyWithFontDescriptors(
178 original: &CTFontCollection,
179 query_descriptors: Option<&CFArray>,
180 options: Option<&CFDictionary>,
181 ) -> Option<NonNull<CTFontCollection>>;
182 }
183 let ret = unsafe {
184 CTFontCollectionCreateCopyWithFontDescriptors(self, query_descriptors, options)
185 };
186 let ret =
187 ret.expect("function was marked as returning non-null, but actually returned NULL");
188 unsafe { CFRetained::from_raw(ret) }
189 }
190}
191
192impl CTMutableFontCollection {
193 #[doc(alias = "CTFontCollectionCreateMutableCopy")]
201 #[inline]
202 pub unsafe fn new_copy(original: &CTFontCollection) -> CFRetained<CTMutableFontCollection> {
203 extern "C-unwind" {
204 fn CTFontCollectionCreateMutableCopy(
205 original: &CTFontCollection,
206 ) -> Option<NonNull<CTMutableFontCollection>>;
207 }
208 let ret = unsafe { CTFontCollectionCreateMutableCopy(original) };
209 let ret =
210 ret.expect("function was marked as returning non-null, but actually returned NULL");
211 unsafe { CFRetained::from_raw(ret) }
212 }
213}
214
215impl CTFontCollection {
216 #[doc(alias = "CTFontCollectionCopyQueryDescriptors")]
224 #[inline]
225 pub unsafe fn query_descriptors(self: &CTFontCollection) -> Option<CFRetained<CFArray>> {
226 extern "C-unwind" {
227 fn CTFontCollectionCopyQueryDescriptors(
228 collection: &CTFontCollection,
229 ) -> Option<NonNull<CFArray>>;
230 }
231 let ret = unsafe { CTFontCollectionCopyQueryDescriptors(self) };
232 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
233 }
234}
235
236impl CTMutableFontCollection {
237 #[doc(alias = "CTFontCollectionSetQueryDescriptors")]
245 #[inline]
246 pub unsafe fn set_query_descriptors(
247 self: &CTMutableFontCollection,
248 descriptors: Option<&CFArray>,
249 ) {
250 extern "C-unwind" {
251 fn CTFontCollectionSetQueryDescriptors(
252 collection: &CTMutableFontCollection,
253 descriptors: Option<&CFArray>,
254 );
255 }
256 unsafe { CTFontCollectionSetQueryDescriptors(self, descriptors) }
257 }
258}
259
260impl CTFontCollection {
261 #[doc(alias = "CTFontCollectionCopyExclusionDescriptors")]
269 #[inline]
270 pub unsafe fn exclusion_descriptors(self: &CTFontCollection) -> Option<CFRetained<CFArray>> {
271 extern "C-unwind" {
272 fn CTFontCollectionCopyExclusionDescriptors(
273 collection: &CTFontCollection,
274 ) -> Option<NonNull<CFArray>>;
275 }
276 let ret = unsafe { CTFontCollectionCopyExclusionDescriptors(self) };
277 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
278 }
279}
280
281impl CTMutableFontCollection {
282 #[doc(alias = "CTFontCollectionSetExclusionDescriptors")]
290 #[inline]
291 pub unsafe fn set_exclusion_descriptors(
292 self: &CTMutableFontCollection,
293 descriptors: Option<&CFArray>,
294 ) {
295 extern "C-unwind" {
296 fn CTFontCollectionSetExclusionDescriptors(
297 collection: &CTMutableFontCollection,
298 descriptors: Option<&CFArray>,
299 );
300 }
301 unsafe { CTFontCollectionSetExclusionDescriptors(self, descriptors) }
302 }
303}
304
305impl CTFontCollection {
306 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptors")]
314 #[inline]
315 pub unsafe fn matching_font_descriptors(
316 self: &CTFontCollection,
317 ) -> Option<CFRetained<CFArray>> {
318 extern "C-unwind" {
319 fn CTFontCollectionCreateMatchingFontDescriptors(
320 collection: &CTFontCollection,
321 ) -> Option<NonNull<CFArray>>;
322 }
323 let ret = unsafe { CTFontCollectionCreateMatchingFontDescriptors(self) };
324 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
325 }
326
327 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback")]
341 #[cfg(feature = "CTFontDescriptor")]
342 #[inline]
343 pub unsafe fn matching_font_descriptors_sorted_with_callback(
344 self: &CTFontCollection,
345 sort_callback: CTFontCollectionSortDescriptorsCallback,
346 ref_con: *mut c_void,
347 ) -> Option<CFRetained<CFArray>> {
348 extern "C-unwind" {
349 fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
350 collection: &CTFontCollection,
351 sort_callback: CTFontCollectionSortDescriptorsCallback,
352 ref_con: *mut c_void,
353 ) -> Option<NonNull<CFArray>>;
354 }
355 let ret = unsafe {
356 CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
357 self,
358 sort_callback,
359 ref_con,
360 )
361 };
362 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
363 }
364
365 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptorsWithOptions")]
376 #[inline]
377 pub unsafe fn matching_font_descriptors_with_options(
378 self: &CTFontCollection,
379 options: Option<&CFDictionary>,
380 ) -> Option<CFRetained<CFArray>> {
381 extern "C-unwind" {
382 fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
383 collection: &CTFontCollection,
384 options: Option<&CFDictionary>,
385 ) -> Option<NonNull<CFArray>>;
386 }
387 let ret =
388 unsafe { CTFontCollectionCreateMatchingFontDescriptorsWithOptions(self, options) };
389 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
390 }
391
392 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptorsForFamily")]
403 #[inline]
404 pub unsafe fn matching_font_descriptors_for_family(
405 self: &CTFontCollection,
406 family_name: &CFString,
407 options: Option<&CFDictionary>,
408 ) -> Option<CFRetained<CFArray>> {
409 extern "C-unwind" {
410 fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
411 collection: &CTFontCollection,
412 family_name: &CFString,
413 options: Option<&CFDictionary>,
414 ) -> Option<NonNull<CFArray>>;
415 }
416 let ret = unsafe {
417 CTFontCollectionCreateMatchingFontDescriptorsForFamily(self, family_name, options)
418 };
419 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
420 }
421}
422
423#[repr(transparent)]
434#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
435pub struct CTFontCollectionCopyOptions(pub u32);
436bitflags::bitflags! {
437 impl CTFontCollectionCopyOptions: u32 {
438 #[doc(alias = "kCTFontCollectionCopyDefaultOptions")]
439 const DefaultOptions = 0;
440 #[doc(alias = "kCTFontCollectionCopyUnique")]
441 const Unique = 1<<0;
442 #[doc(alias = "kCTFontCollectionCopyStandardSort")]
443 const StandardSort = 1<<1;
444 }
445}
446
447#[cfg(feature = "objc2")]
448unsafe impl Encode for CTFontCollectionCopyOptions {
449 const ENCODING: Encoding = u32::ENCODING;
450}
451
452#[cfg(feature = "objc2")]
453unsafe impl RefEncode for CTFontCollectionCopyOptions {
454 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
455}
456
457impl CTFontCollection {
458 #[doc(alias = "CTFontCollectionCopyFontAttribute")]
472 #[inline]
473 pub unsafe fn font_attribute(
474 self: &CTFontCollection,
475 attribute_name: &CFString,
476 options: CTFontCollectionCopyOptions,
477 ) -> CFRetained<CFArray> {
478 extern "C-unwind" {
479 fn CTFontCollectionCopyFontAttribute(
480 collection: &CTFontCollection,
481 attribute_name: &CFString,
482 options: CTFontCollectionCopyOptions,
483 ) -> Option<NonNull<CFArray>>;
484 }
485 let ret = unsafe { CTFontCollectionCopyFontAttribute(self, attribute_name, options) };
486 let ret =
487 ret.expect("function was marked as returning non-null, but actually returned NULL");
488 unsafe { CFRetained::from_raw(ret) }
489 }
490
491 #[doc(alias = "CTFontCollectionCopyFontAttributes")]
505 #[inline]
506 pub unsafe fn font_attributes(
507 self: &CTFontCollection,
508 attribute_names: &CFSet,
509 options: CTFontCollectionCopyOptions,
510 ) -> CFRetained<CFArray> {
511 extern "C-unwind" {
512 fn CTFontCollectionCopyFontAttributes(
513 collection: &CTFontCollection,
514 attribute_names: &CFSet,
515 options: CTFontCollectionCopyOptions,
516 ) -> Option<NonNull<CFArray>>;
517 }
518 let ret = unsafe { CTFontCollectionCopyFontAttributes(self, attribute_names, options) };
519 let ret =
520 ret.expect("function was marked as returning non-null, but actually returned NULL");
521 unsafe { CFRetained::from_raw(ret) }
522 }
523}
524
525#[deprecated = "renamed to `CTFontCollection::from_available_fonts`"]
526#[inline]
527pub unsafe extern "C-unwind" fn CTFontCollectionCreateFromAvailableFonts(
528 options: Option<&CFDictionary>,
529) -> CFRetained<CTFontCollection> {
530 extern "C-unwind" {
531 fn CTFontCollectionCreateFromAvailableFonts(
532 options: Option<&CFDictionary>,
533 ) -> Option<NonNull<CTFontCollection>>;
534 }
535 let ret = unsafe { CTFontCollectionCreateFromAvailableFonts(options) };
536 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
537 unsafe { CFRetained::from_raw(ret) }
538}
539
540#[deprecated = "renamed to `CTFontCollection::with_font_descriptors`"]
541#[inline]
542pub unsafe extern "C-unwind" fn CTFontCollectionCreateWithFontDescriptors(
543 query_descriptors: Option<&CFArray>,
544 options: Option<&CFDictionary>,
545) -> CFRetained<CTFontCollection> {
546 extern "C-unwind" {
547 fn CTFontCollectionCreateWithFontDescriptors(
548 query_descriptors: Option<&CFArray>,
549 options: Option<&CFDictionary>,
550 ) -> Option<NonNull<CTFontCollection>>;
551 }
552 let ret = unsafe { CTFontCollectionCreateWithFontDescriptors(query_descriptors, options) };
553 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
554 unsafe { CFRetained::from_raw(ret) }
555}
556
557#[deprecated = "renamed to `CTFontCollection::copy_with_font_descriptors`"]
558#[inline]
559pub unsafe extern "C-unwind" fn CTFontCollectionCreateCopyWithFontDescriptors(
560 original: &CTFontCollection,
561 query_descriptors: Option<&CFArray>,
562 options: Option<&CFDictionary>,
563) -> CFRetained<CTFontCollection> {
564 extern "C-unwind" {
565 fn CTFontCollectionCreateCopyWithFontDescriptors(
566 original: &CTFontCollection,
567 query_descriptors: Option<&CFArray>,
568 options: Option<&CFDictionary>,
569 ) -> Option<NonNull<CTFontCollection>>;
570 }
571 let ret = unsafe {
572 CTFontCollectionCreateCopyWithFontDescriptors(original, query_descriptors, options)
573 };
574 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
575 unsafe { CFRetained::from_raw(ret) }
576}
577
578#[deprecated = "renamed to `CTMutableFontCollection::new_copy`"]
579#[inline]
580pub unsafe extern "C-unwind" fn CTFontCollectionCreateMutableCopy(
581 original: &CTFontCollection,
582) -> CFRetained<CTMutableFontCollection> {
583 extern "C-unwind" {
584 fn CTFontCollectionCreateMutableCopy(
585 original: &CTFontCollection,
586 ) -> Option<NonNull<CTMutableFontCollection>>;
587 }
588 let ret = unsafe { CTFontCollectionCreateMutableCopy(original) };
589 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
590 unsafe { CFRetained::from_raw(ret) }
591}
592
593#[deprecated = "renamed to `CTFontCollection::query_descriptors`"]
594#[inline]
595pub unsafe extern "C-unwind" fn CTFontCollectionCopyQueryDescriptors(
596 collection: &CTFontCollection,
597) -> Option<CFRetained<CFArray>> {
598 extern "C-unwind" {
599 fn CTFontCollectionCopyQueryDescriptors(
600 collection: &CTFontCollection,
601 ) -> Option<NonNull<CFArray>>;
602 }
603 let ret = unsafe { CTFontCollectionCopyQueryDescriptors(collection) };
604 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
605}
606
607extern "C-unwind" {
608 #[deprecated = "renamed to `CTMutableFontCollection::set_query_descriptors`"]
609 pub fn CTFontCollectionSetQueryDescriptors(
610 collection: &CTMutableFontCollection,
611 descriptors: Option<&CFArray>,
612 );
613}
614
615#[deprecated = "renamed to `CTFontCollection::exclusion_descriptors`"]
616#[inline]
617pub unsafe extern "C-unwind" fn CTFontCollectionCopyExclusionDescriptors(
618 collection: &CTFontCollection,
619) -> Option<CFRetained<CFArray>> {
620 extern "C-unwind" {
621 fn CTFontCollectionCopyExclusionDescriptors(
622 collection: &CTFontCollection,
623 ) -> Option<NonNull<CFArray>>;
624 }
625 let ret = unsafe { CTFontCollectionCopyExclusionDescriptors(collection) };
626 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
627}
628
629extern "C-unwind" {
630 #[deprecated = "renamed to `CTMutableFontCollection::set_exclusion_descriptors`"]
631 pub fn CTFontCollectionSetExclusionDescriptors(
632 collection: &CTMutableFontCollection,
633 descriptors: Option<&CFArray>,
634 );
635}
636
637#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors`"]
638#[inline]
639pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptors(
640 collection: &CTFontCollection,
641) -> Option<CFRetained<CFArray>> {
642 extern "C-unwind" {
643 fn CTFontCollectionCreateMatchingFontDescriptors(
644 collection: &CTFontCollection,
645 ) -> Option<NonNull<CFArray>>;
646 }
647 let ret = unsafe { CTFontCollectionCreateMatchingFontDescriptors(collection) };
648 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
649}
650
651#[cfg(feature = "CTFontDescriptor")]
652#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors_sorted_with_callback`"]
653#[inline]
654pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
655 collection: &CTFontCollection,
656 sort_callback: CTFontCollectionSortDescriptorsCallback,
657 ref_con: *mut c_void,
658) -> Option<CFRetained<CFArray>> {
659 extern "C-unwind" {
660 fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
661 collection: &CTFontCollection,
662 sort_callback: CTFontCollectionSortDescriptorsCallback,
663 ref_con: *mut c_void,
664 ) -> Option<NonNull<CFArray>>;
665 }
666 let ret = unsafe {
667 CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
668 collection,
669 sort_callback,
670 ref_con,
671 )
672 };
673 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
674}
675
676#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors_with_options`"]
677#[inline]
678pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
679 collection: &CTFontCollection,
680 options: Option<&CFDictionary>,
681) -> Option<CFRetained<CFArray>> {
682 extern "C-unwind" {
683 fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
684 collection: &CTFontCollection,
685 options: Option<&CFDictionary>,
686 ) -> Option<NonNull<CFArray>>;
687 }
688 let ret =
689 unsafe { CTFontCollectionCreateMatchingFontDescriptorsWithOptions(collection, options) };
690 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
691}
692
693#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors_for_family`"]
694#[inline]
695pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
696 collection: &CTFontCollection,
697 family_name: &CFString,
698 options: Option<&CFDictionary>,
699) -> Option<CFRetained<CFArray>> {
700 extern "C-unwind" {
701 fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
702 collection: &CTFontCollection,
703 family_name: &CFString,
704 options: Option<&CFDictionary>,
705 ) -> Option<NonNull<CFArray>>;
706 }
707 let ret = unsafe {
708 CTFontCollectionCreateMatchingFontDescriptorsForFamily(collection, family_name, options)
709 };
710 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
711}
712
713#[deprecated = "renamed to `CTFontCollection::font_attribute`"]
714#[inline]
715pub unsafe extern "C-unwind" fn CTFontCollectionCopyFontAttribute(
716 collection: &CTFontCollection,
717 attribute_name: &CFString,
718 options: CTFontCollectionCopyOptions,
719) -> CFRetained<CFArray> {
720 extern "C-unwind" {
721 fn CTFontCollectionCopyFontAttribute(
722 collection: &CTFontCollection,
723 attribute_name: &CFString,
724 options: CTFontCollectionCopyOptions,
725 ) -> Option<NonNull<CFArray>>;
726 }
727 let ret = unsafe { CTFontCollectionCopyFontAttribute(collection, attribute_name, options) };
728 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
729 unsafe { CFRetained::from_raw(ret) }
730}
731
732#[deprecated = "renamed to `CTFontCollection::font_attributes`"]
733#[inline]
734pub unsafe extern "C-unwind" fn CTFontCollectionCopyFontAttributes(
735 collection: &CTFontCollection,
736 attribute_names: &CFSet,
737 options: CTFontCollectionCopyOptions,
738) -> CFRetained<CFArray> {
739 extern "C-unwind" {
740 fn CTFontCollectionCopyFontAttributes(
741 collection: &CTFontCollection,
742 attribute_names: &CFSet,
743 options: CTFontCollectionCopyOptions,
744 ) -> Option<NonNull<CFArray>>;
745 }
746 let ret = unsafe { CTFontCollectionCopyFontAttributes(collection, attribute_names, options) };
747 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
748 unsafe { CFRetained::from_raw(ret) }
749}