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#[doc(alias = "CTFontCollectionRef")]
17#[repr(C)]
18pub struct CTFontCollection {
19 inner: [u8; 0],
20 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
21}
22
23cf_type!(
24 unsafe impl CTFontCollection {}
25);
26#[cfg(feature = "objc2")]
27cf_objc2_type!(
28 unsafe impl RefEncode<"__CTFontCollection"> for CTFontCollection {}
29);
30
31#[doc(alias = "CTMutableFontCollectionRef")]
35#[repr(C)]
36pub struct CTMutableFontCollection {
37 inner: [u8; 0],
38 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
39}
40
41cf_type!(
42 unsafe impl CTMutableFontCollection: CTFontCollection {}
43);
44#[cfg(feature = "objc2")]
45cf_objc2_type!(
46 unsafe impl RefEncode<"__CTFontCollection"> for CTMutableFontCollection {}
47);
48
49unsafe impl ConcreteType for CTFontCollection {
50 #[doc(alias = "CTFontCollectionGetTypeID")]
54 #[inline]
55 fn type_id() -> CFTypeID {
56 extern "C-unwind" {
57 fn CTFontCollectionGetTypeID() -> CFTypeID;
58 }
59 unsafe { CTFontCollectionGetTypeID() }
60 }
61}
62
63#[cfg(feature = "CTFontDescriptor")]
69pub type CTFontCollectionSortDescriptorsCallback = Option<
70 unsafe extern "C-unwind" fn(
71 NonNull<CTFontDescriptor>,
72 NonNull<CTFontDescriptor>,
73 NonNull<c_void>,
74 ) -> CFComparisonResult,
75>;
76
77extern "C" {
78 pub static kCTFontCollectionRemoveDuplicatesOption: &'static CFString;
86}
87
88extern "C" {
89 pub static kCTFontCollectionIncludeDisabledFontsOption: &'static CFString;
97}
98
99extern "C" {
100 pub static kCTFontCollectionDisallowAutoActivationOption: &'static CFString;
108}
109
110impl CTFontCollection {
111 #[doc(alias = "CTFontCollectionCreateFromAvailableFonts")]
123 #[inline]
124 pub unsafe fn from_available_fonts(
125 options: Option<&CFDictionary>,
126 ) -> CFRetained<CTFontCollection> {
127 extern "C-unwind" {
128 fn CTFontCollectionCreateFromAvailableFonts(
129 options: Option<&CFDictionary>,
130 ) -> Option<NonNull<CTFontCollection>>;
131 }
132 let ret = unsafe { CTFontCollectionCreateFromAvailableFonts(options) };
133 let ret =
134 ret.expect("function was marked as returning non-null, but actually returned NULL");
135 unsafe { CFRetained::from_raw(ret) }
136 }
137
138 #[doc(alias = "CTFontCollectionCreateWithFontDescriptors")]
154 #[inline]
155 pub unsafe fn with_font_descriptors(
156 query_descriptors: Option<&CFArray>,
157 options: Option<&CFDictionary>,
158 ) -> CFRetained<CTFontCollection> {
159 extern "C-unwind" {
160 fn CTFontCollectionCreateWithFontDescriptors(
161 query_descriptors: Option<&CFArray>,
162 options: Option<&CFDictionary>,
163 ) -> Option<NonNull<CTFontCollection>>;
164 }
165 let ret = unsafe { CTFontCollectionCreateWithFontDescriptors(query_descriptors, options) };
166 let ret =
167 ret.expect("function was marked as returning non-null, but actually returned NULL");
168 unsafe { CFRetained::from_raw(ret) }
169 }
170
171 #[doc(alias = "CTFontCollectionCreateCopyWithFontDescriptors")]
190 #[inline]
191 pub unsafe fn copy_with_font_descriptors(
192 &self,
193 query_descriptors: Option<&CFArray>,
194 options: Option<&CFDictionary>,
195 ) -> CFRetained<CTFontCollection> {
196 extern "C-unwind" {
197 fn CTFontCollectionCreateCopyWithFontDescriptors(
198 original: &CTFontCollection,
199 query_descriptors: Option<&CFArray>,
200 options: Option<&CFDictionary>,
201 ) -> Option<NonNull<CTFontCollection>>;
202 }
203 let ret = unsafe {
204 CTFontCollectionCreateCopyWithFontDescriptors(self, query_descriptors, options)
205 };
206 let ret =
207 ret.expect("function was marked as returning non-null, but actually returned NULL");
208 unsafe { CFRetained::from_raw(ret) }
209 }
210}
211
212impl CTMutableFontCollection {
213 #[doc(alias = "CTFontCollectionCreateMutableCopy")]
221 #[inline]
222 pub unsafe fn new_copy(original: &CTFontCollection) -> CFRetained<CTMutableFontCollection> {
223 extern "C-unwind" {
224 fn CTFontCollectionCreateMutableCopy(
225 original: &CTFontCollection,
226 ) -> Option<NonNull<CTMutableFontCollection>>;
227 }
228 let ret = unsafe { CTFontCollectionCreateMutableCopy(original) };
229 let ret =
230 ret.expect("function was marked as returning non-null, but actually returned NULL");
231 unsafe { CFRetained::from_raw(ret) }
232 }
233}
234
235impl CTFontCollection {
236 #[doc(alias = "CTFontCollectionCopyQueryDescriptors")]
244 #[inline]
245 pub unsafe fn query_descriptors(&self) -> Option<CFRetained<CFArray>> {
246 extern "C-unwind" {
247 fn CTFontCollectionCopyQueryDescriptors(
248 collection: &CTFontCollection,
249 ) -> Option<NonNull<CFArray>>;
250 }
251 let ret = unsafe { CTFontCollectionCopyQueryDescriptors(self) };
252 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
253 }
254}
255
256impl CTMutableFontCollection {
257 #[doc(alias = "CTFontCollectionSetQueryDescriptors")]
269 #[inline]
270 pub unsafe fn set_query_descriptors(&self, descriptors: Option<&CFArray>) {
271 extern "C-unwind" {
272 fn CTFontCollectionSetQueryDescriptors(
273 collection: &CTMutableFontCollection,
274 descriptors: Option<&CFArray>,
275 );
276 }
277 unsafe { CTFontCollectionSetQueryDescriptors(self, descriptors) }
278 }
279}
280
281impl CTFontCollection {
282 #[doc(alias = "CTFontCollectionCopyExclusionDescriptors")]
290 #[inline]
291 pub unsafe fn exclusion_descriptors(&self) -> Option<CFRetained<CFArray>> {
292 extern "C-unwind" {
293 fn CTFontCollectionCopyExclusionDescriptors(
294 collection: &CTFontCollection,
295 ) -> Option<NonNull<CFArray>>;
296 }
297 let ret = unsafe { CTFontCollectionCopyExclusionDescriptors(self) };
298 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
299 }
300}
301
302impl CTMutableFontCollection {
303 #[doc(alias = "CTFontCollectionSetExclusionDescriptors")]
315 #[inline]
316 pub unsafe fn set_exclusion_descriptors(&self, descriptors: Option<&CFArray>) {
317 extern "C-unwind" {
318 fn CTFontCollectionSetExclusionDescriptors(
319 collection: &CTMutableFontCollection,
320 descriptors: Option<&CFArray>,
321 );
322 }
323 unsafe { CTFontCollectionSetExclusionDescriptors(self, descriptors) }
324 }
325}
326
327impl CTFontCollection {
328 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptors")]
336 #[inline]
337 pub unsafe fn matching_font_descriptors(&self) -> Option<CFRetained<CFArray>> {
338 extern "C-unwind" {
339 fn CTFontCollectionCreateMatchingFontDescriptors(
340 collection: &CTFontCollection,
341 ) -> Option<NonNull<CFArray>>;
342 }
343 let ret = unsafe { CTFontCollectionCreateMatchingFontDescriptors(self) };
344 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
345 }
346
347 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback")]
366 #[cfg(feature = "CTFontDescriptor")]
367 #[inline]
368 pub unsafe fn matching_font_descriptors_sorted_with_callback(
369 &self,
370 sort_callback: CTFontCollectionSortDescriptorsCallback,
371 ref_con: *mut c_void,
372 ) -> Option<CFRetained<CFArray>> {
373 extern "C-unwind" {
374 fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
375 collection: &CTFontCollection,
376 sort_callback: CTFontCollectionSortDescriptorsCallback,
377 ref_con: *mut c_void,
378 ) -> Option<NonNull<CFArray>>;
379 }
380 let ret = unsafe {
381 CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
382 self,
383 sort_callback,
384 ref_con,
385 )
386 };
387 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
388 }
389
390 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptorsWithOptions")]
405 #[inline]
406 pub unsafe fn matching_font_descriptors_with_options(
407 &self,
408 options: Option<&CFDictionary>,
409 ) -> Option<CFRetained<CFArray>> {
410 extern "C-unwind" {
411 fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
412 collection: &CTFontCollection,
413 options: Option<&CFDictionary>,
414 ) -> Option<NonNull<CFArray>>;
415 }
416 let ret =
417 unsafe { CTFontCollectionCreateMatchingFontDescriptorsWithOptions(self, options) };
418 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
419 }
420
421 #[doc(alias = "CTFontCollectionCreateMatchingFontDescriptorsForFamily")]
436 #[inline]
437 pub unsafe fn matching_font_descriptors_for_family(
438 &self,
439 family_name: &CFString,
440 options: Option<&CFDictionary>,
441 ) -> Option<CFRetained<CFArray>> {
442 extern "C-unwind" {
443 fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
444 collection: &CTFontCollection,
445 family_name: &CFString,
446 options: Option<&CFDictionary>,
447 ) -> Option<NonNull<CFArray>>;
448 }
449 let ret = unsafe {
450 CTFontCollectionCreateMatchingFontDescriptorsForFamily(self, family_name, options)
451 };
452 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
453 }
454}
455
456#[repr(transparent)]
467#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
468pub struct CTFontCollectionCopyOptions(pub u32);
469bitflags::bitflags! {
470 impl CTFontCollectionCopyOptions: u32 {
471 #[doc(alias = "kCTFontCollectionCopyDefaultOptions")]
472 const DefaultOptions = 0;
473 #[doc(alias = "kCTFontCollectionCopyUnique")]
474 const Unique = 1<<0;
475 #[doc(alias = "kCTFontCollectionCopyStandardSort")]
476 const StandardSort = 1<<1;
477 }
478}
479
480#[cfg(feature = "objc2")]
481unsafe impl Encode for CTFontCollectionCopyOptions {
482 const ENCODING: Encoding = u32::ENCODING;
483}
484
485#[cfg(feature = "objc2")]
486unsafe impl RefEncode for CTFontCollectionCopyOptions {
487 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
488}
489
490impl CTFontCollection {
491 #[doc(alias = "CTFontCollectionCopyFontAttribute")]
505 #[inline]
506 pub unsafe fn font_attribute(
507 &self,
508 attribute_name: &CFString,
509 options: CTFontCollectionCopyOptions,
510 ) -> CFRetained<CFArray> {
511 extern "C-unwind" {
512 fn CTFontCollectionCopyFontAttribute(
513 collection: &CTFontCollection,
514 attribute_name: &CFString,
515 options: CTFontCollectionCopyOptions,
516 ) -> Option<NonNull<CFArray>>;
517 }
518 let ret = unsafe { CTFontCollectionCopyFontAttribute(self, attribute_name, 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 #[doc(alias = "CTFontCollectionCopyFontAttributes")]
542 #[inline]
543 pub unsafe fn font_attributes(
544 &self,
545 attribute_names: &CFSet,
546 options: CTFontCollectionCopyOptions,
547 ) -> CFRetained<CFArray> {
548 extern "C-unwind" {
549 fn CTFontCollectionCopyFontAttributes(
550 collection: &CTFontCollection,
551 attribute_names: &CFSet,
552 options: CTFontCollectionCopyOptions,
553 ) -> Option<NonNull<CFArray>>;
554 }
555 let ret = unsafe { CTFontCollectionCopyFontAttributes(self, attribute_names, options) };
556 let ret =
557 ret.expect("function was marked as returning non-null, but actually returned NULL");
558 unsafe { CFRetained::from_raw(ret) }
559 }
560}
561
562#[deprecated = "renamed to `CTFontCollection::from_available_fonts`"]
563#[inline]
564pub unsafe extern "C-unwind" fn CTFontCollectionCreateFromAvailableFonts(
565 options: Option<&CFDictionary>,
566) -> CFRetained<CTFontCollection> {
567 extern "C-unwind" {
568 fn CTFontCollectionCreateFromAvailableFonts(
569 options: Option<&CFDictionary>,
570 ) -> Option<NonNull<CTFontCollection>>;
571 }
572 let ret = unsafe { CTFontCollectionCreateFromAvailableFonts(options) };
573 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
574 unsafe { CFRetained::from_raw(ret) }
575}
576
577#[deprecated = "renamed to `CTFontCollection::with_font_descriptors`"]
578#[inline]
579pub unsafe extern "C-unwind" fn CTFontCollectionCreateWithFontDescriptors(
580 query_descriptors: Option<&CFArray>,
581 options: Option<&CFDictionary>,
582) -> CFRetained<CTFontCollection> {
583 extern "C-unwind" {
584 fn CTFontCollectionCreateWithFontDescriptors(
585 query_descriptors: Option<&CFArray>,
586 options: Option<&CFDictionary>,
587 ) -> Option<NonNull<CTFontCollection>>;
588 }
589 let ret = unsafe { CTFontCollectionCreateWithFontDescriptors(query_descriptors, options) };
590 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
591 unsafe { CFRetained::from_raw(ret) }
592}
593
594#[deprecated = "renamed to `CTFontCollection::copy_with_font_descriptors`"]
595#[inline]
596pub unsafe extern "C-unwind" fn CTFontCollectionCreateCopyWithFontDescriptors(
597 original: &CTFontCollection,
598 query_descriptors: Option<&CFArray>,
599 options: Option<&CFDictionary>,
600) -> CFRetained<CTFontCollection> {
601 extern "C-unwind" {
602 fn CTFontCollectionCreateCopyWithFontDescriptors(
603 original: &CTFontCollection,
604 query_descriptors: Option<&CFArray>,
605 options: Option<&CFDictionary>,
606 ) -> Option<NonNull<CTFontCollection>>;
607 }
608 let ret = unsafe {
609 CTFontCollectionCreateCopyWithFontDescriptors(original, query_descriptors, options)
610 };
611 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
612 unsafe { CFRetained::from_raw(ret) }
613}
614
615#[deprecated = "renamed to `CTMutableFontCollection::new_copy`"]
616#[inline]
617pub unsafe extern "C-unwind" fn CTFontCollectionCreateMutableCopy(
618 original: &CTFontCollection,
619) -> CFRetained<CTMutableFontCollection> {
620 extern "C-unwind" {
621 fn CTFontCollectionCreateMutableCopy(
622 original: &CTFontCollection,
623 ) -> Option<NonNull<CTMutableFontCollection>>;
624 }
625 let ret = unsafe { CTFontCollectionCreateMutableCopy(original) };
626 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
627 unsafe { CFRetained::from_raw(ret) }
628}
629
630#[deprecated = "renamed to `CTFontCollection::query_descriptors`"]
631#[inline]
632pub unsafe extern "C-unwind" fn CTFontCollectionCopyQueryDescriptors(
633 collection: &CTFontCollection,
634) -> Option<CFRetained<CFArray>> {
635 extern "C-unwind" {
636 fn CTFontCollectionCopyQueryDescriptors(
637 collection: &CTFontCollection,
638 ) -> Option<NonNull<CFArray>>;
639 }
640 let ret = unsafe { CTFontCollectionCopyQueryDescriptors(collection) };
641 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
642}
643
644extern "C-unwind" {
645 #[deprecated = "renamed to `CTMutableFontCollection::set_query_descriptors`"]
646 pub fn CTFontCollectionSetQueryDescriptors(
647 collection: &CTMutableFontCollection,
648 descriptors: Option<&CFArray>,
649 );
650}
651
652#[deprecated = "renamed to `CTFontCollection::exclusion_descriptors`"]
653#[inline]
654pub unsafe extern "C-unwind" fn CTFontCollectionCopyExclusionDescriptors(
655 collection: &CTFontCollection,
656) -> Option<CFRetained<CFArray>> {
657 extern "C-unwind" {
658 fn CTFontCollectionCopyExclusionDescriptors(
659 collection: &CTFontCollection,
660 ) -> Option<NonNull<CFArray>>;
661 }
662 let ret = unsafe { CTFontCollectionCopyExclusionDescriptors(collection) };
663 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
664}
665
666extern "C-unwind" {
667 #[deprecated = "renamed to `CTMutableFontCollection::set_exclusion_descriptors`"]
668 pub fn CTFontCollectionSetExclusionDescriptors(
669 collection: &CTMutableFontCollection,
670 descriptors: Option<&CFArray>,
671 );
672}
673
674#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors`"]
675#[inline]
676pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptors(
677 collection: &CTFontCollection,
678) -> Option<CFRetained<CFArray>> {
679 extern "C-unwind" {
680 fn CTFontCollectionCreateMatchingFontDescriptors(
681 collection: &CTFontCollection,
682 ) -> Option<NonNull<CFArray>>;
683 }
684 let ret = unsafe { CTFontCollectionCreateMatchingFontDescriptors(collection) };
685 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
686}
687
688#[cfg(feature = "CTFontDescriptor")]
689#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors_sorted_with_callback`"]
690#[inline]
691pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
692 collection: &CTFontCollection,
693 sort_callback: CTFontCollectionSortDescriptorsCallback,
694 ref_con: *mut c_void,
695) -> Option<CFRetained<CFArray>> {
696 extern "C-unwind" {
697 fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
698 collection: &CTFontCollection,
699 sort_callback: CTFontCollectionSortDescriptorsCallback,
700 ref_con: *mut c_void,
701 ) -> Option<NonNull<CFArray>>;
702 }
703 let ret = unsafe {
704 CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
705 collection,
706 sort_callback,
707 ref_con,
708 )
709 };
710 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
711}
712
713#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors_with_options`"]
714#[inline]
715pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
716 collection: &CTFontCollection,
717 options: Option<&CFDictionary>,
718) -> Option<CFRetained<CFArray>> {
719 extern "C-unwind" {
720 fn CTFontCollectionCreateMatchingFontDescriptorsWithOptions(
721 collection: &CTFontCollection,
722 options: Option<&CFDictionary>,
723 ) -> Option<NonNull<CFArray>>;
724 }
725 let ret =
726 unsafe { CTFontCollectionCreateMatchingFontDescriptorsWithOptions(collection, options) };
727 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
728}
729
730#[deprecated = "renamed to `CTFontCollection::matching_font_descriptors_for_family`"]
731#[inline]
732pub unsafe extern "C-unwind" fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
733 collection: &CTFontCollection,
734 family_name: &CFString,
735 options: Option<&CFDictionary>,
736) -> Option<CFRetained<CFArray>> {
737 extern "C-unwind" {
738 fn CTFontCollectionCreateMatchingFontDescriptorsForFamily(
739 collection: &CTFontCollection,
740 family_name: &CFString,
741 options: Option<&CFDictionary>,
742 ) -> Option<NonNull<CFArray>>;
743 }
744 let ret = unsafe {
745 CTFontCollectionCreateMatchingFontDescriptorsForFamily(collection, family_name, options)
746 };
747 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
748}
749
750#[deprecated = "renamed to `CTFontCollection::font_attribute`"]
751#[inline]
752pub unsafe extern "C-unwind" fn CTFontCollectionCopyFontAttribute(
753 collection: &CTFontCollection,
754 attribute_name: &CFString,
755 options: CTFontCollectionCopyOptions,
756) -> CFRetained<CFArray> {
757 extern "C-unwind" {
758 fn CTFontCollectionCopyFontAttribute(
759 collection: &CTFontCollection,
760 attribute_name: &CFString,
761 options: CTFontCollectionCopyOptions,
762 ) -> Option<NonNull<CFArray>>;
763 }
764 let ret = unsafe { CTFontCollectionCopyFontAttribute(collection, attribute_name, options) };
765 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
766 unsafe { CFRetained::from_raw(ret) }
767}
768
769#[deprecated = "renamed to `CTFontCollection::font_attributes`"]
770#[inline]
771pub unsafe extern "C-unwind" fn CTFontCollectionCopyFontAttributes(
772 collection: &CTFontCollection,
773 attribute_names: &CFSet,
774 options: CTFontCollectionCopyOptions,
775) -> CFRetained<CFArray> {
776 extern "C-unwind" {
777 fn CTFontCollectionCopyFontAttributes(
778 collection: &CTFontCollection,
779 attribute_names: &CFSet,
780 options: CTFontCollectionCopyOptions,
781 ) -> Option<NonNull<CFArray>>;
782 }
783 let ret = unsafe { CTFontCollectionCopyFontAttributes(collection, attribute_names, options) };
784 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
785 unsafe { CFRetained::from_raw(ret) }
786}