pango/auto/
font_family.rs1use 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 #[doc(alias = "PangoFontFamily")]
16 pub struct FontFamily(Object<ffi::PangoFontFamily, ffi::PangoFontFamilyClass>) @implements gio::ListModel;
17
18 match fn {
19 type_ => || ffi::pango_font_family_get_type(),
20 }
21}
22
23impl FontFamily {
24 pub const NONE: Option<&'static FontFamily> = None;
25}
26
27impl std::fmt::Display for FontFamily {
28 #[inline]
29 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
30 f.write_str(&FontFamilyExt::name(self))
31 }
32}
33
34pub trait FontFamilyExt: IsA<FontFamily> + 'static {
35 #[cfg(feature = "v1_46")]
36 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
37 #[doc(alias = "pango_font_family_get_face")]
38 #[doc(alias = "get_face")]
39 fn face(&self, name: Option<&str>) -> Option<FontFace> {
40 unsafe {
41 from_glib_none(ffi::pango_font_family_get_face(
42 self.as_ref().to_glib_none().0,
43 name.to_glib_none().0,
44 ))
45 }
46 }
47
48 #[doc(alias = "pango_font_family_get_name")]
49 #[doc(alias = "get_name")]
50 fn name(&self) -> glib::GString {
51 unsafe {
52 from_glib_none(ffi::pango_font_family_get_name(
53 self.as_ref().to_glib_none().0,
54 ))
55 }
56 }
57
58 #[doc(alias = "pango_font_family_is_monospace")]
59 #[doc(alias = "is-monospace")]
60 fn is_monospace(&self) -> bool {
61 unsafe {
62 from_glib(ffi::pango_font_family_is_monospace(
63 self.as_ref().to_glib_none().0,
64 ))
65 }
66 }
67
68 #[cfg(feature = "v1_44")]
69 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
70 #[doc(alias = "pango_font_family_is_variable")]
71 #[doc(alias = "is-variable")]
72 fn is_variable(&self) -> bool {
73 unsafe {
74 from_glib(ffi::pango_font_family_is_variable(
75 self.as_ref().to_glib_none().0,
76 ))
77 }
78 }
79
80 #[doc(alias = "pango_font_family_list_faces")]
81 fn list_faces(&self) -> Vec<FontFace> {
82 unsafe {
83 let mut faces = std::ptr::null_mut();
84 let mut n_faces = std::mem::MaybeUninit::uninit();
85 ffi::pango_font_family_list_faces(
86 self.as_ref().to_glib_none().0,
87 &mut faces,
88 n_faces.as_mut_ptr(),
89 );
90 FromGlibContainer::from_glib_container_num(faces, n_faces.assume_init() as _)
91 }
92 }
93
94 #[cfg(feature = "v1_52")]
95 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
96 #[doc(alias = "is-monospace")]
97 fn connect_is_monospace_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
98 unsafe extern "C" fn notify_is_monospace_trampoline<
99 P: IsA<FontFamily>,
100 F: Fn(&P) + 'static,
101 >(
102 this: *mut ffi::PangoFontFamily,
103 _param_spec: glib::ffi::gpointer,
104 f: glib::ffi::gpointer,
105 ) {
106 let f: &F = &*(f as *const F);
107 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
108 }
109 unsafe {
110 let f: Box_<F> = Box_::new(f);
111 connect_raw(
112 self.as_ptr() as *mut _,
113 c"notify::is-monospace".as_ptr() as *const _,
114 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
115 notify_is_monospace_trampoline::<Self, F> as *const (),
116 )),
117 Box_::into_raw(f),
118 )
119 }
120 }
121
122 #[cfg(feature = "v1_52")]
123 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
124 #[doc(alias = "is-variable")]
125 fn connect_is_variable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
126 unsafe extern "C" fn notify_is_variable_trampoline<
127 P: IsA<FontFamily>,
128 F: Fn(&P) + 'static,
129 >(
130 this: *mut ffi::PangoFontFamily,
131 _param_spec: glib::ffi::gpointer,
132 f: glib::ffi::gpointer,
133 ) {
134 let f: &F = &*(f as *const F);
135 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
136 }
137 unsafe {
138 let f: Box_<F> = Box_::new(f);
139 connect_raw(
140 self.as_ptr() as *mut _,
141 c"notify::is-variable".as_ptr() as *const _,
142 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
143 notify_is_variable_trampoline::<Self, F> as *const (),
144 )),
145 Box_::into_raw(f),
146 )
147 }
148 }
149
150 #[cfg(feature = "v1_52")]
151 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
152 #[doc(alias = "name")]
153 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
154 unsafe extern "C" fn notify_name_trampoline<P: IsA<FontFamily>, F: Fn(&P) + 'static>(
155 this: *mut ffi::PangoFontFamily,
156 _param_spec: glib::ffi::gpointer,
157 f: glib::ffi::gpointer,
158 ) {
159 let f: &F = &*(f as *const F);
160 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
161 }
162 unsafe {
163 let f: Box_<F> = Box_::new(f);
164 connect_raw(
165 self.as_ptr() as *mut _,
166 c"notify::name".as_ptr() as *const _,
167 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
168 notify_name_trampoline::<Self, F> as *const (),
169 )),
170 Box_::into_raw(f),
171 )
172 }
173 }
174}
175
176impl<O: IsA<FontFamily>> FontFamilyExt for O {}