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