objc2_core_text/generated/
CTParagraphStyle.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
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctparagraphstyle?language=objc)
14#[repr(C)]
15pub struct CTParagraphStyle {
16    inner: [u8; 0],
17    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
18}
19
20cf_type!(
21    unsafe impl CTParagraphStyle {}
22);
23#[cfg(feature = "objc2")]
24cf_objc2_type!(
25    unsafe impl RefEncode<"__CTParagraphStyle"> for CTParagraphStyle {}
26);
27
28unsafe impl ConcreteType for CTParagraphStyle {
29    /// Returns the CFType of the paragraph style object
30    #[doc(alias = "CTParagraphStyleGetTypeID")]
31    #[inline]
32    fn type_id() -> CFTypeID {
33        extern "C-unwind" {
34            fn CTParagraphStyleGetTypeID() -> CFTypeID;
35        }
36        unsafe { CTParagraphStyleGetTypeID() }
37    }
38}
39
40/// These constants specify text alignment.
41///
42///
43/// Text is visually left-aligned.
44///
45///
46/// Text is visually right-aligned.
47///
48///
49/// Text is visually center-aligned.
50///
51///
52/// Text is fully justified. The last line in a paragraph is
53/// naturally aligned.
54///
55///
56/// Use the natural alignment of the text's script.
57///
58/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/cttextalignment?language=objc)
59// NS_ENUM
60#[repr(transparent)]
61#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
62pub struct CTTextAlignment(pub u8);
63impl CTTextAlignment {
64    #[doc(alias = "kCTTextAlignmentLeft")]
65    pub const Left: Self = Self(0);
66    #[doc(alias = "kCTTextAlignmentRight")]
67    pub const Right: Self = Self(1);
68    #[doc(alias = "kCTTextAlignmentCenter")]
69    pub const Center: Self = Self(2);
70    #[doc(alias = "kCTTextAlignmentJustified")]
71    pub const Justified: Self = Self(3);
72    #[doc(alias = "kCTTextAlignmentNatural")]
73    pub const Natural: Self = Self(4);
74    #[deprecated = "Deprecated"]
75    pub const kCTLeftTextAlignment: Self = Self(CTTextAlignment::Left.0);
76    #[deprecated = "Deprecated"]
77    pub const kCTRightTextAlignment: Self = Self(CTTextAlignment::Right.0);
78    #[deprecated = "Deprecated"]
79    pub const kCTCenterTextAlignment: Self = Self(CTTextAlignment::Center.0);
80    #[deprecated = "Deprecated"]
81    pub const kCTJustifiedTextAlignment: Self = Self(CTTextAlignment::Justified.0);
82    #[deprecated = "Deprecated"]
83    pub const kCTNaturalTextAlignment: Self = Self(CTTextAlignment::Natural.0);
84}
85
86#[cfg(feature = "objc2")]
87unsafe impl Encode for CTTextAlignment {
88    const ENCODING: Encoding = u8::ENCODING;
89}
90
91#[cfg(feature = "objc2")]
92unsafe impl RefEncode for CTTextAlignment {
93    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
94}
95
96/// These constants specify what happens when a line is too long for
97/// its frame.
98///
99///
100/// Wrapping occurs at word boundaries, unless the word itself doesn't
101/// fit on a single line.
102///
103///
104/// Wrapping occurs before the first character that doesn't fit.
105///
106///
107/// Lines are simply not drawn past the edge of the frame.
108///
109///
110/// Each line is displayed so that the end fits in the frame and the
111/// missing text is indicated by some kind of ellipsis glyph.
112///
113///
114/// Each line is displayed so that the beginning fits in the
115/// container and the missing text is indicated by some kind of
116/// ellipsis glyph.
117///
118///
119/// Each line is displayed so that the beginning and end fit in the
120/// container and the missing text is indicated by some kind of
121/// ellipsis glyph in the middle.
122///
123/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctlinebreakmode?language=objc)
124// NS_ENUM
125#[repr(transparent)]
126#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
127pub struct CTLineBreakMode(pub u8);
128impl CTLineBreakMode {
129    #[doc(alias = "kCTLineBreakByWordWrapping")]
130    pub const ByWordWrapping: Self = Self(0);
131    #[doc(alias = "kCTLineBreakByCharWrapping")]
132    pub const ByCharWrapping: Self = Self(1);
133    #[doc(alias = "kCTLineBreakByClipping")]
134    pub const ByClipping: Self = Self(2);
135    #[doc(alias = "kCTLineBreakByTruncatingHead")]
136    pub const ByTruncatingHead: Self = Self(3);
137    #[doc(alias = "kCTLineBreakByTruncatingTail")]
138    pub const ByTruncatingTail: Self = Self(4);
139    #[doc(alias = "kCTLineBreakByTruncatingMiddle")]
140    pub const ByTruncatingMiddle: Self = Self(5);
141}
142
143#[cfg(feature = "objc2")]
144unsafe impl Encode for CTLineBreakMode {
145    const ENCODING: Encoding = u8::ENCODING;
146}
147
148#[cfg(feature = "objc2")]
149unsafe impl RefEncode for CTLineBreakMode {
150    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
151}
152
153/// These constants specify the writing direction
154///
155///
156/// The writing direction is algorithmically determined
157/// using the Unicode Bidirectional Algorithm rules P2 and P3.
158///
159///
160/// The writing direction is left to right.
161///
162///
163/// The writing direction is right to left.
164///
165/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctwritingdirection?language=objc)
166// NS_ENUM
167#[repr(transparent)]
168#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
169pub struct CTWritingDirection(pub i8);
170impl CTWritingDirection {
171    #[doc(alias = "kCTWritingDirectionNatural")]
172    pub const Natural: Self = Self(-1);
173    #[doc(alias = "kCTWritingDirectionLeftToRight")]
174    pub const LeftToRight: Self = Self(0);
175    #[doc(alias = "kCTWritingDirectionRightToLeft")]
176    pub const RightToLeft: Self = Self(1);
177}
178
179#[cfg(feature = "objc2")]
180unsafe impl Encode for CTWritingDirection {
181    const ENCODING: Encoding = i8::ENCODING;
182}
183
184#[cfg(feature = "objc2")]
185unsafe impl RefEncode for CTWritingDirection {
186    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
187}
188
189/// These constants are used to query and modify the CTParagraphStyle
190/// object.
191///
192///
193/// Each specifier has a type and a default value associated with it.
194/// The type must always be observed when setting or fetching the
195/// value from the CTParagraphStyle object. In addition, some
196/// specifiers affect the behavior of both the framesetter and
197/// the typesetter, and others only affect the behavior of the
198/// framesetter; this is also noted below.
199///
200///
201/// The text alignment. Natural text alignment is realized as
202/// left or right alignment, depending on the line sweep direction
203/// of the first script contained in the paragraph.
204///
205/// Type: CTTextAlignment
206/// Default: kCTTextAlignmentNatural
207/// Application: CTFramesetter
208///
209///
210/// The distance in points from the leading margin of a frame to
211/// the beginning of the paragraph's first line. This value is always
212/// nonnegative.
213///
214/// Type: CGFloat
215/// Default: 0.0
216/// Application: CTFramesetter
217///
218///
219/// The distance in points from the leading margin of a text
220/// container to the beginning of lines other than the first.
221/// This value is always nonnegative.
222///
223/// Type: CGFloat
224/// Default: 0.0
225/// Application: CTFramesetter
226///
227///
228/// The distance in points from the margin of a frame to the end of
229/// lines. If positive, this value is the distance from the leading
230/// margin (for example, the left margin in left-to-right text).
231/// If 0 or negative, it's the distance from the trailing margin.
232///
233/// Type: CGFloat
234/// Default: 0.0
235/// Application: CTFramesetter
236///
237///
238/// The CTTextTab objects, sorted by location, that define the tab
239/// stops for the paragraph style.
240///
241/// Type: CFArray of CTTextTabRef
242/// Default: 12 left-aligned tabs, spaced by 28.0 points
243/// Application: CTFramesetter, CTTypesetter
244///
245///
246/// The document-wide default tab interval. Tabs after the last
247/// specified by kCTParagraphStyleSpecifierTabStops are placed at
248/// integer multiples of this distance (if positive).
249///
250/// Type: CGFloat
251/// Default: 0.0
252/// Application: CTFramesetter, CTTypesetter
253///
254///
255/// The mode that should be used to break lines when laying out
256/// the paragraph's text.
257///
258/// Type: CTLineBreakMode
259/// Default: kCTLineBreakByWordWrapping
260/// Application: CTFramesetter
261///
262///
263/// The line height multiple. The natural line height of the
264/// receiver is multiplied by this factor (if positive) before
265/// being constrained by minimum and maximum line height.
266///
267/// Type: CGFloat
268/// Default: 0.0
269/// Application: CTFramesetter
270///
271///
272/// The maximum height that any line in the frame will occupy,
273/// regardless of the font size or size of any attached graphic.
274/// Glyphs and graphics exceeding this height will overlap
275/// neighboring lines. A maximum height of 0 implies
276/// no line height limit. This value is always nonnegative.
277///
278/// Type: CGFloat
279/// Default: 0.0
280/// Application: CTFramesetter
281///
282///
283/// The minimum height that any line in the frame will occupy,
284/// regardless of the font size or size of any attached graphic.
285/// This value is always nonnegative.
286///
287/// Type: CGFloat
288/// Default: 0.0
289/// Application: CTFramesetter
290///
291///
292/// Deprecated.
293/// Use kCTParagraphStyleSpecifierMaximumLineSpacing, kCTParagraphStyleSpecifierMinimumLineSpacing,
294/// and kCTParagraphStyleSpecifierLineSpacingAdjustment to control
295/// space between lines.
296///
297///
298/// The space added at the end of the paragraph to separate it from
299/// the following paragraph. This value is always nonnegative and is
300/// determined by adding the previous paragraph's
301/// kCTParagraphStyleSpecifierParagraphSpacing setting and the
302/// current paragraph's kCTParagraphStyleSpecifierParagraphSpacingBefore
303/// setting.
304///
305/// Type: CGFloat
306/// Default: 0.0
307/// Application: CTFramesetter
308///
309///
310/// The distance between the paragraph's top and the beginning of
311/// its text content.
312///
313/// Type: CGFloat
314/// Default: 0.0
315/// Application: CTFramesetter
316///
317///
318/// The base writing direction of the lines.
319///
320/// Type: CTWritingDirection
321/// Default: kCTWritingDirectionNatural
322/// Application: CTFramesetter, CTTypesetter
323///
324///
325/// The maximum space in points between lines within the paragraph
326/// (commonly known as leading).
327///
328/// Type: CGFloat
329/// Default: some large number.
330/// Application: CTFramesetter
331///
332///
333/// The minimum space in points between lines within the paragraph
334/// (commonly known as leading).
335///
336/// Type: CGFloat
337/// Default: 0.0
338/// Application: CTFramesetter
339///
340///
341/// The space in points added between lines within the paragraph
342/// (commonly known as leading).
343///
344/// Type: CGFloat
345/// Default: 0.0
346/// Application: CTFramesetter
347///
348///
349/// The options controlling the alignment of the line edges with
350/// the leading and trailing margins.
351///
352/// Type: CTLineBoundsOptions
353/// Default: 0 (no options)
354/// Application: CTTypesetter
355///
356/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctparagraphstylespecifier?language=objc)
357// NS_ENUM
358#[repr(transparent)]
359#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
360pub struct CTParagraphStyleSpecifier(pub u32);
361impl CTParagraphStyleSpecifier {
362    #[doc(alias = "kCTParagraphStyleSpecifierAlignment")]
363    pub const Alignment: Self = Self(0);
364    #[doc(alias = "kCTParagraphStyleSpecifierFirstLineHeadIndent")]
365    pub const FirstLineHeadIndent: Self = Self(1);
366    #[doc(alias = "kCTParagraphStyleSpecifierHeadIndent")]
367    pub const HeadIndent: Self = Self(2);
368    #[doc(alias = "kCTParagraphStyleSpecifierTailIndent")]
369    pub const TailIndent: Self = Self(3);
370    #[doc(alias = "kCTParagraphStyleSpecifierTabStops")]
371    pub const TabStops: Self = Self(4);
372    #[doc(alias = "kCTParagraphStyleSpecifierDefaultTabInterval")]
373    pub const DefaultTabInterval: Self = Self(5);
374    #[doc(alias = "kCTParagraphStyleSpecifierLineBreakMode")]
375    pub const LineBreakMode: Self = Self(6);
376    #[doc(alias = "kCTParagraphStyleSpecifierLineHeightMultiple")]
377    pub const LineHeightMultiple: Self = Self(7);
378    #[doc(alias = "kCTParagraphStyleSpecifierMaximumLineHeight")]
379    pub const MaximumLineHeight: Self = Self(8);
380    #[doc(alias = "kCTParagraphStyleSpecifierMinimumLineHeight")]
381    pub const MinimumLineHeight: Self = Self(9);
382    #[doc(alias = "kCTParagraphStyleSpecifierLineSpacing")]
383    #[deprecated = "See documentation for replacements"]
384    pub const LineSpacing: Self = Self(10);
385    #[doc(alias = "kCTParagraphStyleSpecifierParagraphSpacing")]
386    pub const ParagraphSpacing: Self = Self(11);
387    #[doc(alias = "kCTParagraphStyleSpecifierParagraphSpacingBefore")]
388    pub const ParagraphSpacingBefore: Self = Self(12);
389    #[doc(alias = "kCTParagraphStyleSpecifierBaseWritingDirection")]
390    pub const BaseWritingDirection: Self = Self(13);
391    #[doc(alias = "kCTParagraphStyleSpecifierMaximumLineSpacing")]
392    pub const MaximumLineSpacing: Self = Self(14);
393    #[doc(alias = "kCTParagraphStyleSpecifierMinimumLineSpacing")]
394    pub const MinimumLineSpacing: Self = Self(15);
395    #[doc(alias = "kCTParagraphStyleSpecifierLineSpacingAdjustment")]
396    pub const LineSpacingAdjustment: Self = Self(16);
397    #[doc(alias = "kCTParagraphStyleSpecifierLineBoundsOptions")]
398    pub const LineBoundsOptions: Self = Self(17);
399    #[doc(alias = "kCTParagraphStyleSpecifierCount")]
400    pub const Count: Self = Self(18);
401}
402
403#[cfg(feature = "objc2")]
404unsafe impl Encode for CTParagraphStyleSpecifier {
405    const ENCODING: Encoding = u32::ENCODING;
406}
407
408#[cfg(feature = "objc2")]
409unsafe impl RefEncode for CTParagraphStyleSpecifier {
410    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
411}
412
413/// This structure is used to alter the paragraph style.
414///
415/// Field: spec
416/// The specifier of the setting.
417///
418/// Field: valueSize
419/// The size of the value pointed to by the "value" field. This
420/// must match the size of the value required by the
421/// CTParagraphStyleSpecifier set in the "spec" field.
422///
423/// Field: value
424/// A reference to the value of the setting specified by the
425/// "spec" field. The value must be in the proper range for the
426/// spec value. The value must also be at least valueSize.
427///
428/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctparagraphstylesetting?language=objc)
429#[repr(C)]
430#[derive(Clone, Copy, Debug, PartialEq)]
431pub struct CTParagraphStyleSetting {
432    pub spec: CTParagraphStyleSpecifier,
433    pub valueSize: usize,
434    pub value: NonNull<c_void>,
435}
436
437#[cfg(feature = "objc2")]
438unsafe impl Encode for CTParagraphStyleSetting {
439    const ENCODING: Encoding = Encoding::Struct(
440        "CTParagraphStyleSetting",
441        &[
442            <CTParagraphStyleSpecifier>::ENCODING,
443            <usize>::ENCODING,
444            <NonNull<c_void>>::ENCODING,
445        ],
446    );
447}
448
449#[cfg(feature = "objc2")]
450unsafe impl RefEncode for CTParagraphStyleSetting {
451    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
452}
453
454impl CTParagraphStyle {
455    /// Creates an immutable paragraph style.
456    ///
457    ///
458    /// Using this function is the easiest and most efficient way to
459    /// create a paragraph style. Paragraph styles should be kept
460    /// immutable for totally lock-free operation.
461    ///
462    /// If an invalid paragraph style setting specifier is passed into
463    /// the "settings" parameter, nothing bad will happen but just don't
464    /// expect to be able to query for this value. This is to allow
465    /// backwards compatibility with style setting specifiers that may
466    /// be introduced in future versions.
467    ///
468    ///
469    /// Parameter `settings`: The settings that you wish to pre-load the paragraph style
470    /// with. If you wish to specify the default set of settings,
471    /// then this parameter may be set to NULL.
472    ///
473    ///
474    /// Parameter `settingCount`: The number of settings that you have specified in the
475    /// "settings" parameter. This must be greater than or equal
476    /// to zero.
477    ///
478    ///
479    /// Returns: If the paragraph style creation was successful, this function
480    /// will return a valid reference to an immutable CTParagraphStyle
481    /// object. Otherwise, this function will return NULL.
482    #[doc(alias = "CTParagraphStyleCreate")]
483    #[inline]
484    pub unsafe fn new(
485        settings: *const CTParagraphStyleSetting,
486        setting_count: usize,
487    ) -> CFRetained<CTParagraphStyle> {
488        extern "C-unwind" {
489            fn CTParagraphStyleCreate(
490                settings: *const CTParagraphStyleSetting,
491                setting_count: usize,
492            ) -> Option<NonNull<CTParagraphStyle>>;
493        }
494        let ret = unsafe { CTParagraphStyleCreate(settings, setting_count) };
495        let ret =
496            ret.expect("function was marked as returning non-null, but actually returned NULL");
497        unsafe { CFRetained::from_raw(ret) }
498    }
499
500    /// Creates an immutable copy of a paragraph style.
501    ///
502    ///
503    /// Parameter `paragraphStyle`: The style that you wish to copy.
504    ///
505    ///
506    /// Returns: If the "paragraphStyle" reference is valid, then this
507    /// function will return valid reference to an immutable
508    /// CTParagraphStyle object that is a copy of the one passed into
509    /// "paragraphStyle".
510    #[doc(alias = "CTParagraphStyleCreateCopy")]
511    #[inline]
512    pub unsafe fn copy(self: &CTParagraphStyle) -> CFRetained<CTParagraphStyle> {
513        extern "C-unwind" {
514            fn CTParagraphStyleCreateCopy(
515                paragraph_style: &CTParagraphStyle,
516            ) -> Option<NonNull<CTParagraphStyle>>;
517        }
518        let ret = unsafe { CTParagraphStyleCreateCopy(self) };
519        let ret =
520            ret.expect("function was marked as returning non-null, but actually returned NULL");
521        unsafe { CFRetained::from_raw(ret) }
522    }
523
524    /// Obtains the current value for a single setting specifier.
525    ///
526    ///
527    /// This function will return the current value of the specifier
528    /// whether or not the user had actually set it. If the user has
529    /// not set it, this function will return the default value.
530    ///
531    /// If an invalid paragraph style setting specifier is passed into
532    /// the "spec" parameter, nothing bad will happen and the buffer
533    /// value will simply be zeroed out. This is to allow backwards
534    /// compatibility with style setting specifier that may be introduced
535    /// in future versions.
536    ///
537    ///
538    /// Parameter `paragraphStyle`: The paragraph style that you wish to get the value from.
539    ///
540    ///
541    /// Parameter `spec`: The setting specifier that you want to get the value for.
542    ///
543    ///
544    /// Parameter `valueBufferSize`: The size of the buffer pointed to by the "valueBuffer" parameter.
545    /// This value must be at least as large as the size the required by
546    /// the CTParagraphSpecifier value set in the "spec" parameter.
547    ///
548    ///
549    /// Parameter `valueBuffer`: The buffer where the requested setting value will be written
550    /// upon successful completion. The buffer's size needs to be at least
551    /// as large as the value passed into "valueBufferSize".
552    ///
553    ///
554    /// Returns: This function will return "true" if the valueBuffer had been
555    /// successfully filled. Otherwise, this function will return false,
556    /// indicating that one or more of the parameters is not valid.
557    #[doc(alias = "CTParagraphStyleGetValueForSpecifier")]
558    #[inline]
559    pub unsafe fn value_for_specifier(
560        self: &CTParagraphStyle,
561        spec: CTParagraphStyleSpecifier,
562        value_buffer_size: usize,
563        value_buffer: NonNull<c_void>,
564    ) -> bool {
565        extern "C-unwind" {
566            fn CTParagraphStyleGetValueForSpecifier(
567                paragraph_style: &CTParagraphStyle,
568                spec: CTParagraphStyleSpecifier,
569                value_buffer_size: usize,
570                value_buffer: NonNull<c_void>,
571            ) -> bool;
572        }
573        unsafe { CTParagraphStyleGetValueForSpecifier(self, spec, value_buffer_size, value_buffer) }
574    }
575}
576
577#[deprecated = "renamed to `CTParagraphStyle::new`"]
578#[inline]
579pub unsafe extern "C-unwind" fn CTParagraphStyleCreate(
580    settings: *const CTParagraphStyleSetting,
581    setting_count: usize,
582) -> CFRetained<CTParagraphStyle> {
583    extern "C-unwind" {
584        fn CTParagraphStyleCreate(
585            settings: *const CTParagraphStyleSetting,
586            setting_count: usize,
587        ) -> Option<NonNull<CTParagraphStyle>>;
588    }
589    let ret = unsafe { CTParagraphStyleCreate(settings, setting_count) };
590    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
591    unsafe { CFRetained::from_raw(ret) }
592}
593
594#[deprecated = "renamed to `CTParagraphStyle::copy`"]
595#[inline]
596pub unsafe extern "C-unwind" fn CTParagraphStyleCreateCopy(
597    paragraph_style: &CTParagraphStyle,
598) -> CFRetained<CTParagraphStyle> {
599    extern "C-unwind" {
600        fn CTParagraphStyleCreateCopy(
601            paragraph_style: &CTParagraphStyle,
602        ) -> Option<NonNull<CTParagraphStyle>>;
603    }
604    let ret = unsafe { CTParagraphStyleCreateCopy(paragraph_style) };
605    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
606    unsafe { CFRetained::from_raw(ret) }
607}
608
609extern "C-unwind" {
610    #[deprecated = "renamed to `CTParagraphStyle::value_for_specifier`"]
611    pub fn CTParagraphStyleGetValueForSpecifier(
612        paragraph_style: &CTParagraphStyle,
613        spec: CTParagraphStyleSpecifier,
614        value_buffer_size: usize,
615        value_buffer: NonNull<c_void>,
616    ) -> bool;
617}