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
295
// 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 crate::{ffi, FontFace};
#[cfg(feature = "v1_52")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
use glib::signal::{connect_raw, SignalHandlerId};
use glib::{prelude::*, translate::*};
#[cfg(feature = "v1_52")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
use std::boxed::Box as Box_;

glib::wrapper! {
    /// A [`FontFamily`][crate::FontFamily] is used to represent a family of related
    /// font faces.
    ///
    /// The font faces in a family share a common design, but differ in
    /// slant, weight, width or other aspects.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// ## Properties
    ///
    ///
    /// #### `is-monospace`
    ///  Is this a monospace font
    ///
    /// Readable
    ///
    ///
    /// #### `is-variable`
    ///  Is this a variable font
    ///
    /// Readable
    ///
    ///
    /// #### `item-type`
    ///  The type of items contained in this list.
    ///
    /// Readable
    ///
    ///
    /// #### `n-items`
    ///  The number of items contained in this list.
    ///
    /// Readable
    ///
    ///
    /// #### `name`
    ///  The name of the family
    ///
    /// Readable
    ///
    /// # Implements
    ///
    /// [`FontFamilyExt`][trait@crate::prelude::FontFamilyExt], [`trait@gio::prelude::ListModelExt`]
    #[doc(alias = "PangoFontFamily")]
    pub struct FontFamily(Object<ffi::PangoFontFamily, ffi::PangoFontFamilyClass>) @implements gio::ListModel;

    match fn {
        type_ => || ffi::pango_font_family_get_type(),
    }
}

impl FontFamily {
    pub const NONE: Option<&'static FontFamily> = None;
}

impl std::fmt::Display for FontFamily {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(&FontFamilyExt::name(self))
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::FontFamily>> Sealed for T {}
}

/// Trait containing all [`struct@FontFamily`] methods.
///
/// # Implementors
///
/// [`FontFamily`][struct@crate::FontFamily]
pub trait FontFamilyExt: IsA<FontFamily> + sealed::Sealed + 'static {
    /// Gets the [`FontFace`][crate::FontFace] of @self with the given name.
    /// ## `name`
    /// the name of a face. If the name is [`None`],
    ///   the family's default face (fontconfig calls it "Regular")
    ///   will be returned.
    ///
    /// # Returns
    ///
    /// the [`FontFace`][crate::FontFace],
    ///   or [`None`] if no face with the given name exists.
    #[cfg(feature = "v1_46")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
    #[doc(alias = "pango_font_family_get_face")]
    #[doc(alias = "get_face")]
    fn face(&self, name: Option<&str>) -> Option<FontFace> {
        unsafe {
            from_glib_none(ffi::pango_font_family_get_face(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
            ))
        }
    }

    /// Gets the name of the family.
    ///
    /// The name is unique among all fonts for the font backend and can
    /// be used in a [`FontDescription`][crate::FontDescription] to specify that a face from
    /// this family is desired.
    ///
    /// # Returns
    ///
    /// the name of the family. This string is owned
    ///   by the family object and must not be modified or freed.
    #[doc(alias = "pango_font_family_get_name")]
    #[doc(alias = "get_name")]
    fn name(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::pango_font_family_get_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// A monospace font is a font designed for text display where the the
    /// characters form a regular grid.
    ///
    /// For Western languages this would
    /// mean that the advance width of all characters are the same, but
    /// this categorization also includes Asian fonts which include
    /// double-width characters: characters that occupy two grid cells.
    /// g_unichar_iswide() returns a result that indicates whether a
    /// character is typically double-width in a monospace font.
    ///
    /// The best way to find out the grid-cell size is to call
    /// [`FontMetrics::approximate_digit_width()`][crate::FontMetrics::approximate_digit_width()], since the
    /// results of [`FontMetrics::approximate_char_width()`][crate::FontMetrics::approximate_char_width()] may
    /// be affected by double-width characters.
    ///
    /// # Returns
    ///
    /// [`true`] if the family is monospace.
    #[doc(alias = "pango_font_family_is_monospace")]
    #[doc(alias = "is-monospace")]
    fn is_monospace(&self) -> bool {
        unsafe {
            from_glib(ffi::pango_font_family_is_monospace(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// A variable font is a font which has axes that can be modified to
    /// produce different faces.
    ///
    /// Such axes are also known as _variations_; see
    /// [`FontDescription::set_variations()`][crate::FontDescription::set_variations()] for more information.
    ///
    /// # Returns
    ///
    /// [`true`] if the family is variable
    #[cfg(feature = "v1_44")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
    #[doc(alias = "pango_font_family_is_variable")]
    #[doc(alias = "is-variable")]
    fn is_variable(&self) -> bool {
        unsafe {
            from_glib(ffi::pango_font_family_is_variable(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Lists the different font faces that make up @self.
    ///
    /// The faces in a family share a common design, but differ in slant, weight,
    /// width and other aspects.
    ///
    /// Note that the returned faces are not in any particular order, and
    /// multiple faces may have the same name or characteristics.
    ///
    /// [`FontFamily`][crate::FontFamily] also implemented the [`gio::ListModel`][crate::gio::ListModel] interface
    /// for enumerating faces.
    ///
    /// # Returns
    ///
    ///
    /// ## `faces`
    ///
    ///   location to store an array of pointers to [`FontFace`][crate::FontFace] objects,
    ///   or [`None`]. This array should be freed with g_free() when it is no
    ///   longer needed.
    #[doc(alias = "pango_font_family_list_faces")]
    fn list_faces(&self) -> Vec<FontFace> {
        unsafe {
            let mut faces = std::ptr::null_mut();
            let mut n_faces = std::mem::MaybeUninit::uninit();
            ffi::pango_font_family_list_faces(
                self.as_ref().to_glib_none().0,
                &mut faces,
                n_faces.as_mut_ptr(),
            );
            FromGlibContainer::from_glib_container_num(faces, n_faces.assume_init() as _)
        }
    }

    #[cfg(feature = "v1_52")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
    #[doc(alias = "is-monospace")]
    fn connect_is_monospace_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_monospace_trampoline<
            P: IsA<FontFamily>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::PangoFontFamily,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::is-monospace\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_monospace_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_52")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
    #[doc(alias = "is-variable")]
    fn connect_is_variable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_variable_trampoline<
            P: IsA<FontFamily>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::PangoFontFamily,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::is-variable\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_variable_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_52")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
    #[doc(alias = "name")]
    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_name_trampoline<P: IsA<FontFamily>, F: Fn(&P) + 'static>(
            this: *mut ffi::PangoFontFamily,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::name\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<FontFamily>> FontFamilyExt for O {}