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