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