Skip to main content

pango/auto/
glyph_string.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
5use crate::{Analysis, Font, Rectangle, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// A [`GlyphString`][crate::GlyphString] is used to store strings of glyphs with geometry
10    /// and visual attribute information.
11    ///
12    /// The storage for the glyph information is owned by the structure
13    /// which simplifies memory management.
14    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
15    pub struct GlyphString(Boxed<ffi::PangoGlyphString>);
16
17    match fn {
18        copy => |ptr| ffi::pango_glyph_string_copy(mut_override(ptr)),
19        free => |ptr| ffi::pango_glyph_string_free(ptr),
20        type_ => || ffi::pango_glyph_string_get_type(),
21    }
22}
23
24impl GlyphString {
25    /// Create a new [`GlyphString`][crate::GlyphString].
26    ///
27    /// # Returns
28    ///
29    /// the newly allocated [`GlyphString`][crate::GlyphString], which
30    ///   should be freed with `Pango::GlyphString::free()`.
31    #[doc(alias = "pango_glyph_string_new")]
32    pub fn new() -> GlyphString {
33        unsafe { from_glib_full(ffi::pango_glyph_string_new()) }
34    }
35
36    /// Compute the logical and ink extents of a glyph string.
37    ///
38    /// See the documentation for [`FontExt::glyph_extents()`][crate::prelude::FontExt::glyph_extents()] for details
39    /// about the interpretation of the rectangles.
40    ///
41    /// Examples of logical (red) and ink (green) rects:
42    ///
43    /// ![](rects1.png) ![](rects2.png)
44    /// ## `font`
45    /// a [`Font`][crate::Font]
46    ///
47    /// # Returns
48    ///
49    ///
50    /// ## `ink_rect`
51    /// rectangle used to store the extents of the glyph string as drawn
52    ///
53    /// ## `logical_rect`
54    /// rectangle used to store the logical extents of the glyph string
55    #[doc(alias = "pango_glyph_string_extents")]
56    pub fn extents(&mut self, font: &impl IsA<Font>) -> (Rectangle, Rectangle) {
57        unsafe {
58            let mut ink_rect = Rectangle::uninitialized();
59            let mut logical_rect = Rectangle::uninitialized();
60            ffi::pango_glyph_string_extents(
61                self.to_glib_none_mut().0,
62                font.as_ref().to_glib_none().0,
63                ink_rect.to_glib_none_mut().0,
64                logical_rect.to_glib_none_mut().0,
65            );
66            (ink_rect, logical_rect)
67        }
68    }
69
70    /// Computes the extents of a sub-portion of a glyph string.
71    ///
72    /// The extents are relative to the start of the glyph string range
73    /// (the origin of their coordinate system is at the start of the range,
74    /// not at the start of the entire glyph string).
75    /// ## `start`
76    /// start index
77    /// ## `end`
78    ///  end)
79    /// ## `font`
80    /// a [`Font`][crate::Font]
81    ///
82    /// # Returns
83    ///
84    ///
85    /// ## `ink_rect`
86    /// rectangle used to
87    ///   store the extents of the glyph string range as drawn
88    ///
89    /// ## `logical_rect`
90    /// rectangle used to
91    ///   store the logical extents of the glyph string range
92    #[doc(alias = "pango_glyph_string_extents_range")]
93    pub fn extents_range(
94        &mut self,
95        start: i32,
96        end: i32,
97        font: &impl IsA<Font>,
98    ) -> (Rectangle, Rectangle) {
99        unsafe {
100            let mut ink_rect = Rectangle::uninitialized();
101            let mut logical_rect = Rectangle::uninitialized();
102            ffi::pango_glyph_string_extents_range(
103                self.to_glib_none_mut().0,
104                start,
105                end,
106                font.as_ref().to_glib_none().0,
107                ink_rect.to_glib_none_mut().0,
108                logical_rect.to_glib_none_mut().0,
109            );
110            (ink_rect, logical_rect)
111        }
112    }
113
114    /// Computes the logical width of the glyph string.
115    ///
116    /// This can also be computed using [`extents()`][Self::extents()].
117    /// However, since this only computes the width, it's much faster. This
118    /// is in fact only a convenience function that computes the sum of
119    /// @geometry.width for each glyph in the @self.
120    ///
121    /// # Returns
122    ///
123    /// the logical width of the glyph string.
124    #[doc(alias = "pango_glyph_string_get_width")]
125    #[doc(alias = "get_width")]
126    pub fn width(&self) -> i32 {
127        unsafe { ffi::pango_glyph_string_get_width(mut_override(self.to_glib_none().0)) }
128    }
129
130    /// /picture
131    /// ## `text`
132    /// the text for the run
133    /// ## `length`
134    /// the number of bytes (not characters) in @text.
135    /// ## `analysis`
136    /// the analysis information return from [`itemize()`][crate::itemize()]
137    /// ## `index_`
138    /// the byte index within @text
139    /// ## `trailing`
140    /// whether we should compute the result for the beginning ([`false`])
141    ///   or end ([`true`]) of the character.
142    ///
143    /// # Returns
144    ///
145    ///
146    /// ## `x_pos`
147    /// location to store result
148    #[doc(alias = "pango_glyph_string_index_to_x")]
149    pub fn index_to_x(&self, text: &str, analysis: &Analysis, index_: i32, trailing: bool) -> i32 {
150        let length = text.len() as _;
151        unsafe {
152            let mut x_pos = std::mem::MaybeUninit::uninit();
153            ffi::pango_glyph_string_index_to_x(
154                mut_override(self.to_glib_none().0),
155                text.to_glib_none().0,
156                length,
157                mut_override(analysis.to_glib_none().0),
158                index_,
159                trailing.into_glib(),
160                x_pos.as_mut_ptr(),
161            );
162            x_pos.assume_init()
163        }
164    }
165
166    //#[cfg(feature = "v1_50")]
167    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
168    //#[doc(alias = "pango_glyph_string_index_to_x_full")]
169    //pub fn index_to_x_full(&mut self, text: &str, analysis: &mut Analysis, attrs: /*Ignored*/Option<&mut LogAttr>, index_: i32, trailing: bool) -> i32 {
170    //    unsafe { TODO: call ffi:pango_glyph_string_index_to_x_full() }
171    //}
172
173    /// Resize a glyph string to the given length.
174    /// ## `new_len`
175    /// the new length of the string
176    #[doc(alias = "pango_glyph_string_set_size")]
177    pub fn set_size(&mut self, new_len: i32) {
178        unsafe {
179            ffi::pango_glyph_string_set_size(self.to_glib_none_mut().0, new_len);
180        }
181    }
182
183    /// Convert from x offset to character position.
184    ///
185    /// Character positions are computed by dividing up each cluster into
186    /// equal portions. In scripts where positioning within a cluster is
187    /// not allowed (such as Thai), the returned value may not be a valid
188    /// cursor position; the caller must combine the result with the logical
189    /// attributes for the text to compute the valid cursor position.
190    /// ## `text`
191    /// the text for the run
192    /// ## `length`
193    /// the number of bytes (not characters) in text.
194    /// ## `analysis`
195    /// the analysis information return from [`itemize()`][crate::itemize()]
196    /// ## `x_pos`
197    /// the x offset (in Pango units)
198    ///
199    /// # Returns
200    ///
201    ///
202    /// ## `index_`
203    /// location to store calculated byte index
204    ///   within @text
205    ///
206    /// ## `trailing`
207    /// location to store a boolean indicating
208    ///   whether the user clicked on the leading or trailing edge of the
209    ///   character
210    #[doc(alias = "pango_glyph_string_x_to_index")]
211    pub fn x_to_index(&self, text: &str, analysis: &Analysis, x_pos: i32) -> (i32, i32) {
212        let length = text.len() as _;
213        unsafe {
214            let mut index_ = std::mem::MaybeUninit::uninit();
215            let mut trailing = std::mem::MaybeUninit::uninit();
216            ffi::pango_glyph_string_x_to_index(
217                mut_override(self.to_glib_none().0),
218                text.to_glib_none().0,
219                length,
220                mut_override(analysis.to_glib_none().0),
221                x_pos,
222                index_.as_mut_ptr(),
223                trailing.as_mut_ptr(),
224            );
225            (index_.assume_init(), trailing.assume_init())
226        }
227    }
228}
229
230impl Default for GlyphString {
231    fn default() -> Self {
232        Self::new()
233    }
234}
235
236unsafe impl Send for GlyphString {}
237unsafe impl Sync for GlyphString {}