1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib::object::IsA;
use glib::translate::*;
use pango_sys;
use std::fmt;
use std::mem;
use std::ptr;
use Direction;
use Font;
use FontDescription;
use FontFamily;
use FontMap;
use FontMetrics;
use Fontset;
use Gravity;
use GravityHint;
use Language;
use Matrix;

glib_wrapper! {
    pub struct Context(Object<pango_sys::PangoContext, pango_sys::PangoContextClass, ContextClass>);

    match fn {
        get_type => || pango_sys::pango_context_get_type(),
    }
}

impl Context {
    pub fn new() -> Context {
        unsafe { from_glib_full(pango_sys::pango_context_new()) }
    }

    pub fn changed(&self) {
        unsafe {
            pango_sys::pango_context_changed(self.to_glib_none().0);
        }
    }

    pub fn get_base_dir(&self) -> Direction {
        unsafe { from_glib(pango_sys::pango_context_get_base_dir(self.to_glib_none().0)) }
    }

    pub fn get_base_gravity(&self) -> Gravity {
        unsafe {
            from_glib(pango_sys::pango_context_get_base_gravity(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_font_description(&self) -> Option<FontDescription> {
        unsafe {
            from_glib_none(pango_sys::pango_context_get_font_description(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_font_map(&self) -> Option<FontMap> {
        unsafe { from_glib_none(pango_sys::pango_context_get_font_map(self.to_glib_none().0)) }
    }

    pub fn get_gravity(&self) -> Gravity {
        unsafe { from_glib(pango_sys::pango_context_get_gravity(self.to_glib_none().0)) }
    }

    pub fn get_gravity_hint(&self) -> GravityHint {
        unsafe {
            from_glib(pango_sys::pango_context_get_gravity_hint(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_language(&self) -> Option<Language> {
        unsafe { from_glib_full(pango_sys::pango_context_get_language(self.to_glib_none().0)) }
    }

    pub fn get_matrix(&self) -> Option<Matrix> {
        unsafe { from_glib_none(pango_sys::pango_context_get_matrix(self.to_glib_none().0)) }
    }

    pub fn get_metrics(
        &self,
        desc: Option<&FontDescription>,
        language: Option<&Language>,
    ) -> Option<FontMetrics> {
        unsafe {
            from_glib_full(pango_sys::pango_context_get_metrics(
                self.to_glib_none().0,
                desc.to_glib_none().0,
                mut_override(language.to_glib_none().0),
            ))
        }
    }

    #[cfg(any(feature = "v1_44", feature = "dox"))]
    pub fn get_round_glyph_positions(&self) -> bool {
        unsafe {
            from_glib(pango_sys::pango_context_get_round_glyph_positions(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_serial(&self) -> u32 {
        unsafe { pango_sys::pango_context_get_serial(self.to_glib_none().0) }
    }

    pub fn list_families(&self) -> Vec<FontFamily> {
        unsafe {
            let mut families = ptr::null_mut();
            let mut n_families = mem::MaybeUninit::uninit();
            pango_sys::pango_context_list_families(
                self.to_glib_none().0,
                &mut families,
                n_families.as_mut_ptr(),
            );
            FromGlibContainer::from_glib_container_num(families, n_families.assume_init() as usize)
        }
    }

    pub fn load_font(&self, desc: &FontDescription) -> Option<Font> {
        unsafe {
            from_glib_full(pango_sys::pango_context_load_font(
                self.to_glib_none().0,
                desc.to_glib_none().0,
            ))
        }
    }

    pub fn load_fontset(&self, desc: &FontDescription, language: &Language) -> Option<Fontset> {
        unsafe {
            from_glib_full(pango_sys::pango_context_load_fontset(
                self.to_glib_none().0,
                desc.to_glib_none().0,
                mut_override(language.to_glib_none().0),
            ))
        }
    }

    pub fn set_base_dir(&self, direction: Direction) {
        unsafe {
            pango_sys::pango_context_set_base_dir(self.to_glib_none().0, direction.to_glib());
        }
    }

    pub fn set_base_gravity(&self, gravity: Gravity) {
        unsafe {
            pango_sys::pango_context_set_base_gravity(self.to_glib_none().0, gravity.to_glib());
        }
    }

    pub fn set_font_description(&self, desc: &FontDescription) {
        unsafe {
            pango_sys::pango_context_set_font_description(
                self.to_glib_none().0,
                desc.to_glib_none().0,
            );
        }
    }

    pub fn set_font_map<P: IsA<FontMap>>(&self, font_map: &P) {
        unsafe {
            pango_sys::pango_context_set_font_map(
                self.to_glib_none().0,
                font_map.as_ref().to_glib_none().0,
            );
        }
    }

    pub fn set_gravity_hint(&self, hint: GravityHint) {
        unsafe {
            pango_sys::pango_context_set_gravity_hint(self.to_glib_none().0, hint.to_glib());
        }
    }

    pub fn set_language(&self, language: &Language) {
        unsafe {
            pango_sys::pango_context_set_language(
                self.to_glib_none().0,
                mut_override(language.to_glib_none().0),
            );
        }
    }

    pub fn set_matrix(&self, matrix: Option<&Matrix>) {
        unsafe {
            pango_sys::pango_context_set_matrix(self.to_glib_none().0, matrix.to_glib_none().0);
        }
    }

    #[cfg(any(feature = "v1_44", feature = "dox"))]
    pub fn set_round_glyph_positions(&self, round_positions: bool) {
        unsafe {
            pango_sys::pango_context_set_round_glyph_positions(
                self.to_glib_none().0,
                round_positions.to_glib(),
            );
        }
    }
}

impl Default for Context {
    fn default() -> Self {
        Self::new()
    }
}

impl fmt::Display for Context {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Context")
    }
}