pango/auto/
font_map.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, Context, Font, FontDescription, FontFamily, Fontset, Language};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    #[doc(alias = "PangoFontMap")]
10    pub struct FontMap(Object<ffi::PangoFontMap, ffi::PangoFontMapClass>) @implements gio::ListModel;
11
12    match fn {
13        type_ => || ffi::pango_font_map_get_type(),
14    }
15}
16
17impl FontMap {
18    pub const NONE: Option<&'static FontMap> = None;
19}
20
21pub trait FontMapExt: IsA<FontMap> + 'static {
22    #[cfg(feature = "v1_56")]
23    #[cfg_attr(docsrs, doc(cfg(feature = "v1_56")))]
24    #[doc(alias = "pango_font_map_add_font_file")]
25    fn add_font_file(&self, filename: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
26        unsafe {
27            let mut error = std::ptr::null_mut();
28            let is_ok = ffi::pango_font_map_add_font_file(
29                self.as_ref().to_glib_none().0,
30                filename.as_ref().to_glib_none().0,
31                &mut error,
32            );
33            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
34            if error.is_null() {
35                Ok(())
36            } else {
37                Err(from_glib_full(error))
38            }
39        }
40    }
41
42    #[doc(alias = "pango_font_map_changed")]
43    fn changed(&self) {
44        unsafe {
45            ffi::pango_font_map_changed(self.as_ref().to_glib_none().0);
46        }
47    }
48
49    #[doc(alias = "pango_font_map_create_context")]
50    fn create_context(&self) -> Context {
51        unsafe {
52            from_glib_full(ffi::pango_font_map_create_context(
53                self.as_ref().to_glib_none().0,
54            ))
55        }
56    }
57
58    #[cfg(feature = "v1_46")]
59    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
60    #[doc(alias = "pango_font_map_get_family")]
61    #[doc(alias = "get_family")]
62    fn family(&self, name: &str) -> FontFamily {
63        unsafe {
64            from_glib_none(ffi::pango_font_map_get_family(
65                self.as_ref().to_glib_none().0,
66                name.to_glib_none().0,
67            ))
68        }
69    }
70
71    #[doc(alias = "pango_font_map_get_serial")]
72    #[doc(alias = "get_serial")]
73    fn serial(&self) -> u32 {
74        unsafe { ffi::pango_font_map_get_serial(self.as_ref().to_glib_none().0) }
75    }
76
77    #[doc(alias = "pango_font_map_list_families")]
78    fn list_families(&self) -> Vec<FontFamily> {
79        unsafe {
80            let mut families = std::ptr::null_mut();
81            let mut n_families = std::mem::MaybeUninit::uninit();
82            ffi::pango_font_map_list_families(
83                self.as_ref().to_glib_none().0,
84                &mut families,
85                n_families.as_mut_ptr(),
86            );
87            FromGlibContainer::from_glib_container_num(families, n_families.assume_init() as _)
88        }
89    }
90
91    #[doc(alias = "pango_font_map_load_font")]
92    fn load_font(&self, context: &Context, desc: &FontDescription) -> Option<Font> {
93        unsafe {
94            from_glib_full(ffi::pango_font_map_load_font(
95                self.as_ref().to_glib_none().0,
96                context.to_glib_none().0,
97                desc.to_glib_none().0,
98            ))
99        }
100    }
101
102    #[doc(alias = "pango_font_map_load_fontset")]
103    fn load_fontset(
104        &self,
105        context: &Context,
106        desc: &FontDescription,
107        language: &Language,
108    ) -> Option<Fontset> {
109        unsafe {
110            from_glib_full(ffi::pango_font_map_load_fontset(
111                self.as_ref().to_glib_none().0,
112                context.to_glib_none().0,
113                desc.to_glib_none().0,
114                mut_override(language.to_glib_none().0),
115            ))
116        }
117    }
118
119    #[cfg(feature = "v1_52")]
120    #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
121    #[doc(alias = "pango_font_map_reload_font")]
122    fn reload_font(
123        &self,
124        font: &impl IsA<Font>,
125        scale: f64,
126        context: Option<&Context>,
127        variations: Option<&str>,
128    ) -> Font {
129        unsafe {
130            from_glib_full(ffi::pango_font_map_reload_font(
131                self.as_ref().to_glib_none().0,
132                font.as_ref().to_glib_none().0,
133                scale,
134                context.to_glib_none().0,
135                variations.to_glib_none().0,
136            ))
137        }
138    }
139}
140
141impl<O: IsA<FontMap>> FontMapExt for O {}