pango/auto/
glyph_string.rs1use crate::{ffi, Analysis, Font, Rectangle};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10 pub struct GlyphString(Boxed<ffi::PangoGlyphString>);
11
12 match fn {
13 copy => |ptr| ffi::pango_glyph_string_copy(mut_override(ptr)),
14 free => |ptr| ffi::pango_glyph_string_free(ptr),
15 type_ => || ffi::pango_glyph_string_get_type(),
16 }
17}
18
19impl GlyphString {
20 #[doc(alias = "pango_glyph_string_new")]
21 pub fn new() -> GlyphString {
22 unsafe { from_glib_full(ffi::pango_glyph_string_new()) }
23 }
24
25 #[doc(alias = "pango_glyph_string_extents")]
26 pub fn extents(&mut self, font: &impl IsA<Font>) -> (Rectangle, Rectangle) {
27 unsafe {
28 let mut ink_rect = Rectangle::uninitialized();
29 let mut logical_rect = Rectangle::uninitialized();
30 ffi::pango_glyph_string_extents(
31 self.to_glib_none_mut().0,
32 font.as_ref().to_glib_none().0,
33 ink_rect.to_glib_none_mut().0,
34 logical_rect.to_glib_none_mut().0,
35 );
36 (ink_rect, logical_rect)
37 }
38 }
39
40 #[doc(alias = "pango_glyph_string_extents_range")]
41 pub fn extents_range(
42 &mut self,
43 start: i32,
44 end: i32,
45 font: &impl IsA<Font>,
46 ) -> (Rectangle, Rectangle) {
47 unsafe {
48 let mut ink_rect = Rectangle::uninitialized();
49 let mut logical_rect = Rectangle::uninitialized();
50 ffi::pango_glyph_string_extents_range(
51 self.to_glib_none_mut().0,
52 start,
53 end,
54 font.as_ref().to_glib_none().0,
55 ink_rect.to_glib_none_mut().0,
56 logical_rect.to_glib_none_mut().0,
57 );
58 (ink_rect, logical_rect)
59 }
60 }
61
62 #[doc(alias = "pango_glyph_string_get_width")]
63 #[doc(alias = "get_width")]
64 pub fn width(&self) -> i32 {
65 unsafe { ffi::pango_glyph_string_get_width(mut_override(self.to_glib_none().0)) }
66 }
67
68 #[doc(alias = "pango_glyph_string_index_to_x")]
69 pub fn index_to_x(&self, text: &str, analysis: &Analysis, index_: i32, trailing: bool) -> i32 {
70 let length = text.len() as _;
71 unsafe {
72 let mut x_pos = std::mem::MaybeUninit::uninit();
73 ffi::pango_glyph_string_index_to_x(
74 mut_override(self.to_glib_none().0),
75 text.to_glib_none().0,
76 length,
77 mut_override(analysis.to_glib_none().0),
78 index_,
79 trailing.into_glib(),
80 x_pos.as_mut_ptr(),
81 );
82 x_pos.assume_init()
83 }
84 }
85
86 #[doc(alias = "pango_glyph_string_set_size")]
94 pub fn set_size(&mut self, new_len: i32) {
95 unsafe {
96 ffi::pango_glyph_string_set_size(self.to_glib_none_mut().0, new_len);
97 }
98 }
99
100 #[doc(alias = "pango_glyph_string_x_to_index")]
101 pub fn x_to_index(&self, text: &str, analysis: &Analysis, x_pos: i32) -> (i32, i32) {
102 let length = text.len() as _;
103 unsafe {
104 let mut index_ = std::mem::MaybeUninit::uninit();
105 let mut trailing = std::mem::MaybeUninit::uninit();
106 ffi::pango_glyph_string_x_to_index(
107 mut_override(self.to_glib_none().0),
108 text.to_glib_none().0,
109 length,
110 mut_override(analysis.to_glib_none().0),
111 x_pos,
112 index_.as_mut_ptr(),
113 trailing.as_mut_ptr(),
114 );
115 (index_.assume_init(), trailing.assume_init())
116 }
117 }
118}
119
120impl Default for GlyphString {
121 fn default() -> Self {
122 Self::new()
123 }
124}
125
126unsafe impl Send for GlyphString {}
127unsafe impl Sync for GlyphString {}