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