objc2_core_text/generated/
CTRubyAnnotation.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::marker::{PhantomData, PhantomPinned};
5use core::ptr::NonNull;
6#[cfg(feature = "objc2")]
7use objc2::__framework_prelude::*;
8use objc2_core_foundation::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyannotation?language=objc)
13#[doc(alias = "CTRubyAnnotationRef")]
14#[repr(C)]
15pub struct CTRubyAnnotation {
16    inner: [u8; 0],
17    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
18}
19
20cf_type!(
21    unsafe impl CTRubyAnnotation {}
22);
23#[cfg(feature = "objc2")]
24cf_objc2_type!(
25    unsafe impl RefEncode<"__CTRubyAnnotation"> for CTRubyAnnotation {}
26);
27
28unsafe impl ConcreteType for CTRubyAnnotation {
29    /// Returns the CFType of the ruby annotation object
30    #[doc(alias = "CTRubyAnnotationGetTypeID")]
31    #[inline]
32    fn type_id() -> CFTypeID {
33        extern "C-unwind" {
34            fn CTRubyAnnotationGetTypeID() -> CFTypeID;
35        }
36        unsafe { CTRubyAnnotationGetTypeID() }
37    }
38}
39
40/// These constants specify how to align the ruby annotation and the base text relative to each other when they don't have the same length.
41///
42///
43/// CoreText will determine the alignment.
44///
45///
46/// The ruby text is aligned with the start edge of the base text.
47///
48///
49/// The ruby text is centered within the width of the base text. If the ruby text is wider than the base text the base text is centered in the width of the ruby text.
50///
51///
52/// The ruby text is aligned with the end edge of the base text.
53///
54///
55/// If the width of the ruby text is less than the width of the base text, the ruby text is evenly distributed over the width of the base text, with the first letter of the ruby text aligning with the first letter of the base text and the last letter of the ruby text aligning with the last letter of the base text. If the width of the base text is less than the width of the ruby text, the base text is evenly distributed over the width of the ruby text.
56///
57///
58/// If the width of the ruby text is less than the width of the base text, the ruby text is evenly distributed over the width of the base text, with a certain amount of space, usually half the inter-character width of the ruby text, before the first and after the last character. If the width of the base text is less than the width of the ruby text, the base text is similarly aligned to the width of the ruby text.
59///
60///
61/// If the ruby text is not adjacent to a line edge it is aligned as with kCTRubyAlignmentAuto. If it is adjacent to a line edge the end of ruby text adjacent to the line edge is aligned to the line edge. This is only relevant if the width of the ruby text is greater than the width of the base text; otherwise alignment is as with kCTRubyAlignmentAuto.
62///
63/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyalignment?language=objc)
64// NS_ENUM
65#[repr(transparent)]
66#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
67pub struct CTRubyAlignment(pub u8);
68impl CTRubyAlignment {
69    #[doc(alias = "kCTRubyAlignmentInvalid")]
70    pub const Invalid: Self = Self(255);
71    #[doc(alias = "kCTRubyAlignmentAuto")]
72    pub const Auto: Self = Self(0);
73    #[doc(alias = "kCTRubyAlignmentStart")]
74    pub const Start: Self = Self(1);
75    #[doc(alias = "kCTRubyAlignmentCenter")]
76    pub const Center: Self = Self(2);
77    #[doc(alias = "kCTRubyAlignmentEnd")]
78    pub const End: Self = Self(3);
79    #[doc(alias = "kCTRubyAlignmentDistributeLetter")]
80    pub const DistributeLetter: Self = Self(4);
81    #[doc(alias = "kCTRubyAlignmentDistributeSpace")]
82    pub const DistributeSpace: Self = Self(5);
83    #[doc(alias = "kCTRubyAlignmentLineEdge")]
84    pub const LineEdge: Self = Self(6);
85}
86
87#[cfg(feature = "objc2")]
88unsafe impl Encode for CTRubyAlignment {
89    const ENCODING: Encoding = u8::ENCODING;
90}
91
92#[cfg(feature = "objc2")]
93unsafe impl RefEncode for CTRubyAlignment {
94    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
95}
96
97/// These constants specify whether, and on which side, ruby text is allowed to overhang adjacent text if it is wider than the base text.
98///
99///
100/// The ruby text can overhang adjacent text on both sides.
101///
102///
103/// The ruby text can overhang the text that proceeds it.
104///
105///
106/// The ruby text can overhang the text that follows it.
107///
108///
109/// The ruby text cannot overhang the proceeding or following text.
110///
111/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyoverhang?language=objc)
112// NS_ENUM
113#[repr(transparent)]
114#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
115pub struct CTRubyOverhang(pub u8);
116impl CTRubyOverhang {
117    #[doc(alias = "kCTRubyOverhangInvalid")]
118    pub const Invalid: Self = Self(255);
119    #[doc(alias = "kCTRubyOverhangAuto")]
120    pub const Auto: Self = Self(0);
121    #[doc(alias = "kCTRubyOverhangStart")]
122    pub const Start: Self = Self(1);
123    #[doc(alias = "kCTRubyOverhangEnd")]
124    pub const End: Self = Self(2);
125    #[doc(alias = "kCTRubyOverhangNone")]
126    pub const None: Self = Self(3);
127}
128
129#[cfg(feature = "objc2")]
130unsafe impl Encode for CTRubyOverhang {
131    const ENCODING: Encoding = u8::ENCODING;
132}
133
134#[cfg(feature = "objc2")]
135unsafe impl RefEncode for CTRubyOverhang {
136    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
137}
138
139/// These constants specify the position of the ruby text with respect to the base text.
140///
141///
142/// The ruby text is positioned before the base text; i.e. above horizontal text and to the right of vertical text.
143///
144///
145/// The ruby text is positioned after the base text; i.e. below horizontal text and to the left of vertical text.
146///
147///
148/// The ruby text is positioned to the right of the base text whether it is horizontal or vertical. This is the way that Bopomofo annotations are attached to Chinese text in Taiwan.
149///
150///
151/// The ruby text follows the base text with no special styling.
152///
153/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyposition?language=objc)
154// NS_ENUM
155#[repr(transparent)]
156#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
157pub struct CTRubyPosition(pub u8);
158impl CTRubyPosition {
159    #[doc(alias = "kCTRubyPositionBefore")]
160    pub const Before: Self = Self(0);
161    #[doc(alias = "kCTRubyPositionAfter")]
162    pub const After: Self = Self(1);
163    #[doc(alias = "kCTRubyPositionInterCharacter")]
164    pub const InterCharacter: Self = Self(2);
165    #[doc(alias = "kCTRubyPositionInline")]
166    pub const Inline: Self = Self(3);
167    #[doc(alias = "kCTRubyPositionCount")]
168    pub const Count: Self = Self(4);
169}
170
171#[cfg(feature = "objc2")]
172unsafe impl Encode for CTRubyPosition {
173    const ENCODING: Encoding = u8::ENCODING;
174}
175
176#[cfg(feature = "objc2")]
177unsafe impl RefEncode for CTRubyPosition {
178    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
179}
180
181extern "C" {
182    /// Specifies the size of the annotation text as a percent of the size of the base text.
183    ///
184    ///
185    /// Value must be a CFNumberRef.
186    ///
187    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrubyannotationsizefactorattributename?language=objc)
188    pub static kCTRubyAnnotationSizeFactorAttributeName: &'static CFString;
189}
190
191extern "C" {
192    /// Treat the size specified in kCTRubyAnnotationSizeFactorAttributeName as the maximum
193    /// scale factor, when the base text size is smaller than annotation text size, we will
194    /// try to scale the annotation font size down so that it will fit the base text without
195    /// overhang or adding extra padding between base text.
196    ///
197    ///
198    /// Value must be a CFBooleanRef. Default is false.
199    ///
200    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrubyannotationscaletofitattributename?language=objc)
201    pub static kCTRubyAnnotationScaleToFitAttributeName: &'static CFString;
202}
203
204impl CTRubyAnnotation {
205    /// Creates an immutable ruby annotation object.
206    ///
207    ///
208    /// Using this function to create a ruby annotation object with more precise
209    /// control of the annotation text.
210    ///
211    ///
212    /// Parameter `alignment`: Specifies how the ruby text and the base text should be aligned relative to each other.
213    ///
214    ///
215    /// Parameter `overhang`: Specifies how the ruby text can overhang adjacent characters.
216    ///
217    ///
218    /// Parameter `position`: The position of the annotation text.
219    ///
220    ///
221    /// Parameter `string`: A string without any formatting, its format will be derived from the attrs specified below.
222    ///
223    ///
224    /// Parameter `attributes`: A attribute dictionary to combine with the string specified above. If you don't specify
225    /// kCTFontAttributeName, the font used by the Ruby annotation will be deduced from the base
226    /// text, with a size factor specified by a CFNumberRef value keyed by
227    /// kCTRubyAnnotationSizeFactorAttributeName.
228    ///
229    ///
230    /// Returns: This function will return a reference to a CTRubyAnnotation object.
231    ///
232    /// # Safety
233    ///
234    /// `attributes` generics must be of the correct type.
235    #[doc(alias = "CTRubyAnnotationCreateWithAttributes")]
236    #[inline]
237    pub unsafe fn with_attributes(
238        alignment: CTRubyAlignment,
239        overhang: CTRubyOverhang,
240        position: CTRubyPosition,
241        string: &CFString,
242        attributes: &CFDictionary,
243    ) -> CFRetained<CTRubyAnnotation> {
244        extern "C-unwind" {
245            fn CTRubyAnnotationCreateWithAttributes(
246                alignment: CTRubyAlignment,
247                overhang: CTRubyOverhang,
248                position: CTRubyPosition,
249                string: &CFString,
250                attributes: &CFDictionary,
251            ) -> Option<NonNull<CTRubyAnnotation>>;
252        }
253        let ret = unsafe {
254            CTRubyAnnotationCreateWithAttributes(alignment, overhang, position, string, attributes)
255        };
256        let ret =
257            ret.expect("function was marked as returning non-null, but actually returned NULL");
258        unsafe { CFRetained::from_raw(ret) }
259    }
260
261    /// Creates an immutable copy of a ruby annotation object.
262    ///
263    ///
264    /// Parameter `rubyAnnotation`: The ruby annotation that you wish to copy.
265    ///
266    ///
267    /// Returns: If the "rubyAnnotation" reference is valid, then this
268    /// function will return valid reference to an immutable
269    /// CTRubyAnnotation object that is a copy of the one passed into
270    /// "rubyAnnotation".
271    #[doc(alias = "CTRubyAnnotationCreateCopy")]
272    #[inline]
273    pub unsafe fn copy(&self) -> CFRetained<CTRubyAnnotation> {
274        extern "C-unwind" {
275            fn CTRubyAnnotationCreateCopy(
276                ruby_annotation: &CTRubyAnnotation,
277            ) -> Option<NonNull<CTRubyAnnotation>>;
278        }
279        let ret = unsafe { CTRubyAnnotationCreateCopy(self) };
280        let ret =
281            ret.expect("function was marked as returning non-null, but actually returned NULL");
282        unsafe { CFRetained::from_raw(ret) }
283    }
284
285    /// Get the alignment value of a ruby annotation object.
286    ///
287    ///
288    /// Parameter `rubyAnnotation`: The ruby annotation object.
289    ///
290    ///
291    /// Returns: If the "rubyAnnotation" reference is valid, then this
292    /// function will return its alignment. Otherwise it will return kCTRubyAlignmentInvalid.
293    #[doc(alias = "CTRubyAnnotationGetAlignment")]
294    #[inline]
295    pub unsafe fn alignment(&self) -> CTRubyAlignment {
296        extern "C-unwind" {
297            fn CTRubyAnnotationGetAlignment(ruby_annotation: &CTRubyAnnotation) -> CTRubyAlignment;
298        }
299        unsafe { CTRubyAnnotationGetAlignment(self) }
300    }
301
302    /// Get the overhang value of a ruby annotation object.
303    ///
304    ///
305    /// Parameter `rubyAnnotation`: The ruby annotation object.
306    ///
307    ///
308    /// Returns: If the "rubyAnnotation" reference is valid, then this
309    /// function will return its overhang value. Otherwise it will return kCTRubyOverhangInvalid.
310    #[doc(alias = "CTRubyAnnotationGetOverhang")]
311    #[inline]
312    pub unsafe fn overhang(&self) -> CTRubyOverhang {
313        extern "C-unwind" {
314            fn CTRubyAnnotationGetOverhang(ruby_annotation: &CTRubyAnnotation) -> CTRubyOverhang;
315        }
316        unsafe { CTRubyAnnotationGetOverhang(self) }
317    }
318
319    /// Get the size factor of a ruby annotation object.
320    ///
321    ///
322    /// Parameter `rubyAnnotation`: The ruby annotation object.
323    ///
324    ///
325    /// Returns: If the "rubyAnnotation" reference is valid, then this
326    /// function will return its sizeFactor. Otherwise it will return 0.
327    #[doc(alias = "CTRubyAnnotationGetSizeFactor")]
328    #[inline]
329    pub unsafe fn size_factor(&self) -> CGFloat {
330        extern "C-unwind" {
331            fn CTRubyAnnotationGetSizeFactor(ruby_annotation: &CTRubyAnnotation) -> CGFloat;
332        }
333        unsafe { CTRubyAnnotationGetSizeFactor(self) }
334    }
335
336    /// Get the ruby text for a particular position in a ruby annotation.
337    ///
338    ///
339    /// Parameter `rubyAnnotation`: The ruby annotation object.
340    ///
341    ///
342    /// Parameter `position`: The position for which you want to get the ruby text.
343    ///
344    ///
345    /// Returns: If the "rubyAnnotation" reference and the position are valid, then this
346    /// function will return a CFStringRef for the text. Otherwise it will return NULL.
347    #[doc(alias = "CTRubyAnnotationGetTextForPosition")]
348    #[inline]
349    pub unsafe fn text_for_position(
350        &self,
351        position: CTRubyPosition,
352    ) -> Option<CFRetained<CFString>> {
353        extern "C-unwind" {
354            fn CTRubyAnnotationGetTextForPosition(
355                ruby_annotation: &CTRubyAnnotation,
356                position: CTRubyPosition,
357            ) -> Option<NonNull<CFString>>;
358        }
359        let ret = unsafe { CTRubyAnnotationGetTextForPosition(self, position) };
360        ret.map(|ret| unsafe { CFRetained::retain(ret) })
361    }
362}
363
364#[deprecated = "renamed to `CTRubyAnnotation::with_attributes`"]
365#[inline]
366pub unsafe extern "C-unwind" fn CTRubyAnnotationCreateWithAttributes(
367    alignment: CTRubyAlignment,
368    overhang: CTRubyOverhang,
369    position: CTRubyPosition,
370    string: &CFString,
371    attributes: &CFDictionary,
372) -> CFRetained<CTRubyAnnotation> {
373    extern "C-unwind" {
374        fn CTRubyAnnotationCreateWithAttributes(
375            alignment: CTRubyAlignment,
376            overhang: CTRubyOverhang,
377            position: CTRubyPosition,
378            string: &CFString,
379            attributes: &CFDictionary,
380        ) -> Option<NonNull<CTRubyAnnotation>>;
381    }
382    let ret = unsafe {
383        CTRubyAnnotationCreateWithAttributes(alignment, overhang, position, string, attributes)
384    };
385    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
386    unsafe { CFRetained::from_raw(ret) }
387}
388
389#[deprecated = "renamed to `CTRubyAnnotation::copy`"]
390#[inline]
391pub unsafe extern "C-unwind" fn CTRubyAnnotationCreateCopy(
392    ruby_annotation: &CTRubyAnnotation,
393) -> CFRetained<CTRubyAnnotation> {
394    extern "C-unwind" {
395        fn CTRubyAnnotationCreateCopy(
396            ruby_annotation: &CTRubyAnnotation,
397        ) -> Option<NonNull<CTRubyAnnotation>>;
398    }
399    let ret = unsafe { CTRubyAnnotationCreateCopy(ruby_annotation) };
400    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
401    unsafe { CFRetained::from_raw(ret) }
402}
403
404extern "C-unwind" {
405    #[deprecated = "renamed to `CTRubyAnnotation::alignment`"]
406    pub fn CTRubyAnnotationGetAlignment(ruby_annotation: &CTRubyAnnotation) -> CTRubyAlignment;
407}
408
409extern "C-unwind" {
410    #[deprecated = "renamed to `CTRubyAnnotation::overhang`"]
411    pub fn CTRubyAnnotationGetOverhang(ruby_annotation: &CTRubyAnnotation) -> CTRubyOverhang;
412}
413
414extern "C-unwind" {
415    #[deprecated = "renamed to `CTRubyAnnotation::size_factor`"]
416    pub fn CTRubyAnnotationGetSizeFactor(ruby_annotation: &CTRubyAnnotation) -> CGFloat;
417}
418
419#[deprecated = "renamed to `CTRubyAnnotation::text_for_position`"]
420#[inline]
421pub unsafe extern "C-unwind" fn CTRubyAnnotationGetTextForPosition(
422    ruby_annotation: &CTRubyAnnotation,
423    position: CTRubyPosition,
424) -> Option<CFRetained<CFString>> {
425    extern "C-unwind" {
426        fn CTRubyAnnotationGetTextForPosition(
427            ruby_annotation: &CTRubyAnnotation,
428            position: CTRubyPosition,
429        ) -> Option<NonNull<CFString>>;
430    }
431    let ret = unsafe { CTRubyAnnotationGetTextForPosition(ruby_annotation, position) };
432    ret.map(|ret| unsafe { CFRetained::retain(ret) })
433}