objc2_core_text/generated/CTRunDelegate.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#[cfg(feature = "objc2-core-graphics")]
11use objc2_core_graphics::*;
12
13use crate::*;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrundelegate?language=objc)
16#[repr(C)]
17pub struct CTRunDelegate {
18 inner: [u8; 0],
19 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
20}
21
22cf_type!(
23 #[encoding_name = "__CTRunDelegate"]
24 unsafe impl CTRunDelegate {}
25);
26
27unsafe impl ConcreteType for CTRunDelegate {
28 /// Returns the CFType of CTRunDelegate objects.
29 #[doc(alias = "CTRunDelegateGetTypeID")]
30 #[inline]
31 fn type_id() -> CFTypeID {
32 extern "C-unwind" {
33 fn CTRunDelegateGetTypeID() -> CFTypeID;
34 }
35 unsafe { CTRunDelegateGetTypeID() }
36 }
37}
38
39/// The callback invoked when a CTRunDelegate is deallocated.
40///
41///
42/// Parameter `refCon`: The value supplied to CTRunDelegateCreate.
43///
44/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrundelegatedeallocatecallback?language=objc)
45pub type CTRunDelegateDeallocateCallback = Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>;
46
47/// The callback used to determine typographic ascent.
48///
49///
50/// Parameter `refCon`: The value supplied to CTRunDelegateCreate.
51///
52///
53/// Returns: A CGFloat value indicating the typographic ascent of glyphs to
54/// which a run delegate pertains.
55///
56/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrundelegategetascentcallback?language=objc)
57pub type CTRunDelegateGetAscentCallback =
58 Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> CGFloat>;
59
60/// The callback used to determine typographic descent.
61///
62///
63/// Parameter `refCon`: The value supplied to CTRunDelegateCreate.
64///
65///
66/// Returns: A CGFloat value indicating the typographic descent of glyphs to
67/// which a run delegate pertains.
68///
69/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrundelegategetdescentcallback?language=objc)
70pub type CTRunDelegateGetDescentCallback =
71 Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> CGFloat>;
72
73/// The callback used to determine width.
74///
75///
76/// Parameter `refCon`: The value supplied to CTRunDelegateCreate.
77///
78///
79/// Returns: A CGFloat value indicating the width of glyphs to which a run
80/// delegate pertains. A value of 0.0 indicates that the glyphs
81/// should not be drawn.
82///
83/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrundelegategetwidthcallback?language=objc)
84pub type CTRunDelegateGetWidthCallback =
85 Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> CGFloat>;
86
87/// Structure containing the callbacks of a CTRunDelegate.
88///
89///
90/// These callbacks are provided by the owner of a run delegate and
91/// are used to modify glyph metrics during layout. The values
92/// returned by a delegate are applied to each glyph in the run(s)
93/// corresponding to the attribute containing that delegate.
94///
95/// Field: version
96/// The version number of the callbacks being passed in as a
97/// parameter to CTRunDelegateCreate. This field should always
98/// be set to kCTRunDelegateCurrentVersion.
99///
100/// Field: dealloc
101/// The callback used when a CTRunDelegate's retain count reaches
102/// 0 and the CTRunDelegate is deallocated. This callback may be
103/// NULL.
104///
105/// Field: getAscent
106/// The callback used to indicate the ascent of the
107/// CTRunDelegate. This callback may be NULL, which is equivalent
108/// to a getAscent callback that always returns 0.
109///
110/// Field: getDescent
111/// The callback used to indicate the descent of the
112/// CTRunDelegate. This callback may be NULL, which is equivalent
113/// to a getDescent callback that always returns 0.
114///
115/// Field: getWidth
116/// The callback used to indicate the width of the
117/// CTRunDelegate. This callback may be NULL, which is equivalent
118/// to a getWidth callback that always returns 0.
119///
120/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrundelegatecallbacks?language=objc)
121#[repr(C)]
122#[derive(Clone, Copy, Debug, PartialEq)]
123pub struct CTRunDelegateCallbacks {
124 pub version: CFIndex,
125 pub dealloc: CTRunDelegateDeallocateCallback,
126 pub getAscent: CTRunDelegateGetAscentCallback,
127 pub getDescent: CTRunDelegateGetDescentCallback,
128 pub getWidth: CTRunDelegateGetWidthCallback,
129}
130
131#[cfg(feature = "objc2")]
132unsafe impl Encode for CTRunDelegateCallbacks {
133 const ENCODING: Encoding = Encoding::Struct(
134 "?",
135 &[
136 <CFIndex>::ENCODING,
137 <CTRunDelegateDeallocateCallback>::ENCODING,
138 <CTRunDelegateGetAscentCallback>::ENCODING,
139 <CTRunDelegateGetDescentCallback>::ENCODING,
140 <CTRunDelegateGetWidthCallback>::ENCODING,
141 ],
142 );
143}
144
145#[cfg(feature = "objc2")]
146unsafe impl RefEncode for CTRunDelegateCallbacks {
147 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
148}
149
150/// [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrundelegateversion1?language=objc)
151pub const kCTRunDelegateVersion1: c_uint = 1;
152/// [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrundelegatecurrentversion?language=objc)
153pub const kCTRunDelegateCurrentVersion: c_uint = kCTRunDelegateVersion1;
154
155/// Creates an immutable instance of a run delegate.
156///
157///
158/// This function creates an immutable instance of a run delegate
159/// that can be used for reserving space in a line or for eliding the
160/// glyphs for a range of text altogether.
161///
162///
163/// Parameter `callbacks`: The callbacks for this run delegate.
164///
165///
166/// Returns: If run delegate creation was successful, this function will
167/// return a valid reference to an immutable CTRunDelegate
168/// object. Otherwise, this function will return NULL.
169#[inline]
170pub unsafe extern "C-unwind" fn CTRunDelegateCreate(
171 callbacks: NonNull<CTRunDelegateCallbacks>,
172 ref_con: *mut c_void,
173) -> Option<CFRetained<CTRunDelegate>> {
174 extern "C-unwind" {
175 fn CTRunDelegateCreate(
176 callbacks: NonNull<CTRunDelegateCallbacks>,
177 ref_con: *mut c_void,
178 ) -> Option<NonNull<CTRunDelegate>>;
179 }
180 let ret = unsafe { CTRunDelegateCreate(callbacks, ref_con) };
181 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
182}
183
184/// Returns a run delegate's refCon value.
185///
186///
187/// This function returns the refCon value that a run delegate was
188/// created with.
189///
190///
191/// Parameter `runDelegate`: The run delegate to be queried.
192///
193///
194/// Returns: The refCon value of the supplied run delegate.
195#[inline]
196pub unsafe extern "C-unwind" fn CTRunDelegateGetRefCon(
197 run_delegate: &CTRunDelegate,
198) -> NonNull<c_void> {
199 extern "C-unwind" {
200 fn CTRunDelegateGetRefCon(run_delegate: &CTRunDelegate) -> Option<NonNull<c_void>>;
201 }
202 let ret = unsafe { CTRunDelegateGetRefCon(run_delegate) };
203 ret.expect("function was marked as returning non-null, but actually returned NULL")
204}
205
206#[cfg(feature = "objc2")]
207extern_protocol!(
208 /// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctadaptiveimageproviding?language=objc)
209 #[cfg(feature = "objc2")]
210 pub unsafe trait CTAdaptiveImageProviding {
211 #[cfg(feature = "objc2-core-graphics")]
212 #[unsafe(method(imageForProposedSize:scaleFactor:imageOffset:imageSize:))]
213 #[unsafe(method_family = none)]
214 unsafe fn imageForProposedSize_scaleFactor_imageOffset_imageSize(
215 &self,
216 proposed_size: CGSize,
217 scale_factor: CGFloat,
218 out_image_offset: NonNull<CGPoint>,
219 out_image_size: NonNull<CGSize>,
220 ) -> Option<Retained<CGImage>>;
221 }
222);