pango/auto/
layout_line.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v1_50")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
7use crate::Direction;
8use crate::{ffi, Rectangle};
9use glib::translate::*;
10
11glib::wrapper! {
12    /// A [`LayoutLine`][crate::LayoutLine] represents one of the lines resulting from laying
13    /// out a paragraph via [`Layout`][crate::Layout].
14    ///
15    /// [`LayoutLine`][crate::LayoutLine] structures are obtained by calling
16    /// [`Layout::line()`][crate::Layout::line()] and are only valid until the text,
17    /// attributes, or settings of the parent [`Layout`][crate::Layout] are modified.
18    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
19    pub struct LayoutLine(Shared<ffi::PangoLayoutLine>);
20
21    match fn {
22        ref => |ptr| ffi::pango_layout_line_ref(ptr),
23        unref => |ptr| ffi::pango_layout_line_unref(ptr),
24        type_ => || ffi::pango_layout_line_get_type(),
25    }
26}
27
28impl LayoutLine {
29    /// Computes the logical and ink extents of a layout line.
30    ///
31    /// See [`FontExt::glyph_extents()`][crate::prelude::FontExt::glyph_extents()] for details
32    /// about the interpretation of the rectangles.
33    ///
34    /// # Returns
35    ///
36    ///
37    /// ## `ink_rect`
38    /// rectangle used to store the extents of
39    ///   the glyph string as drawn
40    ///
41    /// ## `logical_rect`
42    /// rectangle used to store the logical
43    ///   extents of the glyph string
44    #[doc(alias = "pango_layout_line_get_extents")]
45    #[doc(alias = "get_extents")]
46    pub fn extents(&self) -> (Rectangle, Rectangle) {
47        unsafe {
48            let mut ink_rect = Rectangle::uninitialized();
49            let mut logical_rect = Rectangle::uninitialized();
50            ffi::pango_layout_line_get_extents(
51                self.to_glib_none().0,
52                ink_rect.to_glib_none_mut().0,
53                logical_rect.to_glib_none_mut().0,
54            );
55            (ink_rect, logical_rect)
56        }
57    }
58
59    /// Computes the height of the line, as the maximum of the heights
60    /// of fonts used in this line.
61    ///
62    /// Note that the actual baseline-to-baseline distance between lines
63    /// of text is influenced by other factors, such as
64    /// [`Layout::set_spacing()`][crate::Layout::set_spacing()] and
65    /// [`Layout::set_line_spacing()`][crate::Layout::set_line_spacing()].
66    ///
67    /// # Returns
68    ///
69    ///
70    /// ## `height`
71    /// return location for the line height
72    #[cfg(feature = "v1_44")]
73    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
74    #[doc(alias = "pango_layout_line_get_height")]
75    #[doc(alias = "get_height")]
76    pub fn height(&self) -> i32 {
77        unsafe {
78            let mut height = std::mem::MaybeUninit::uninit();
79            ffi::pango_layout_line_get_height(self.to_glib_none().0, height.as_mut_ptr());
80            height.assume_init()
81        }
82    }
83
84    /// Returns the length of the line, in bytes.
85    ///
86    /// # Returns
87    ///
88    /// the length of the line
89    #[cfg(feature = "v1_50")]
90    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
91    #[doc(alias = "pango_layout_line_get_length")]
92    #[doc(alias = "get_length")]
93    pub fn length(&self) -> i32 {
94        unsafe { ffi::pango_layout_line_get_length(self.to_glib_none().0) }
95    }
96
97    /// Computes the logical and ink extents of @self in device units.
98    ///
99    /// This function just calls [`extents()`][Self::extents()] followed by
100    /// two [`extents_to_pixels()`][crate::extents_to_pixels()] calls, rounding @ink_rect and @logical_rect
101    /// such that the rounded rectangles fully contain the unrounded one (that is,
102    /// passes them as first argument to [`extents_to_pixels()`][crate::extents_to_pixels()]).
103    ///
104    /// # Returns
105    ///
106    ///
107    /// ## `ink_rect`
108    /// rectangle used to store the extents of
109    ///   the glyph string as drawn
110    ///
111    /// ## `logical_rect`
112    /// rectangle used to store the logical
113    ///   extents of the glyph string
114    #[doc(alias = "pango_layout_line_get_pixel_extents")]
115    #[doc(alias = "get_pixel_extents")]
116    pub fn pixel_extents(&self) -> (Rectangle, Rectangle) {
117        unsafe {
118            let mut ink_rect = Rectangle::uninitialized();
119            let mut logical_rect = Rectangle::uninitialized();
120            ffi::pango_layout_line_get_pixel_extents(
121                self.to_glib_none().0,
122                ink_rect.to_glib_none_mut().0,
123                logical_rect.to_glib_none_mut().0,
124            );
125            (ink_rect, logical_rect)
126        }
127    }
128
129    /// Returns the resolved direction of the line.
130    ///
131    /// # Returns
132    ///
133    /// the resolved direction of the line
134    #[cfg(feature = "v1_50")]
135    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
136    #[doc(alias = "pango_layout_line_get_resolved_direction")]
137    #[doc(alias = "get_resolved_direction")]
138    pub fn resolved_direction(&self) -> Direction {
139        unsafe {
140            from_glib(ffi::pango_layout_line_get_resolved_direction(
141                self.to_glib_none().0,
142            ))
143        }
144    }
145
146    /// Returns the start index of the line, as byte index
147    /// into the text of the layout.
148    ///
149    /// # Returns
150    ///
151    /// the start index of the line
152    #[cfg(feature = "v1_50")]
153    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
154    #[doc(alias = "pango_layout_line_get_start_index")]
155    #[doc(alias = "get_start_index")]
156    pub fn start_index(&self) -> i32 {
157        unsafe { ffi::pango_layout_line_get_start_index(self.to_glib_none().0) }
158    }
159
160    /// Converts an index within a line to a X position.
161    /// ## `index_`
162    /// byte offset of a grapheme within the layout
163    /// ## `trailing`
164    /// an integer indicating the edge of the grapheme to retrieve
165    ///   the position of. If > 0, the trailing edge of the grapheme,
166    ///   if 0, the leading of the grapheme
167    ///
168    /// # Returns
169    ///
170    ///
171    /// ## `x_pos`
172    /// location to store the x_offset (in Pango units)
173    #[doc(alias = "pango_layout_line_index_to_x")]
174    pub fn index_to_x(&self, index_: i32, trailing: bool) -> i32 {
175        unsafe {
176            let mut x_pos = std::mem::MaybeUninit::uninit();
177            ffi::pango_layout_line_index_to_x(
178                self.to_glib_none().0,
179                index_,
180                trailing.into_glib(),
181                x_pos.as_mut_ptr(),
182            );
183            x_pos.assume_init()
184        }
185    }
186
187    /// Returns whether this is the first line of the paragraph.
188    ///
189    /// # Returns
190    ///
191    /// [`true`] if this is the first line
192    #[cfg(feature = "v1_50")]
193    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
194    #[doc(alias = "pango_layout_line_is_paragraph_start")]
195    pub fn is_paragraph_start(&self) -> bool {
196        unsafe {
197            from_glib(ffi::pango_layout_line_is_paragraph_start(
198                self.to_glib_none().0,
199            ))
200        }
201    }
202}