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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// 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::translate::*;
use glib::GString;
use pango_sys;
use std::fmt;
use std::hash;
use FontMask;
use Gravity;
use Stretch;
use Style;
use Variant;
use Weight;

glib_wrapper! {
    #[derive(Debug, PartialOrd, Ord)]
    pub struct FontDescription(Boxed<pango_sys::PangoFontDescription>);

    match fn {
        copy => |ptr| pango_sys::pango_font_description_copy(mut_override(ptr)),
        free => |ptr| pango_sys::pango_font_description_free(ptr),
        get_type => || pango_sys::pango_font_description_get_type(),
    }
}

impl FontDescription {
    pub fn new() -> FontDescription {
        unsafe { from_glib_full(pango_sys::pango_font_description_new()) }
    }

    pub fn better_match(
        &self,
        old_match: Option<&FontDescription>,
        new_match: &FontDescription,
    ) -> bool {
        unsafe {
            from_glib(pango_sys::pango_font_description_better_match(
                self.to_glib_none().0,
                old_match.to_glib_none().0,
                new_match.to_glib_none().0,
            ))
        }
    }

    fn equal(&self, desc2: &FontDescription) -> bool {
        unsafe {
            from_glib(pango_sys::pango_font_description_equal(
                self.to_glib_none().0,
                desc2.to_glib_none().0,
            ))
        }
    }

    pub fn get_family(&self) -> Option<GString> {
        unsafe {
            from_glib_none(pango_sys::pango_font_description_get_family(
                self.to_glib_none().0,
            ))
        }
    }

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

    pub fn get_set_fields(&self) -> FontMask {
        unsafe {
            from_glib(pango_sys::pango_font_description_get_set_fields(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_size(&self) -> i32 {
        unsafe { pango_sys::pango_font_description_get_size(self.to_glib_none().0) }
    }

    pub fn get_size_is_absolute(&self) -> bool {
        unsafe {
            from_glib(pango_sys::pango_font_description_get_size_is_absolute(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_stretch(&self) -> Stretch {
        unsafe {
            from_glib(pango_sys::pango_font_description_get_stretch(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_style(&self) -> Style {
        unsafe {
            from_glib(pango_sys::pango_font_description_get_style(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_variant(&self) -> Variant {
        unsafe {
            from_glib(pango_sys::pango_font_description_get_variant(
                self.to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v1_42", feature = "dox"))]
    pub fn get_variations(&self) -> Option<GString> {
        unsafe {
            from_glib_none(pango_sys::pango_font_description_get_variations(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn get_weight(&self) -> Weight {
        unsafe {
            from_glib(pango_sys::pango_font_description_get_weight(
                self.to_glib_none().0,
            ))
        }
    }

    fn hash(&self) -> u32 {
        unsafe { pango_sys::pango_font_description_hash(self.to_glib_none().0) }
    }

    pub fn merge(&mut self, desc_to_merge: Option<&FontDescription>, replace_existing: bool) {
        unsafe {
            pango_sys::pango_font_description_merge(
                self.to_glib_none_mut().0,
                desc_to_merge.to_glib_none().0,
                replace_existing.to_glib(),
            );
        }
    }

    pub fn set_absolute_size(&mut self, size: f64) {
        unsafe {
            pango_sys::pango_font_description_set_absolute_size(self.to_glib_none_mut().0, size);
        }
    }

    pub fn set_family(&mut self, family: &str) {
        unsafe {
            pango_sys::pango_font_description_set_family(
                self.to_glib_none_mut().0,
                family.to_glib_none().0,
            );
        }
    }

    pub fn set_gravity(&mut self, gravity: Gravity) {
        unsafe {
            pango_sys::pango_font_description_set_gravity(
                self.to_glib_none_mut().0,
                gravity.to_glib(),
            );
        }
    }

    pub fn set_size(&mut self, size: i32) {
        unsafe {
            pango_sys::pango_font_description_set_size(self.to_glib_none_mut().0, size);
        }
    }

    pub fn set_stretch(&mut self, stretch: Stretch) {
        unsafe {
            pango_sys::pango_font_description_set_stretch(
                self.to_glib_none_mut().0,
                stretch.to_glib(),
            );
        }
    }

    pub fn set_style(&mut self, style: Style) {
        unsafe {
            pango_sys::pango_font_description_set_style(self.to_glib_none_mut().0, style.to_glib());
        }
    }

    pub fn set_variant(&mut self, variant: Variant) {
        unsafe {
            pango_sys::pango_font_description_set_variant(
                self.to_glib_none_mut().0,
                variant.to_glib(),
            );
        }
    }

    #[cfg(any(feature = "v1_42", feature = "dox"))]
    pub fn set_variations(&mut self, variations: &str) {
        unsafe {
            pango_sys::pango_font_description_set_variations(
                self.to_glib_none_mut().0,
                variations.to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v1_42", feature = "dox"))]
    pub fn set_variations_static(&mut self, variations: &str) {
        unsafe {
            pango_sys::pango_font_description_set_variations_static(
                self.to_glib_none_mut().0,
                variations.to_glib_none().0,
            );
        }
    }

    pub fn set_weight(&mut self, weight: Weight) {
        unsafe {
            pango_sys::pango_font_description_set_weight(
                self.to_glib_none_mut().0,
                weight.to_glib(),
            );
        }
    }

    pub fn to_filename(&self) -> Option<GString> {
        unsafe {
            from_glib_full(pango_sys::pango_font_description_to_filename(
                self.to_glib_none().0,
            ))
        }
    }

    fn to_string(&self) -> GString {
        unsafe {
            from_glib_full(pango_sys::pango_font_description_to_string(
                self.to_glib_none().0,
            ))
        }
    }

    pub fn unset_fields(&mut self, to_unset: FontMask) {
        unsafe {
            pango_sys::pango_font_description_unset_fields(
                self.to_glib_none_mut().0,
                to_unset.to_glib(),
            );
        }
    }

    pub fn from_string(str: &str) -> FontDescription {
        unsafe {
            from_glib_full(pango_sys::pango_font_description_from_string(
                str.to_glib_none().0,
            ))
        }
    }
}

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

impl PartialEq for FontDescription {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for FontDescription {}

impl fmt::Display for FontDescription {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.to_string())
    }
}

impl hash::Hash for FontDescription {
    #[inline]
    fn hash<H>(&self, state: &mut H)
    where
        H: hash::Hasher,
    {
        hash::Hash::hash(&self.hash(), state)
    }
}