pango/auto/font_family.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 crate::{FontFace, ffi};
6#[cfg(feature = "v1_52")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
8use glib::signal::{SignalHandlerId, connect_raw};
9use glib::{prelude::*, translate::*};
10#[cfg(feature = "v1_52")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// A [`FontFamily`][crate::FontFamily] is used to represent a family of related
16 /// font faces.
17 ///
18 /// The font faces in a family share a common design, but differ in
19 /// slant, weight, width or other aspects.
20 ///
21 /// This is an Abstract Base Class, you cannot instantiate it.
22 ///
23 /// ## Properties
24 ///
25 ///
26 /// #### `is-monospace`
27 /// Is this a monospace font
28 ///
29 /// Readable
30 ///
31 ///
32 /// #### `is-variable`
33 /// Is this a variable font
34 ///
35 /// Readable
36 ///
37 ///
38 /// #### `item-type`
39 /// The type of items contained in this list.
40 ///
41 /// Readable
42 ///
43 ///
44 /// #### `n-items`
45 /// The number of items contained in this list.
46 ///
47 /// Readable
48 ///
49 ///
50 /// #### `name`
51 /// The name of the family
52 ///
53 /// Readable
54 ///
55 /// # Implements
56 ///
57 /// [`FontFamilyExt`][trait@crate::prelude::FontFamilyExt], [`trait@gio::prelude::ListModelExt`]
58 #[doc(alias = "PangoFontFamily")]
59 pub struct FontFamily(Object<ffi::PangoFontFamily, ffi::PangoFontFamilyClass>) @implements gio::ListModel;
60
61 match fn {
62 type_ => || ffi::pango_font_family_get_type(),
63 }
64}
65
66impl FontFamily {
67 pub const NONE: Option<&'static FontFamily> = None;
68}
69
70impl std::fmt::Display for FontFamily {
71 #[inline]
72 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
73 f.write_str(&FontFamilyExt::name(self))
74 }
75}
76
77/// Trait containing all [`struct@FontFamily`] methods.
78///
79/// # Implementors
80///
81/// [`FontFamily`][struct@crate::FontFamily]
82pub trait FontFamilyExt: IsA<FontFamily> + 'static {
83 /// Gets the [`FontFace`][crate::FontFace] of @self with the given name.
84 /// ## `name`
85 /// the name of a face. If the name is [`None`],
86 /// the family's default face (fontconfig calls it "Regular")
87 /// will be returned.
88 ///
89 /// # Returns
90 ///
91 /// the [`FontFace`][crate::FontFace],
92 /// or [`None`] if no face with the given name exists.
93 #[cfg(feature = "v1_46")]
94 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
95 #[doc(alias = "pango_font_family_get_face")]
96 #[doc(alias = "get_face")]
97 fn face(&self, name: Option<&str>) -> Option<FontFace> {
98 unsafe {
99 from_glib_none(ffi::pango_font_family_get_face(
100 self.as_ref().to_glib_none().0,
101 name.to_glib_none().0,
102 ))
103 }
104 }
105
106 /// Gets the name of the family.
107 ///
108 /// The name is unique among all fonts for the font backend and can
109 /// be used in a [`FontDescription`][crate::FontDescription] to specify that a face from
110 /// this family is desired.
111 ///
112 /// # Returns
113 ///
114 /// the name of the family. This string is owned
115 /// by the family object and must not be modified or freed.
116 #[doc(alias = "pango_font_family_get_name")]
117 #[doc(alias = "get_name")]
118 fn name(&self) -> glib::GString {
119 unsafe {
120 from_glib_none(ffi::pango_font_family_get_name(
121 self.as_ref().to_glib_none().0,
122 ))
123 }
124 }
125
126 /// A monospace font is a font designed for text display where the the
127 /// characters form a regular grid.
128 ///
129 /// For Western languages this would
130 /// mean that the advance width of all characters are the same, but
131 /// this categorization also includes Asian fonts which include
132 /// double-width characters: characters that occupy two grid cells.
133 /// g_unichar_iswide() returns a result that indicates whether a
134 /// character is typically double-width in a monospace font.
135 ///
136 /// The best way to find out the grid-cell size is to call
137 /// [`FontMetrics::approximate_digit_width()`][crate::FontMetrics::approximate_digit_width()], since the
138 /// results of [`FontMetrics::approximate_char_width()`][crate::FontMetrics::approximate_char_width()] may
139 /// be affected by double-width characters.
140 ///
141 /// # Returns
142 ///
143 /// [`true`] if the family is monospace.
144 #[doc(alias = "pango_font_family_is_monospace")]
145 #[doc(alias = "is-monospace")]
146 fn is_monospace(&self) -> bool {
147 unsafe {
148 from_glib(ffi::pango_font_family_is_monospace(
149 self.as_ref().to_glib_none().0,
150 ))
151 }
152 }
153
154 /// A variable font is a font which has axes that can be modified to
155 /// produce different faces.
156 ///
157 /// Such axes are also known as _variations_; see
158 /// [`FontDescription::set_variations()`][crate::FontDescription::set_variations()] for more information.
159 ///
160 /// # Returns
161 ///
162 /// [`true`] if the family is variable
163 #[cfg(feature = "v1_44")]
164 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
165 #[doc(alias = "pango_font_family_is_variable")]
166 #[doc(alias = "is-variable")]
167 fn is_variable(&self) -> bool {
168 unsafe {
169 from_glib(ffi::pango_font_family_is_variable(
170 self.as_ref().to_glib_none().0,
171 ))
172 }
173 }
174
175 /// Lists the different font faces that make up @self.
176 ///
177 /// The faces in a family share a common design, but differ in slant, weight,
178 /// width and other aspects.
179 ///
180 /// Note that the returned faces are not in any particular order, and
181 /// multiple faces may have the same name or characteristics.
182 ///
183 /// [`FontFamily`][crate::FontFamily] also implemented the [`gio::ListModel`][crate::gio::ListModel] interface
184 /// for enumerating faces.
185 ///
186 /// # Returns
187 ///
188 ///
189 /// ## `faces`
190 ///
191 /// location to store an array of pointers to [`FontFace`][crate::FontFace] objects,
192 /// or [`None`]. This array should be freed with g_free() when it is no
193 /// longer needed.
194 #[doc(alias = "pango_font_family_list_faces")]
195 fn list_faces(&self) -> Vec<FontFace> {
196 unsafe {
197 let mut faces = std::ptr::null_mut();
198 let mut n_faces = std::mem::MaybeUninit::uninit();
199 ffi::pango_font_family_list_faces(
200 self.as_ref().to_glib_none().0,
201 &mut faces,
202 n_faces.as_mut_ptr(),
203 );
204 FromGlibContainer::from_glib_container_num(faces, n_faces.assume_init() as _)
205 }
206 }
207
208 #[cfg(feature = "v1_52")]
209 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
210 #[doc(alias = "is-monospace")]
211 fn connect_is_monospace_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
212 unsafe extern "C" fn notify_is_monospace_trampoline<
213 P: IsA<FontFamily>,
214 F: Fn(&P) + 'static,
215 >(
216 this: *mut ffi::PangoFontFamily,
217 _param_spec: glib::ffi::gpointer,
218 f: glib::ffi::gpointer,
219 ) {
220 unsafe {
221 let f: &F = &*(f as *const F);
222 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
223 }
224 }
225 unsafe {
226 let f: Box_<F> = Box_::new(f);
227 connect_raw(
228 self.as_ptr() as *mut _,
229 c"notify::is-monospace".as_ptr() as *const _,
230 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
231 notify_is_monospace_trampoline::<Self, F> as *const (),
232 )),
233 Box_::into_raw(f),
234 )
235 }
236 }
237
238 #[cfg(feature = "v1_52")]
239 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
240 #[doc(alias = "is-variable")]
241 fn connect_is_variable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
242 unsafe extern "C" fn notify_is_variable_trampoline<
243 P: IsA<FontFamily>,
244 F: Fn(&P) + 'static,
245 >(
246 this: *mut ffi::PangoFontFamily,
247 _param_spec: glib::ffi::gpointer,
248 f: glib::ffi::gpointer,
249 ) {
250 unsafe {
251 let f: &F = &*(f as *const F);
252 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
253 }
254 }
255 unsafe {
256 let f: Box_<F> = Box_::new(f);
257 connect_raw(
258 self.as_ptr() as *mut _,
259 c"notify::is-variable".as_ptr() as *const _,
260 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261 notify_is_variable_trampoline::<Self, F> as *const (),
262 )),
263 Box_::into_raw(f),
264 )
265 }
266 }
267
268 #[cfg(feature = "v1_52")]
269 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
270 #[doc(alias = "name")]
271 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
272 unsafe extern "C" fn notify_name_trampoline<P: IsA<FontFamily>, F: Fn(&P) + 'static>(
273 this: *mut ffi::PangoFontFamily,
274 _param_spec: glib::ffi::gpointer,
275 f: glib::ffi::gpointer,
276 ) {
277 unsafe {
278 let f: &F = &*(f as *const F);
279 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
280 }
281 }
282 unsafe {
283 let f: Box_<F> = Box_::new(f);
284 connect_raw(
285 self.as_ptr() as *mut _,
286 c"notify::name".as_ptr() as *const _,
287 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
288 notify_name_trampoline::<Self, F> as *const (),
289 )),
290 Box_::into_raw(f),
291 )
292 }
293 }
294}
295
296impl<O: IsA<FontFamily>> FontFamilyExt for O {}