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    /// A [`FontMap`][crate::FontMap] represents the set of fonts available for a
10    /// particular rendering system.
11    ///
12    /// This is a virtual object with implementations being specific to
13    /// particular rendering systems.
14    ///
15    /// This is an Abstract Base Class, you cannot instantiate it.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `item-type`
21    ///  The type of items contained in this list.
22    ///
23    /// Readable
24    ///
25    ///
26    /// #### `n-items`
27    ///  The number of items contained in this list.
28    ///
29    /// Readable
30    ///
31    /// # Implements
32    ///
33    /// [`FontMapExt`][trait@crate::prelude::FontMapExt], [`trait@gio::prelude::ListModelExt`]
34    #[doc(alias = "PangoFontMap")]
35    pub struct FontMap(Object<ffi::PangoFontMap, ffi::PangoFontMapClass>) @implements gio::ListModel;
36
37    match fn {
38        type_ => || ffi::pango_font_map_get_type(),
39    }
40}
41
42impl FontMap {
43    pub const NONE: Option<&'static FontMap> = None;
44}
45
46mod sealed {
47    pub trait Sealed {}
48    impl<T: super::IsA<super::FontMap>> Sealed for T {}
49}
50
51/// Trait containing all [`struct@FontMap`] methods.
52///
53/// # Implementors
54///
55/// [`FontMap`][struct@crate::FontMap]
56pub trait FontMapExt: IsA<FontMap> + sealed::Sealed + 'static {
57    /// Loads a font file with one or more fonts into the [`FontMap`][crate::FontMap].
58    ///
59    /// The added fonts will take precedence over preexisting
60    /// fonts with the same name.
61    /// ## `filename`
62    /// Path to the font file
63    ///
64    /// # Returns
65    ///
66    /// True if the font file is successfully loaded
67    ///     into the fontmap, false if an error occurred.
68    #[cfg(feature = "v1_56")]
69    #[cfg_attr(docsrs, doc(cfg(feature = "v1_56")))]
70    #[doc(alias = "pango_font_map_add_font_file")]
71    fn add_font_file(&self, filename: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
72        unsafe {
73            let mut error = std::ptr::null_mut();
74            let is_ok = ffi::pango_font_map_add_font_file(
75                self.as_ref().to_glib_none().0,
76                filename.as_ref().to_glib_none().0,
77                &mut error,
78            );
79            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
80            if error.is_null() {
81                Ok(())
82            } else {
83                Err(from_glib_full(error))
84            }
85        }
86    }
87
88    /// Forces a change in the context, which will cause any [`Context`][crate::Context]
89    /// using this fontmap to change.
90    ///
91    /// This function is only useful when implementing a new backend
92    /// for Pango, something applications won't do. Backends should
93    /// call this function if they have attached extra data to the
94    /// context and such data is changed.
95    #[doc(alias = "pango_font_map_changed")]
96    fn changed(&self) {
97        unsafe {
98            ffi::pango_font_map_changed(self.as_ref().to_glib_none().0);
99        }
100    }
101
102    /// Creates a [`Context`][crate::Context] connected to @self.
103    ///
104    /// This is equivalent to [`Context::new()`][crate::Context::new()] followed by
105    /// [`Context::set_font_map()`][crate::Context::set_font_map()].
106    ///
107    /// If you are using Pango as part of a higher-level system,
108    /// that system may have it's own way of create a [`Context`][crate::Context].
109    /// For instance, the GTK toolkit has, among others,
110    /// gtk_widget_get_pango_context(). Use those instead.
111    ///
112    /// # Returns
113    ///
114    /// the newly allocated [`Context`][crate::Context],
115    ///   which should be freed with g_object_unref().
116    #[doc(alias = "pango_font_map_create_context")]
117    fn create_context(&self) -> Context {
118        unsafe {
119            from_glib_full(ffi::pango_font_map_create_context(
120                self.as_ref().to_glib_none().0,
121            ))
122        }
123    }
124
125    /// Gets a font family by name.
126    /// ## `name`
127    /// a family name
128    ///
129    /// # Returns
130    ///
131    /// the [`FontFamily`][crate::FontFamily]
132    #[cfg(feature = "v1_46")]
133    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
134    #[doc(alias = "pango_font_map_get_family")]
135    #[doc(alias = "get_family")]
136    fn family(&self, name: &str) -> FontFamily {
137        unsafe {
138            from_glib_none(ffi::pango_font_map_get_family(
139                self.as_ref().to_glib_none().0,
140                name.to_glib_none().0,
141            ))
142        }
143    }
144
145    /// Returns the current serial number of @self.
146    ///
147    /// The serial number is initialized to an small number larger than zero
148    /// when a new fontmap is created and is increased whenever the fontmap
149    /// is changed. It may wrap, but will never have the value 0. Since it can
150    /// wrap, never compare it with "less than", always use "not equals".
151    ///
152    /// The fontmap can only be changed using backend-specific API, like changing
153    /// fontmap resolution.
154    ///
155    /// This can be used to automatically detect changes to a [`FontMap`][crate::FontMap],
156    /// like in [`Context`][crate::Context].
157    ///
158    /// # Returns
159    ///
160    /// The current serial number of @self.
161    #[doc(alias = "pango_font_map_get_serial")]
162    #[doc(alias = "get_serial")]
163    fn serial(&self) -> u32 {
164        unsafe { ffi::pango_font_map_get_serial(self.as_ref().to_glib_none().0) }
165    }
166
167    /// List all families for a fontmap.
168    ///
169    /// Note that the returned families are not in any particular order.
170    ///
171    /// [`FontMap`][crate::FontMap] also implemented the [`gio::ListModel`][crate::gio::ListModel] interface
172    /// for enumerating families.
173    ///
174    /// # Returns
175    ///
176    ///
177    /// ## `families`
178    /// location to
179    ///   store a pointer to an array of [`FontFamily`][crate::FontFamily] *.
180    ///   This array should be freed with g_free().
181    #[doc(alias = "pango_font_map_list_families")]
182    fn list_families(&self) -> Vec<FontFamily> {
183        unsafe {
184            let mut families = std::ptr::null_mut();
185            let mut n_families = std::mem::MaybeUninit::uninit();
186            ffi::pango_font_map_list_families(
187                self.as_ref().to_glib_none().0,
188                &mut families,
189                n_families.as_mut_ptr(),
190            );
191            FromGlibContainer::from_glib_container_num(families, n_families.assume_init() as _)
192        }
193    }
194
195    /// Load the font in the fontmap that is the closest match for @desc.
196    /// ## `context`
197    /// the [`Context`][crate::Context] the font will be used with
198    /// ## `desc`
199    /// a [`FontDescription`][crate::FontDescription] describing the font to load
200    ///
201    /// # Returns
202    ///
203    /// the newly allocated [`Font`][crate::Font]
204    ///   loaded, or [`None`] if no font matched.
205    #[doc(alias = "pango_font_map_load_font")]
206    fn load_font(&self, context: &Context, desc: &FontDescription) -> Option<Font> {
207        unsafe {
208            from_glib_full(ffi::pango_font_map_load_font(
209                self.as_ref().to_glib_none().0,
210                context.to_glib_none().0,
211                desc.to_glib_none().0,
212            ))
213        }
214    }
215
216    /// Load a set of fonts in the fontmap that can be used to render
217    /// a font matching @desc.
218    /// ## `context`
219    /// the [`Context`][crate::Context] the font will be used with
220    /// ## `desc`
221    /// a [`FontDescription`][crate::FontDescription] describing the font to load
222    /// ## `language`
223    /// a [`Language`][crate::Language] the fonts will be used for
224    ///
225    /// # Returns
226    ///
227    /// the newly allocated
228    ///   [`Fontset`][crate::Fontset] loaded, or [`None`] if no font matched.
229    #[doc(alias = "pango_font_map_load_fontset")]
230    fn load_fontset(
231        &self,
232        context: &Context,
233        desc: &FontDescription,
234        language: &Language,
235    ) -> Option<Fontset> {
236        unsafe {
237            from_glib_full(ffi::pango_font_map_load_fontset(
238                self.as_ref().to_glib_none().0,
239                context.to_glib_none().0,
240                desc.to_glib_none().0,
241                mut_override(language.to_glib_none().0),
242            ))
243        }
244    }
245
246    /// Returns a new font that is like @font, except that its size
247    /// is multiplied by @scale, its backend-dependent configuration
248    /// (e.g. cairo font options) is replaced by the one in @context,
249    /// and its variations are replaced by @variations.
250    /// ## `font`
251    /// a font in @self
252    /// ## `scale`
253    /// the scale factor to apply
254    /// ## `context`
255    /// a [`Context`][crate::Context]
256    /// ## `variations`
257    /// font variations to use
258    ///
259    /// # Returns
260    ///
261    /// the modified font
262    #[cfg(feature = "v1_52")]
263    #[cfg_attr(docsrs, doc(cfg(feature = "v1_52")))]
264    #[doc(alias = "pango_font_map_reload_font")]
265    fn reload_font(
266        &self,
267        font: &impl IsA<Font>,
268        scale: f64,
269        context: Option<&Context>,
270        variations: Option<&str>,
271    ) -> Font {
272        unsafe {
273            from_glib_full(ffi::pango_font_map_reload_font(
274                self.as_ref().to_glib_none().0,
275                font.as_ref().to_glib_none().0,
276                scale,
277                context.to_glib_none().0,
278                variations.to_glib_none().0,
279            ))
280        }
281    }
282}
283
284impl<O: IsA<FontMap>> FontMapExt for O {}