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
// 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::FontFace;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::mem;
use std::ptr;

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.
    ///
    /// # Implements
    ///
    /// [`FontFamilyExt`][trait@crate::prelude::FontFamilyExt]
    #[doc(alias = "PangoFontFamily")]
    pub struct FontFamily(Object<ffi::PangoFontFamily, ffi::PangoFontFamilyClass>);

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

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

/// Trait containing all [`struct@FontFamily`] methods.
///
/// # Implementors
///
/// [`FontFamily`][struct@crate::FontFamily]
pub trait FontFamilyExt: '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(any(feature = "v1_46", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
    #[doc(alias = "pango_font_family_get_face")]
    #[doc(alias = "get_face")]
    fn face(&self, name: Option<&str>) -> Option<FontFace>;

    /// 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) -> Option<glib::GString>;

    /// 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")]
    fn is_monospace(&self) -> bool;

    /// 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(any(feature = "v1_44", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
    #[doc(alias = "pango_font_family_is_variable")]
    fn is_variable(&self) -> bool;

    /// 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` 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>;
}

impl<O: IsA<FontFamily>> FontFamilyExt for O {
    #[cfg(any(feature = "v1_46", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
    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,
            ))
        }
    }

    fn name(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::pango_font_family_get_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn is_monospace(&self) -> bool {
        unsafe {
            from_glib(ffi::pango_font_family_is_monospace(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v1_44", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
    fn is_variable(&self) -> bool {
        unsafe {
            from_glib(ffi::pango_font_family_is_variable(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn list_faces(&self) -> Vec<FontFace> {
        unsafe {
            let mut faces = ptr::null_mut();
            let mut n_faces = 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 usize)
        }
    }
}

impl fmt::Display for FontFamily {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("FontFamily")
    }
}