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#[repr(C)]
14pub struct CTRubyAnnotation {
15    inner: [u8; 0],
16    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
17}
18
19cf_type!(
20    #[encoding_name = "__CTRubyAnnotation"]
21    unsafe impl CTRubyAnnotation {}
22);
23
24unsafe impl ConcreteType for CTRubyAnnotation {
25    /// Returns the CFType of the ruby annotation object
26    #[doc(alias = "CTRubyAnnotationGetTypeID")]
27    #[inline]
28    fn type_id() -> CFTypeID {
29        extern "C-unwind" {
30            fn CTRubyAnnotationGetTypeID() -> CFTypeID;
31        }
32        unsafe { CTRubyAnnotationGetTypeID() }
33    }
34}
35
36/// 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.
37///
38///
39/// CoreText will determine the alignment.
40///
41///
42/// The ruby text is aligned with the start edge of the base text.
43///
44///
45/// 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.
46///
47///
48/// The ruby text is aligned with the end edge of the base text.
49///
50///
51/// 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.
52///
53///
54/// 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.
55///
56///
57/// 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.
58///
59/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyalignment?language=objc)
60// NS_ENUM
61#[repr(transparent)]
62#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
63pub struct CTRubyAlignment(pub u8);
64impl CTRubyAlignment {
65    #[doc(alias = "kCTRubyAlignmentInvalid")]
66    pub const Invalid: Self = Self(255);
67    #[doc(alias = "kCTRubyAlignmentAuto")]
68    pub const Auto: Self = Self(0);
69    #[doc(alias = "kCTRubyAlignmentStart")]
70    pub const Start: Self = Self(1);
71    #[doc(alias = "kCTRubyAlignmentCenter")]
72    pub const Center: Self = Self(2);
73    #[doc(alias = "kCTRubyAlignmentEnd")]
74    pub const End: Self = Self(3);
75    #[doc(alias = "kCTRubyAlignmentDistributeLetter")]
76    pub const DistributeLetter: Self = Self(4);
77    #[doc(alias = "kCTRubyAlignmentDistributeSpace")]
78    pub const DistributeSpace: Self = Self(5);
79    #[doc(alias = "kCTRubyAlignmentLineEdge")]
80    pub const LineEdge: Self = Self(6);
81}
82
83#[cfg(feature = "objc2")]
84unsafe impl Encode for CTRubyAlignment {
85    const ENCODING: Encoding = u8::ENCODING;
86}
87
88#[cfg(feature = "objc2")]
89unsafe impl RefEncode for CTRubyAlignment {
90    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
91}
92
93/// These constants specify whether, and on which side, ruby text is allowed to overhang adjacent text if it is wider than the base text.
94///
95///
96/// The ruby text can overhang adjacent text on both sides.
97///
98///
99/// The ruby text can overhang the text that proceeds it.
100///
101///
102/// The ruby text can overhang the text that follows it.
103///
104///
105/// The ruby text cannot overhang the proceeding or following text.
106///
107/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyoverhang?language=objc)
108// NS_ENUM
109#[repr(transparent)]
110#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
111pub struct CTRubyOverhang(pub u8);
112impl CTRubyOverhang {
113    #[doc(alias = "kCTRubyOverhangInvalid")]
114    pub const Invalid: Self = Self(255);
115    #[doc(alias = "kCTRubyOverhangAuto")]
116    pub const Auto: Self = Self(0);
117    #[doc(alias = "kCTRubyOverhangStart")]
118    pub const Start: Self = Self(1);
119    #[doc(alias = "kCTRubyOverhangEnd")]
120    pub const End: Self = Self(2);
121    #[doc(alias = "kCTRubyOverhangNone")]
122    pub const None: Self = Self(3);
123}
124
125#[cfg(feature = "objc2")]
126unsafe impl Encode for CTRubyOverhang {
127    const ENCODING: Encoding = u8::ENCODING;
128}
129
130#[cfg(feature = "objc2")]
131unsafe impl RefEncode for CTRubyOverhang {
132    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
133}
134
135/// These constants specify the position of the ruby text with respect to the base text.
136///
137///
138/// The ruby text is positioned before the base text; i.e. above horizontal text and to the right of vertical text.
139///
140///
141/// The ruby text is positioned after the base text; i.e. below horizontal text and to the left of vertical text.
142///
143///
144/// 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.
145///
146///
147/// The ruby text follows the base text with no special styling.
148///
149/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyposition?language=objc)
150// NS_ENUM
151#[repr(transparent)]
152#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
153pub struct CTRubyPosition(pub u8);
154impl CTRubyPosition {
155    #[doc(alias = "kCTRubyPositionBefore")]
156    pub const Before: Self = Self(0);
157    #[doc(alias = "kCTRubyPositionAfter")]
158    pub const After: Self = Self(1);
159    #[doc(alias = "kCTRubyPositionInterCharacter")]
160    pub const InterCharacter: Self = Self(2);
161    #[doc(alias = "kCTRubyPositionInline")]
162    pub const Inline: Self = Self(3);
163    #[doc(alias = "kCTRubyPositionCount")]
164    pub const Count: Self = Self(4);
165}
166
167#[cfg(feature = "objc2")]
168unsafe impl Encode for CTRubyPosition {
169    const ENCODING: Encoding = u8::ENCODING;
170}
171
172#[cfg(feature = "objc2")]
173unsafe impl RefEncode for CTRubyPosition {
174    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
175}
176
177extern "C" {
178    /// Specifies the size of the annotation text as a percent of the size of the base text.
179    ///
180    ///
181    /// Value must be a CFNumberRef.
182    ///
183    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrubyannotationsizefactorattributename?language=objc)
184    pub static kCTRubyAnnotationSizeFactorAttributeName: &'static CFString;
185}
186
187extern "C" {
188    /// Treat the size specified in kCTRubyAnnotationSizeFactorAttributeName as the maximum
189    /// scale factor, when the base text size is smaller than annotation text size, we will
190    /// try to scale the annotation font size down so that it will fit the base text without
191    /// overhang or adding extra padding between base text.
192    ///
193    ///
194    /// Value must be a CFBooleanRef. Default is false.
195    ///
196    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrubyannotationscaletofitattributename?language=objc)
197    pub static kCTRubyAnnotationScaleToFitAttributeName: &'static CFString;
198}
199
200/// Creates an immutable ruby annotation object.
201///
202///
203/// Using this function to create a ruby annotation object with more precise
204/// control of the annotation text.
205///
206///
207/// Parameter `alignment`: Specifies how the ruby text and the base text should be aligned relative to each other.
208///
209///
210/// Parameter `overhang`: Specifies how the ruby text can overhang adjacent characters.
211///
212///
213/// Parameter `position`: The position of the annotation text.
214///
215///
216/// Parameter `string`: A string without any formatting, its format will be derived from the attrs specified below.
217///
218///
219/// Parameter `attributes`: A attribute dictionary to combine with the string specified above. If you don't specify
220/// kCTFontAttributeName, the font used by the Ruby annotation will be deduced from the base
221/// text, with a size factor specified by a CFNumberRef value keyed by
222/// kCTRubyAnnotationSizeFactorAttributeName.
223///
224///
225/// Returns: This function will return a reference to a CTRubyAnnotation object.
226#[inline]
227pub unsafe extern "C-unwind" fn CTRubyAnnotationCreateWithAttributes(
228    alignment: CTRubyAlignment,
229    overhang: CTRubyOverhang,
230    position: CTRubyPosition,
231    string: &CFString,
232    attributes: &CFDictionary,
233) -> CFRetained<CTRubyAnnotation> {
234    extern "C-unwind" {
235        fn CTRubyAnnotationCreateWithAttributes(
236            alignment: CTRubyAlignment,
237            overhang: CTRubyOverhang,
238            position: CTRubyPosition,
239            string: &CFString,
240            attributes: &CFDictionary,
241        ) -> Option<NonNull<CTRubyAnnotation>>;
242    }
243    let ret = unsafe {
244        CTRubyAnnotationCreateWithAttributes(alignment, overhang, position, string, attributes)
245    };
246    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
247    unsafe { CFRetained::from_raw(ret) }
248}
249
250/// Creates an immutable copy of a ruby annotation object.
251///
252///
253/// Parameter `rubyAnnotation`: The ruby annotation that you wish to copy.
254///
255///
256/// Returns: If the "rubyAnnotation" reference is valid, then this
257/// function will return valid reference to an immutable
258/// CTRubyAnnotation object that is a copy of the one passed into
259/// "rubyAnnotation".
260#[inline]
261pub unsafe extern "C-unwind" fn CTRubyAnnotationCreateCopy(
262    ruby_annotation: &CTRubyAnnotation,
263) -> CFRetained<CTRubyAnnotation> {
264    extern "C-unwind" {
265        fn CTRubyAnnotationCreateCopy(
266            ruby_annotation: &CTRubyAnnotation,
267        ) -> Option<NonNull<CTRubyAnnotation>>;
268    }
269    let ret = unsafe { CTRubyAnnotationCreateCopy(ruby_annotation) };
270    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
271    unsafe { CFRetained::from_raw(ret) }
272}
273
274extern "C-unwind" {
275    /// Get the alignment value of a ruby annotation object.
276    ///
277    ///
278    /// Parameter `rubyAnnotation`: The ruby annotation object.
279    ///
280    ///
281    /// Returns: If the "rubyAnnotation" reference is valid, then this
282    /// function will return its alignment. Otherwise it will return kCTRubyAlignmentInvalid.
283    pub fn CTRubyAnnotationGetAlignment(ruby_annotation: &CTRubyAnnotation) -> CTRubyAlignment;
284}
285
286extern "C-unwind" {
287    /// Get the overhang value of a ruby annotation object.
288    ///
289    ///
290    /// Parameter `rubyAnnotation`: The ruby annotation object.
291    ///
292    ///
293    /// Returns: If the "rubyAnnotation" reference is valid, then this
294    /// function will return its overhang value. Otherwise it will return kCTRubyOverhangInvalid.
295    pub fn CTRubyAnnotationGetOverhang(ruby_annotation: &CTRubyAnnotation) -> CTRubyOverhang;
296}
297
298extern "C-unwind" {
299    /// Get the size factor of a ruby annotation object.
300    ///
301    ///
302    /// Parameter `rubyAnnotation`: The ruby annotation object.
303    ///
304    ///
305    /// Returns: If the "rubyAnnotation" reference is valid, then this
306    /// function will return its sizeFactor. Otherwise it will return 0.
307    pub fn CTRubyAnnotationGetSizeFactor(ruby_annotation: &CTRubyAnnotation) -> CGFloat;
308}
309
310/// Get the ruby text for a particular position in a ruby annotation.
311///
312///
313/// Parameter `rubyAnnotation`: The ruby annotation object.
314///
315///
316/// Parameter `position`: The position for which you want to get the ruby text.
317///
318///
319/// Returns: If the "rubyAnnotation" reference and the position are valid, then this
320/// function will return a CFStringRef for the text. Otherwise it will return NULL.
321#[inline]
322pub unsafe extern "C-unwind" fn CTRubyAnnotationGetTextForPosition(
323    ruby_annotation: &CTRubyAnnotation,
324    position: CTRubyPosition,
325) -> Option<CFRetained<CFString>> {
326    extern "C-unwind" {
327        fn CTRubyAnnotationGetTextForPosition(
328            ruby_annotation: &CTRubyAnnotation,
329            position: CTRubyPosition,
330        ) -> Option<NonNull<CFString>>;
331    }
332    let ret = unsafe { CTRubyAnnotationGetTextForPosition(ruby_annotation, position) };
333    ret.map(|ret| unsafe { CFRetained::retain(ret) })
334}