objc2-core-text 0.3.2

Bindings to the CoreText framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyannotation?language=objc)
#[doc(alias = "CTRubyAnnotationRef")]
#[repr(C)]
pub struct CTRubyAnnotation {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl CTRubyAnnotation {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"__CTRubyAnnotation"> for CTRubyAnnotation {}
);

unsafe impl ConcreteType for CTRubyAnnotation {
    /// Returns the CFType of the ruby annotation object
    #[doc(alias = "CTRubyAnnotationGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn CTRubyAnnotationGetTypeID() -> CFTypeID;
        }
        unsafe { CTRubyAnnotationGetTypeID() }
    }
}

/// 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.
///
///
/// CoreText will determine the alignment.
///
///
/// The ruby text is aligned with the start edge of the base text.
///
///
/// 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.
///
///
/// The ruby text is aligned with the end edge of the base text.
///
///
/// 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.
///
///
/// 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.
///
///
/// 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.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyalignment?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CTRubyAlignment(pub u8);
impl CTRubyAlignment {
    #[doc(alias = "kCTRubyAlignmentInvalid")]
    pub const Invalid: Self = Self(255);
    #[doc(alias = "kCTRubyAlignmentAuto")]
    pub const Auto: Self = Self(0);
    #[doc(alias = "kCTRubyAlignmentStart")]
    pub const Start: Self = Self(1);
    #[doc(alias = "kCTRubyAlignmentCenter")]
    pub const Center: Self = Self(2);
    #[doc(alias = "kCTRubyAlignmentEnd")]
    pub const End: Self = Self(3);
    #[doc(alias = "kCTRubyAlignmentDistributeLetter")]
    pub const DistributeLetter: Self = Self(4);
    #[doc(alias = "kCTRubyAlignmentDistributeSpace")]
    pub const DistributeSpace: Self = Self(5);
    #[doc(alias = "kCTRubyAlignmentLineEdge")]
    pub const LineEdge: Self = Self(6);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CTRubyAlignment {
    const ENCODING: Encoding = u8::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CTRubyAlignment {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// These constants specify whether, and on which side, ruby text is allowed to overhang adjacent text if it is wider than the base text.
///
///
/// The ruby text can overhang adjacent text on both sides.
///
///
/// The ruby text can overhang the text that proceeds it.
///
///
/// The ruby text can overhang the text that follows it.
///
///
/// The ruby text cannot overhang the proceeding or following text.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyoverhang?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CTRubyOverhang(pub u8);
impl CTRubyOverhang {
    #[doc(alias = "kCTRubyOverhangInvalid")]
    pub const Invalid: Self = Self(255);
    #[doc(alias = "kCTRubyOverhangAuto")]
    pub const Auto: Self = Self(0);
    #[doc(alias = "kCTRubyOverhangStart")]
    pub const Start: Self = Self(1);
    #[doc(alias = "kCTRubyOverhangEnd")]
    pub const End: Self = Self(2);
    #[doc(alias = "kCTRubyOverhangNone")]
    pub const None: Self = Self(3);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CTRubyOverhang {
    const ENCODING: Encoding = u8::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CTRubyOverhang {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// These constants specify the position of the ruby text with respect to the base text.
///
///
/// The ruby text is positioned before the base text; i.e. above horizontal text and to the right of vertical text.
///
///
/// The ruby text is positioned after the base text; i.e. below horizontal text and to the left of vertical text.
///
///
/// 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.
///
///
/// The ruby text follows the base text with no special styling.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrubyposition?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CTRubyPosition(pub u8);
impl CTRubyPosition {
    #[doc(alias = "kCTRubyPositionBefore")]
    pub const Before: Self = Self(0);
    #[doc(alias = "kCTRubyPositionAfter")]
    pub const After: Self = Self(1);
    #[doc(alias = "kCTRubyPositionInterCharacter")]
    pub const InterCharacter: Self = Self(2);
    #[doc(alias = "kCTRubyPositionInline")]
    pub const Inline: Self = Self(3);
    #[doc(alias = "kCTRubyPositionCount")]
    pub const Count: Self = Self(4);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CTRubyPosition {
    const ENCODING: Encoding = u8::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CTRubyPosition {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// Specifies the size of the annotation text as a percent of the size of the base text.
    ///
    ///
    /// Value must be a CFNumberRef.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrubyannotationsizefactorattributename?language=objc)
    pub static kCTRubyAnnotationSizeFactorAttributeName: &'static CFString;
}

extern "C" {
    /// Treat the size specified in kCTRubyAnnotationSizeFactorAttributeName as the maximum
    /// scale factor, when the base text size is smaller than annotation text size, we will
    /// try to scale the annotation font size down so that it will fit the base text without
    /// overhang or adding extra padding between base text.
    ///
    ///
    /// Value must be a CFBooleanRef. Default is false.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/kctrubyannotationscaletofitattributename?language=objc)
    pub static kCTRubyAnnotationScaleToFitAttributeName: &'static CFString;
}

impl CTRubyAnnotation {
    /// Creates an immutable ruby annotation object.
    ///
    ///
    /// Using this function to create a ruby annotation object with more precise
    /// control of the annotation text.
    ///
    ///
    /// Parameter `alignment`: Specifies how the ruby text and the base text should be aligned relative to each other.
    ///
    ///
    /// Parameter `overhang`: Specifies how the ruby text can overhang adjacent characters.
    ///
    ///
    /// Parameter `position`: The position of the annotation text.
    ///
    ///
    /// Parameter `string`: A string without any formatting, its format will be derived from the attrs specified below.
    ///
    ///
    /// Parameter `attributes`: A attribute dictionary to combine with the string specified above. If you don't specify
    /// kCTFontAttributeName, the font used by the Ruby annotation will be deduced from the base
    /// text, with a size factor specified by a CFNumberRef value keyed by
    /// kCTRubyAnnotationSizeFactorAttributeName.
    ///
    ///
    /// Returns: This function will return a reference to a CTRubyAnnotation object.
    ///
    /// # Safety
    ///
    /// `attributes` generics must be of the correct type.
    #[doc(alias = "CTRubyAnnotationCreateWithAttributes")]
    #[inline]
    pub unsafe fn with_attributes(
        alignment: CTRubyAlignment,
        overhang: CTRubyOverhang,
        position: CTRubyPosition,
        string: &CFString,
        attributes: &CFDictionary,
    ) -> CFRetained<CTRubyAnnotation> {
        extern "C-unwind" {
            fn CTRubyAnnotationCreateWithAttributes(
                alignment: CTRubyAlignment,
                overhang: CTRubyOverhang,
                position: CTRubyPosition,
                string: &CFString,
                attributes: &CFDictionary,
            ) -> Option<NonNull<CTRubyAnnotation>>;
        }
        let ret = unsafe {
            CTRubyAnnotationCreateWithAttributes(alignment, overhang, position, string, attributes)
        };
        let ret =
            ret.expect("function was marked as returning non-null, but actually returned NULL");
        unsafe { CFRetained::from_raw(ret) }
    }

    /// Creates an immutable copy of a ruby annotation object.
    ///
    ///
    /// Parameter `rubyAnnotation`: The ruby annotation that you wish to copy.
    ///
    ///
    /// Returns: If the "rubyAnnotation" reference is valid, then this
    /// function will return valid reference to an immutable
    /// CTRubyAnnotation object that is a copy of the one passed into
    /// "rubyAnnotation".
    #[doc(alias = "CTRubyAnnotationCreateCopy")]
    #[inline]
    pub unsafe fn copy(&self) -> CFRetained<CTRubyAnnotation> {
        extern "C-unwind" {
            fn CTRubyAnnotationCreateCopy(
                ruby_annotation: &CTRubyAnnotation,
            ) -> Option<NonNull<CTRubyAnnotation>>;
        }
        let ret = unsafe { CTRubyAnnotationCreateCopy(self) };
        let ret =
            ret.expect("function was marked as returning non-null, but actually returned NULL");
        unsafe { CFRetained::from_raw(ret) }
    }

    /// Get the alignment value of a ruby annotation object.
    ///
    ///
    /// Parameter `rubyAnnotation`: The ruby annotation object.
    ///
    ///
    /// Returns: If the "rubyAnnotation" reference is valid, then this
    /// function will return its alignment. Otherwise it will return kCTRubyAlignmentInvalid.
    #[doc(alias = "CTRubyAnnotationGetAlignment")]
    #[inline]
    pub unsafe fn alignment(&self) -> CTRubyAlignment {
        extern "C-unwind" {
            fn CTRubyAnnotationGetAlignment(ruby_annotation: &CTRubyAnnotation) -> CTRubyAlignment;
        }
        unsafe { CTRubyAnnotationGetAlignment(self) }
    }

    /// Get the overhang value of a ruby annotation object.
    ///
    ///
    /// Parameter `rubyAnnotation`: The ruby annotation object.
    ///
    ///
    /// Returns: If the "rubyAnnotation" reference is valid, then this
    /// function will return its overhang value. Otherwise it will return kCTRubyOverhangInvalid.
    #[doc(alias = "CTRubyAnnotationGetOverhang")]
    #[inline]
    pub unsafe fn overhang(&self) -> CTRubyOverhang {
        extern "C-unwind" {
            fn CTRubyAnnotationGetOverhang(ruby_annotation: &CTRubyAnnotation) -> CTRubyOverhang;
        }
        unsafe { CTRubyAnnotationGetOverhang(self) }
    }

    /// Get the size factor of a ruby annotation object.
    ///
    ///
    /// Parameter `rubyAnnotation`: The ruby annotation object.
    ///
    ///
    /// Returns: If the "rubyAnnotation" reference is valid, then this
    /// function will return its sizeFactor. Otherwise it will return 0.
    #[doc(alias = "CTRubyAnnotationGetSizeFactor")]
    #[inline]
    pub unsafe fn size_factor(&self) -> CGFloat {
        extern "C-unwind" {
            fn CTRubyAnnotationGetSizeFactor(ruby_annotation: &CTRubyAnnotation) -> CGFloat;
        }
        unsafe { CTRubyAnnotationGetSizeFactor(self) }
    }

    /// Get the ruby text for a particular position in a ruby annotation.
    ///
    ///
    /// Parameter `rubyAnnotation`: The ruby annotation object.
    ///
    ///
    /// Parameter `position`: The position for which you want to get the ruby text.
    ///
    ///
    /// Returns: If the "rubyAnnotation" reference and the position are valid, then this
    /// function will return a CFStringRef for the text. Otherwise it will return NULL.
    #[doc(alias = "CTRubyAnnotationGetTextForPosition")]
    #[inline]
    pub unsafe fn text_for_position(
        &self,
        position: CTRubyPosition,
    ) -> Option<CFRetained<CFString>> {
        extern "C-unwind" {
            fn CTRubyAnnotationGetTextForPosition(
                ruby_annotation: &CTRubyAnnotation,
                position: CTRubyPosition,
            ) -> Option<NonNull<CFString>>;
        }
        let ret = unsafe { CTRubyAnnotationGetTextForPosition(self, position) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }
}

#[deprecated = "renamed to `CTRubyAnnotation::with_attributes`"]
#[inline]
pub unsafe extern "C-unwind" fn CTRubyAnnotationCreateWithAttributes(
    alignment: CTRubyAlignment,
    overhang: CTRubyOverhang,
    position: CTRubyPosition,
    string: &CFString,
    attributes: &CFDictionary,
) -> CFRetained<CTRubyAnnotation> {
    extern "C-unwind" {
        fn CTRubyAnnotationCreateWithAttributes(
            alignment: CTRubyAlignment,
            overhang: CTRubyOverhang,
            position: CTRubyPosition,
            string: &CFString,
            attributes: &CFDictionary,
        ) -> Option<NonNull<CTRubyAnnotation>>;
    }
    let ret = unsafe {
        CTRubyAnnotationCreateWithAttributes(alignment, overhang, position, string, attributes)
    };
    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
    unsafe { CFRetained::from_raw(ret) }
}

#[deprecated = "renamed to `CTRubyAnnotation::copy`"]
#[inline]
pub unsafe extern "C-unwind" fn CTRubyAnnotationCreateCopy(
    ruby_annotation: &CTRubyAnnotation,
) -> CFRetained<CTRubyAnnotation> {
    extern "C-unwind" {
        fn CTRubyAnnotationCreateCopy(
            ruby_annotation: &CTRubyAnnotation,
        ) -> Option<NonNull<CTRubyAnnotation>>;
    }
    let ret = unsafe { CTRubyAnnotationCreateCopy(ruby_annotation) };
    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
    unsafe { CFRetained::from_raw(ret) }
}

extern "C-unwind" {
    #[deprecated = "renamed to `CTRubyAnnotation::alignment`"]
    pub fn CTRubyAnnotationGetAlignment(ruby_annotation: &CTRubyAnnotation) -> CTRubyAlignment;
}

extern "C-unwind" {
    #[deprecated = "renamed to `CTRubyAnnotation::overhang`"]
    pub fn CTRubyAnnotationGetOverhang(ruby_annotation: &CTRubyAnnotation) -> CTRubyOverhang;
}

extern "C-unwind" {
    #[deprecated = "renamed to `CTRubyAnnotation::size_factor`"]
    pub fn CTRubyAnnotationGetSizeFactor(ruby_annotation: &CTRubyAnnotation) -> CGFloat;
}

#[deprecated = "renamed to `CTRubyAnnotation::text_for_position`"]
#[inline]
pub unsafe extern "C-unwind" fn CTRubyAnnotationGetTextForPosition(
    ruby_annotation: &CTRubyAnnotation,
    position: CTRubyPosition,
) -> Option<CFRetained<CFString>> {
    extern "C-unwind" {
        fn CTRubyAnnotationGetTextForPosition(
            ruby_annotation: &CTRubyAnnotation,
            position: CTRubyPosition,
        ) -> Option<NonNull<CFString>>;
    }
    let ret = unsafe { CTRubyAnnotationGetTextForPosition(ruby_annotation, position) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}