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