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