pango/auto/
font_description.rs1use crate::{ffi, FontMask, Gravity, Stretch, Style, Variant, Weight};
6use glib::translate::*;
7
8glib::wrapper! {
9 #[derive(Debug, PartialOrd, Ord)]
10 pub struct FontDescription(Boxed<ffi::PangoFontDescription>);
11
12 match fn {
13 copy => |ptr| ffi::pango_font_description_copy(ptr),
14 free => |ptr| ffi::pango_font_description_free(ptr),
15 type_ => || ffi::pango_font_description_get_type(),
16 }
17}
18
19impl FontDescription {
20 #[doc(alias = "pango_font_description_new")]
21 pub fn new() -> FontDescription {
22 unsafe { from_glib_full(ffi::pango_font_description_new()) }
23 }
24
25 #[doc(alias = "pango_font_description_better_match")]
26 pub fn better_match(
27 &self,
28 old_match: Option<&FontDescription>,
29 new_match: &FontDescription,
30 ) -> bool {
31 unsafe {
32 from_glib(ffi::pango_font_description_better_match(
33 self.to_glib_none().0,
34 old_match.to_glib_none().0,
35 new_match.to_glib_none().0,
36 ))
37 }
38 }
39
40 #[doc(alias = "pango_font_description_equal")]
41 fn equal(&self, desc2: &FontDescription) -> bool {
42 unsafe {
43 from_glib(ffi::pango_font_description_equal(
44 self.to_glib_none().0,
45 desc2.to_glib_none().0,
46 ))
47 }
48 }
49
50 #[doc(alias = "pango_font_description_get_family")]
51 #[doc(alias = "get_family")]
52 pub fn family(&self) -> Option<glib::GString> {
53 unsafe {
54 from_glib_none(ffi::pango_font_description_get_family(
55 self.to_glib_none().0,
56 ))
57 }
58 }
59
60 #[cfg(feature = "v1_56")]
61 #[cfg_attr(docsrs, doc(cfg(feature = "v1_56")))]
62 #[doc(alias = "pango_font_description_get_features")]
63 #[doc(alias = "get_features")]
64 pub fn features(&self) -> Option<glib::GString> {
65 unsafe {
66 from_glib_none(ffi::pango_font_description_get_features(
67 self.to_glib_none().0,
68 ))
69 }
70 }
71
72 #[doc(alias = "pango_font_description_get_gravity")]
73 #[doc(alias = "get_gravity")]
74 pub fn gravity(&self) -> Gravity {
75 unsafe {
76 from_glib(ffi::pango_font_description_get_gravity(
77 self.to_glib_none().0,
78 ))
79 }
80 }
81
82 #[doc(alias = "pango_font_description_get_set_fields")]
83 #[doc(alias = "get_set_fields")]
84 pub fn set_fields(&self) -> FontMask {
85 unsafe {
86 from_glib(ffi::pango_font_description_get_set_fields(
87 self.to_glib_none().0,
88 ))
89 }
90 }
91
92 #[doc(alias = "pango_font_description_get_size")]
93 #[doc(alias = "get_size")]
94 pub fn size(&self) -> i32 {
95 unsafe { ffi::pango_font_description_get_size(self.to_glib_none().0) }
96 }
97
98 #[doc(alias = "pango_font_description_get_size_is_absolute")]
99 #[doc(alias = "get_size_is_absolute")]
100 pub fn is_size_absolute(&self) -> bool {
101 unsafe {
102 from_glib(ffi::pango_font_description_get_size_is_absolute(
103 self.to_glib_none().0,
104 ))
105 }
106 }
107
108 #[doc(alias = "pango_font_description_get_stretch")]
109 #[doc(alias = "get_stretch")]
110 pub fn stretch(&self) -> Stretch {
111 unsafe {
112 from_glib(ffi::pango_font_description_get_stretch(
113 self.to_glib_none().0,
114 ))
115 }
116 }
117
118 #[doc(alias = "pango_font_description_get_style")]
119 #[doc(alias = "get_style")]
120 pub fn style(&self) -> Style {
121 unsafe { from_glib(ffi::pango_font_description_get_style(self.to_glib_none().0)) }
122 }
123
124 #[doc(alias = "pango_font_description_get_variant")]
125 #[doc(alias = "get_variant")]
126 pub fn variant(&self) -> Variant {
127 unsafe {
128 from_glib(ffi::pango_font_description_get_variant(
129 self.to_glib_none().0,
130 ))
131 }
132 }
133
134 #[cfg(feature = "v1_42")]
135 #[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
136 #[doc(alias = "pango_font_description_get_variations")]
137 #[doc(alias = "get_variations")]
138 pub fn variations(&self) -> Option<glib::GString> {
139 unsafe {
140 from_glib_none(ffi::pango_font_description_get_variations(
141 self.to_glib_none().0,
142 ))
143 }
144 }
145
146 #[doc(alias = "pango_font_description_get_weight")]
147 #[doc(alias = "get_weight")]
148 pub fn weight(&self) -> Weight {
149 unsafe {
150 from_glib(ffi::pango_font_description_get_weight(
151 self.to_glib_none().0,
152 ))
153 }
154 }
155
156 #[doc(alias = "pango_font_description_hash")]
157 fn hash(&self) -> u32 {
158 unsafe { ffi::pango_font_description_hash(self.to_glib_none().0) }
159 }
160
161 #[doc(alias = "pango_font_description_merge")]
162 pub fn merge(&mut self, desc_to_merge: Option<&FontDescription>, replace_existing: bool) {
163 unsafe {
164 ffi::pango_font_description_merge(
165 self.to_glib_none_mut().0,
166 desc_to_merge.to_glib_none().0,
167 replace_existing.into_glib(),
168 );
169 }
170 }
171
172 #[doc(alias = "pango_font_description_set_absolute_size")]
173 pub fn set_absolute_size(&mut self, size: f64) {
174 unsafe {
175 ffi::pango_font_description_set_absolute_size(self.to_glib_none_mut().0, size);
176 }
177 }
178
179 #[doc(alias = "pango_font_description_set_family")]
180 pub fn set_family(&mut self, family: &str) {
181 unsafe {
182 ffi::pango_font_description_set_family(
183 self.to_glib_none_mut().0,
184 family.to_glib_none().0,
185 );
186 }
187 }
188
189 #[cfg(feature = "v1_56")]
190 #[cfg_attr(docsrs, doc(cfg(feature = "v1_56")))]
191 #[doc(alias = "pango_font_description_set_features")]
192 pub fn set_features(&mut self, features: Option<&str>) {
193 unsafe {
194 ffi::pango_font_description_set_features(
195 self.to_glib_none_mut().0,
196 features.to_glib_none().0,
197 );
198 }
199 }
200
201 #[doc(alias = "pango_font_description_set_gravity")]
202 pub fn set_gravity(&mut self, gravity: Gravity) {
203 unsafe {
204 ffi::pango_font_description_set_gravity(self.to_glib_none_mut().0, gravity.into_glib());
205 }
206 }
207
208 #[doc(alias = "pango_font_description_set_size")]
209 pub fn set_size(&mut self, size: i32) {
210 unsafe {
211 ffi::pango_font_description_set_size(self.to_glib_none_mut().0, size);
212 }
213 }
214
215 #[doc(alias = "pango_font_description_set_stretch")]
216 pub fn set_stretch(&mut self, stretch: Stretch) {
217 unsafe {
218 ffi::pango_font_description_set_stretch(self.to_glib_none_mut().0, stretch.into_glib());
219 }
220 }
221
222 #[doc(alias = "pango_font_description_set_style")]
223 pub fn set_style(&mut self, style: Style) {
224 unsafe {
225 ffi::pango_font_description_set_style(self.to_glib_none_mut().0, style.into_glib());
226 }
227 }
228
229 #[doc(alias = "pango_font_description_set_variant")]
230 pub fn set_variant(&mut self, variant: Variant) {
231 unsafe {
232 ffi::pango_font_description_set_variant(self.to_glib_none_mut().0, variant.into_glib());
233 }
234 }
235
236 #[cfg(feature = "v1_42")]
237 #[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
238 #[doc(alias = "pango_font_description_set_variations")]
239 pub fn set_variations(&mut self, variations: Option<&str>) {
240 unsafe {
241 ffi::pango_font_description_set_variations(
242 self.to_glib_none_mut().0,
243 variations.to_glib_none().0,
244 );
245 }
246 }
247
248 #[doc(alias = "pango_font_description_set_weight")]
249 pub fn set_weight(&mut self, weight: Weight) {
250 unsafe {
251 ffi::pango_font_description_set_weight(self.to_glib_none_mut().0, weight.into_glib());
252 }
253 }
254
255 #[doc(alias = "pango_font_description_to_filename")]
256 pub fn to_filename(&self) -> Option<glib::GString> {
257 unsafe {
258 from_glib_full(ffi::pango_font_description_to_filename(
259 self.to_glib_none().0,
260 ))
261 }
262 }
263
264 #[doc(alias = "pango_font_description_to_string")]
265 #[doc(alias = "to_string")]
266 pub fn to_str(&self) -> glib::GString {
267 unsafe { from_glib_full(ffi::pango_font_description_to_string(self.to_glib_none().0)) }
268 }
269
270 #[doc(alias = "pango_font_description_unset_fields")]
271 pub fn unset_fields(&mut self, to_unset: FontMask) {
272 unsafe {
273 ffi::pango_font_description_unset_fields(
274 self.to_glib_none_mut().0,
275 to_unset.into_glib(),
276 );
277 }
278 }
279
280 #[doc(alias = "pango_font_description_from_string")]
281 pub fn from_string(str: &str) -> FontDescription {
282 unsafe {
283 from_glib_full(ffi::pango_font_description_from_string(
284 str.to_glib_none().0,
285 ))
286 }
287 }
288}
289
290impl Default for FontDescription {
291 fn default() -> Self {
292 Self::new()
293 }
294}
295
296impl PartialEq for FontDescription {
297 #[inline]
298 fn eq(&self, other: &Self) -> bool {
299 self.equal(other)
300 }
301}
302
303impl Eq for FontDescription {}
304
305impl std::fmt::Display for FontDescription {
306 #[inline]
307 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308 f.write_str(&self.to_str())
309 }
310}
311
312impl std::hash::Hash for FontDescription {
313 #[inline]
314 fn hash<H>(&self, state: &mut H)
315 where
316 H: std::hash::Hasher,
317 {
318 std::hash::Hash::hash(&self.hash(), state)
319 }
320}
321
322unsafe impl Send for FontDescription {}
323unsafe impl Sync for FontDescription {}