pango/auto/
font_family.rs1use 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 #[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 unsafe {
107 let f: &F = &*(f as *const F);
108 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
109 }
110 }
111 unsafe {
112 let f: Box_<F> = Box_::new(f);
113 connect_raw(
114 self.as_ptr() as *mut _,
115 c"notify::is-monospace".as_ptr(),
116 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
117 notify_is_monospace_trampoline::<Self, F> as *const (),
118 )),
119 Box_::into_raw(f),
120 )
121 }
122 }
123
124 #[cfg(feature = "v1_52")]
125 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
126 #[doc(alias = "is-variable")]
127 fn connect_is_variable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
128 unsafe extern "C" fn notify_is_variable_trampoline<
129 P: IsA<FontFamily>,
130 F: Fn(&P) + 'static,
131 >(
132 this: *mut ffi::PangoFontFamily,
133 _param_spec: glib::ffi::gpointer,
134 f: glib::ffi::gpointer,
135 ) {
136 unsafe {
137 let f: &F = &*(f as *const F);
138 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
139 }
140 }
141 unsafe {
142 let f: Box_<F> = Box_::new(f);
143 connect_raw(
144 self.as_ptr() as *mut _,
145 c"notify::is-variable".as_ptr(),
146 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
147 notify_is_variable_trampoline::<Self, F> as *const (),
148 )),
149 Box_::into_raw(f),
150 )
151 }
152 }
153
154 #[cfg(feature = "v1_52")]
155 #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
156 #[doc(alias = "name")]
157 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
158 unsafe extern "C" fn notify_name_trampoline<P: IsA<FontFamily>, F: Fn(&P) + 'static>(
159 this: *mut ffi::PangoFontFamily,
160 _param_spec: glib::ffi::gpointer,
161 f: glib::ffi::gpointer,
162 ) {
163 unsafe {
164 let f: &F = &*(f as *const F);
165 f(FontFamily::from_glib_borrow(this).unsafe_cast_ref())
166 }
167 }
168 unsafe {
169 let f: Box_<F> = Box_::new(f);
170 connect_raw(
171 self.as_ptr() as *mut _,
172 c"notify::name".as_ptr(),
173 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
174 notify_name_trampoline::<Self, F> as *const (),
175 )),
176 Box_::into_raw(f),
177 )
178 }
179 }
180}
181
182impl<O: IsA<FontFamily>> FontFamilyExt for O {}