pango/auto/
context.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 glib::object::IsA;
6use glib::translate::*;
7use pango_sys;
8use std::fmt;
9use std::mem;
10use std::ptr;
11use Direction;
12use Font;
13use FontDescription;
14use FontFamily;
15use FontMap;
16use FontMetrics;
17use Fontset;
18use Gravity;
19use GravityHint;
20use Language;
21use Matrix;
22
23glib_wrapper! {
24    pub struct Context(Object<pango_sys::PangoContext, pango_sys::PangoContextClass, ContextClass>);
25
26    match fn {
27        get_type => || pango_sys::pango_context_get_type(),
28    }
29}
30
31impl Context {
32    pub fn new() -> Context {
33        unsafe { from_glib_full(pango_sys::pango_context_new()) }
34    }
35
36    pub fn changed(&self) {
37        unsafe {
38            pango_sys::pango_context_changed(self.to_glib_none().0);
39        }
40    }
41
42    pub fn get_base_dir(&self) -> Direction {
43        unsafe { from_glib(pango_sys::pango_context_get_base_dir(self.to_glib_none().0)) }
44    }
45
46    pub fn get_base_gravity(&self) -> Gravity {
47        unsafe {
48            from_glib(pango_sys::pango_context_get_base_gravity(
49                self.to_glib_none().0,
50            ))
51        }
52    }
53
54    pub fn get_font_description(&self) -> Option<FontDescription> {
55        unsafe {
56            from_glib_none(pango_sys::pango_context_get_font_description(
57                self.to_glib_none().0,
58            ))
59        }
60    }
61
62    pub fn get_font_map(&self) -> Option<FontMap> {
63        unsafe { from_glib_none(pango_sys::pango_context_get_font_map(self.to_glib_none().0)) }
64    }
65
66    pub fn get_gravity(&self) -> Gravity {
67        unsafe { from_glib(pango_sys::pango_context_get_gravity(self.to_glib_none().0)) }
68    }
69
70    pub fn get_gravity_hint(&self) -> GravityHint {
71        unsafe {
72            from_glib(pango_sys::pango_context_get_gravity_hint(
73                self.to_glib_none().0,
74            ))
75        }
76    }
77
78    pub fn get_language(&self) -> Option<Language> {
79        unsafe { from_glib_full(pango_sys::pango_context_get_language(self.to_glib_none().0)) }
80    }
81
82    pub fn get_matrix(&self) -> Option<Matrix> {
83        unsafe { from_glib_none(pango_sys::pango_context_get_matrix(self.to_glib_none().0)) }
84    }
85
86    pub fn get_metrics(
87        &self,
88        desc: Option<&FontDescription>,
89        language: Option<&Language>,
90    ) -> Option<FontMetrics> {
91        unsafe {
92            from_glib_full(pango_sys::pango_context_get_metrics(
93                self.to_glib_none().0,
94                desc.to_glib_none().0,
95                mut_override(language.to_glib_none().0),
96            ))
97        }
98    }
99
100    pub fn get_serial(&self) -> u32 {
101        unsafe { pango_sys::pango_context_get_serial(self.to_glib_none().0) }
102    }
103
104    pub fn list_families(&self) -> Vec<FontFamily> {
105        unsafe {
106            let mut families = ptr::null_mut();
107            let mut n_families = mem::uninitialized();
108            pango_sys::pango_context_list_families(
109                self.to_glib_none().0,
110                &mut families,
111                &mut n_families,
112            );
113            FromGlibContainer::from_glib_container_num(families, n_families as usize)
114        }
115    }
116
117    pub fn load_font(&self, desc: &FontDescription) -> Option<Font> {
118        unsafe {
119            from_glib_full(pango_sys::pango_context_load_font(
120                self.to_glib_none().0,
121                desc.to_glib_none().0,
122            ))
123        }
124    }
125
126    pub fn load_fontset(&self, desc: &FontDescription, language: &Language) -> Option<Fontset> {
127        unsafe {
128            from_glib_full(pango_sys::pango_context_load_fontset(
129                self.to_glib_none().0,
130                desc.to_glib_none().0,
131                mut_override(language.to_glib_none().0),
132            ))
133        }
134    }
135
136    pub fn set_base_dir(&self, direction: Direction) {
137        unsafe {
138            pango_sys::pango_context_set_base_dir(self.to_glib_none().0, direction.to_glib());
139        }
140    }
141
142    pub fn set_base_gravity(&self, gravity: Gravity) {
143        unsafe {
144            pango_sys::pango_context_set_base_gravity(self.to_glib_none().0, gravity.to_glib());
145        }
146    }
147
148    pub fn set_font_description(&self, desc: &FontDescription) {
149        unsafe {
150            pango_sys::pango_context_set_font_description(
151                self.to_glib_none().0,
152                desc.to_glib_none().0,
153            );
154        }
155    }
156
157    pub fn set_font_map<P: IsA<FontMap>>(&self, font_map: &P) {
158        unsafe {
159            pango_sys::pango_context_set_font_map(
160                self.to_glib_none().0,
161                font_map.as_ref().to_glib_none().0,
162            );
163        }
164    }
165
166    pub fn set_gravity_hint(&self, hint: GravityHint) {
167        unsafe {
168            pango_sys::pango_context_set_gravity_hint(self.to_glib_none().0, hint.to_glib());
169        }
170    }
171
172    pub fn set_language(&self, language: &Language) {
173        unsafe {
174            pango_sys::pango_context_set_language(
175                self.to_glib_none().0,
176                mut_override(language.to_glib_none().0),
177            );
178        }
179    }
180
181    pub fn set_matrix(&self, matrix: Option<&Matrix>) {
182        unsafe {
183            pango_sys::pango_context_set_matrix(self.to_glib_none().0, matrix.to_glib_none().0);
184        }
185    }
186}
187
188impl Default for Context {
189    fn default() -> Self {
190        Self::new()
191    }
192}
193
194impl fmt::Display for Context {
195    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
196        write!(f, "Context")
197    }
198}