1 // Take a look at the license at the top of the repository in the LICENSE file.
2 
3 use crate::GlyphItem;
4 use crate::GlyphString;
5 use crate::Item;
6 use glib::translate::*;
7 
8 impl GlyphString {
num_glyphs(&self) -> i329     pub fn num_glyphs(&self) -> i32 {
10         unsafe { (*self.to_glib_none().0).num_glyphs }
11     }
12 
glyph_info(&self) -> Vec<GlyphInfo>13     pub fn glyph_info(&self) -> Vec<GlyphInfo> {
14         if self.num_glyphs() < 0 {
15             return Vec::new();
16         }
17         let num_glyphs = self.num_glyphs() as usize;
18         unsafe {
19             let glyphs: *mut ffi::PangoGlyphInfo = (*self.to_glib_none().0).glyphs;
20             FromGlibContainer::from_glib_none_num(glyphs, num_glyphs)
21         }
22     }
23 }
24 
25 impl GlyphItem {
item(&self) -> Item26     pub fn item(&self) -> Item {
27         unsafe { from_glib_none((*self.to_glib_none().0).item) }
28     }
29 
glyph_string(&self) -> GlyphString30     pub fn glyph_string(&self) -> GlyphString {
31         unsafe { from_glib_none((*self.to_glib_none().0).glyphs) }
32     }
33 }
34 
35 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
36 #[doc(alias = "PangoGlyphInfo")]
37 pub struct GlyphInfo(*mut ffi::PangoGlyphInfo);
38 
39 impl GlyphInfo {
glyph(&self) -> u3240     pub fn glyph(&self) -> u32 {
41         unsafe { (*self.0).glyph }
42     }
43 
geometry(&self) -> &GlyphGeometry44     pub fn geometry(&self) -> &GlyphGeometry {
45         unsafe { &*(&((*self.0).geometry) as *const _ as *const GlyphGeometry) }
46     }
47 }
48 
49 impl FromGlibContainerAsVec<*mut ffi::PangoGlyphInfo, *mut ffi::PangoGlyphInfo> for GlyphInfo {
from_glib_none_num_as_vec(ptr: *mut ffi::PangoGlyphInfo, num: usize) -> Vec<Self>50     unsafe fn from_glib_none_num_as_vec(ptr: *mut ffi::PangoGlyphInfo, num: usize) -> Vec<Self> {
51         if num == 0 || ptr.is_null() {
52             return Vec::new();
53         }
54         let mut res = Vec::with_capacity(num);
55         for x in 0..num {
56             res.push(from_glib_none(ptr.add(x)));
57         }
58         res
59     }
60 
from_glib_container_num_as_vec( ptr: *mut ffi::PangoGlyphInfo, num: usize, ) -> Vec<Self>61     unsafe fn from_glib_container_num_as_vec(
62         ptr: *mut ffi::PangoGlyphInfo,
63         num: usize,
64     ) -> Vec<Self> {
65         let res = FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
66         glib::ffi::g_free(ptr as *mut _);
67         res
68     }
69 
from_glib_full_num_as_vec(ptr: *mut ffi::PangoGlyphInfo, num: usize) -> Vec<Self>70     unsafe fn from_glib_full_num_as_vec(ptr: *mut ffi::PangoGlyphInfo, num: usize) -> Vec<Self> {
71         FromGlibContainerAsVec::from_glib_container_num_as_vec(ptr, num)
72     }
73 }
74 impl FromGlibContainerAsVec<*mut ffi::PangoGlyphInfo, *const ffi::PangoGlyphInfo> for GlyphInfo {
from_glib_none_num_as_vec(ptr: *const ffi::PangoGlyphInfo, num: usize) -> Vec<Self>75     unsafe fn from_glib_none_num_as_vec(ptr: *const ffi::PangoGlyphInfo, num: usize) -> Vec<Self> {
76         if num == 0 || ptr.is_null() {
77             return Vec::new();
78         }
79         let mut res = Vec::with_capacity(num);
80         for x in 0..num {
81             res.push(from_glib_none(ptr.add(x)));
82         }
83         res
84     }
85 
from_glib_container_num_as_vec( ptr: *const ffi::PangoGlyphInfo, num: usize, ) -> Vec<Self>86     unsafe fn from_glib_container_num_as_vec(
87         ptr: *const ffi::PangoGlyphInfo,
88         num: usize,
89     ) -> Vec<Self> {
90         let res = FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
91         glib::ffi::g_free(ptr as *mut _);
92         res
93     }
94 
from_glib_full_num_as_vec(ptr: *const ffi::PangoGlyphInfo, num: usize) -> Vec<Self>95     unsafe fn from_glib_full_num_as_vec(ptr: *const ffi::PangoGlyphInfo, num: usize) -> Vec<Self> {
96         FromGlibContainerAsVec::from_glib_container_num_as_vec(ptr, num)
97     }
98 }
99 
100 #[doc(hidden)]
101 impl<'a> ToGlibPtr<'a, *mut ffi::PangoGlyphInfo> for &'a GlyphInfo {
102     type Storage = &'a GlyphInfo;
103 
to_glib_none(&self) -> Stash<'a, *mut ffi::PangoGlyphInfo, Self>104     fn to_glib_none(&self) -> Stash<'a, *mut ffi::PangoGlyphInfo, Self> {
105         Stash(self.0, *self)
106     }
107 }
108 
109 #[doc(hidden)]
110 impl<'a> ToGlibPtrMut<'a, *mut ffi::PangoGlyphInfo> for GlyphInfo {
111     type Storage = &'a mut Self;
112 
113     #[inline]
to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::PangoGlyphInfo, Self>114     fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::PangoGlyphInfo, Self> {
115         StashMut(self.0, self)
116     }
117 }
118 
119 #[doc(hidden)]
120 impl FromGlibPtrNone<*mut ffi::PangoGlyphInfo> for GlyphInfo {
from_glib_none(ptr: *mut ffi::PangoGlyphInfo) -> Self121     unsafe fn from_glib_none(ptr: *mut ffi::PangoGlyphInfo) -> Self {
122         assert!(!ptr.is_null());
123         Self(ptr)
124     }
125 }
126 
127 #[doc(hidden)]
128 impl FromGlibPtrFull<*mut ffi::PangoGlyphInfo> for GlyphInfo {
from_glib_full(ptr: *mut ffi::PangoGlyphInfo) -> Self129     unsafe fn from_glib_full(ptr: *mut ffi::PangoGlyphInfo) -> Self {
130         assert!(!ptr.is_null());
131         Self(ptr)
132     }
133 }
134 
135 #[doc(hidden)]
136 impl FromGlibPtrNone<*const ffi::PangoGlyphInfo> for GlyphInfo {
from_glib_none(ptr: *const ffi::PangoGlyphInfo) -> Self137     unsafe fn from_glib_none(ptr: *const ffi::PangoGlyphInfo) -> Self {
138         assert!(!ptr.is_null());
139         Self(ptr as *mut _)
140     }
141 }
142 
143 #[doc(hidden)]
144 impl FromGlibPtrFull<*const ffi::PangoGlyphInfo> for GlyphInfo {
from_glib_full(ptr: *const ffi::PangoGlyphInfo) -> Self145     unsafe fn from_glib_full(ptr: *const ffi::PangoGlyphInfo) -> Self {
146         assert!(!ptr.is_null());
147         Self(ptr as *mut _)
148     }
149 }
150 
151 #[derive(Clone, Copy, Debug)]
152 #[repr(C)]
153 #[doc(alias = "PangoGlyphGeometry")]
154 pub struct GlyphGeometry(ffi::PangoGlyphGeometry);
155 
156 impl GlyphGeometry {
width(&self) -> i32157     pub fn width(&self) -> i32 {
158         self.0.width
159     }
160 
x_offset(&self) -> i32161     pub fn x_offset(&self) -> i32 {
162         self.0.x_offset
163     }
164 
y_offset(&self) -> i32165     pub fn y_offset(&self) -> i32 {
166         self.0.y_offset
167     }
168 }
169 
170 #[doc(hidden)]
171 impl<'a> ToGlibPtr<'a, *const ffi::PangoGlyphGeometry> for GlyphGeometry {
172     type Storage = &'a Self;
173 
174     #[inline]
to_glib_none(&'a self) -> Stash<'a, *const ffi::PangoGlyphGeometry, Self>175     fn to_glib_none(&'a self) -> Stash<'a, *const ffi::PangoGlyphGeometry, Self> {
176         let ptr: *const ffi::PangoGlyphGeometry = &self.0;
177         Stash(ptr, self)
178     }
179 }
180 
181 #[doc(hidden)]
182 impl FromGlibPtrNone<*const ffi::PangoGlyphGeometry> for GlyphGeometry {
from_glib_none(ptr: *const ffi::PangoGlyphGeometry) -> Self183     unsafe fn from_glib_none(ptr: *const ffi::PangoGlyphGeometry) -> Self {
184         GlyphGeometry(*ptr)
185     }
186 }
187