pangocairo/
font_map.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, translate::*};
4
5use crate::{ffi, FontMap};
6
7mod sealed {
8    pub trait Sealed {}
9    impl<T: super::IsA<super::FontMap>> Sealed for T {}
10}
11
12pub trait PangoCairoFontMapExtManual: sealed::Sealed + IsA<FontMap> + 'static {
13    /// Gets the type of Cairo font backend that @self uses.
14    ///
15    /// # Returns
16    ///
17    /// the [`cairo::FontType`][crate::cairo::FontType] cairo font backend type
18    #[doc(alias = "pango_cairo_font_map_get_font_type")]
19    #[doc(alias = "get_font_type")]
20    fn font_type(&self) -> cairo::FontType {
21        unsafe { ffi::pango_cairo_font_map_get_font_type(self.as_ref().to_glib_none().0).into() }
22    }
23}
24
25impl<O: IsA<FontMap>> PangoCairoFontMapExtManual for O {}
26
27impl FontMap {
28    #[doc(alias = "pango_cairo_font_map_new_for_font_type")]
29    #[doc(alias = "new_for_font_type")]
30    pub fn for_font_type(fonttype: cairo::FontType) -> Option<pango::FontMap> {
31        unsafe { from_glib_full(ffi::pango_cairo_font_map_new_for_font_type(fonttype.into())) }
32    }
33
34    /// Creates a new [`FontMap`][crate::FontMap] object.
35    ///
36    /// A fontmap is used to cache information about available fonts,
37    /// and holds certain global parameters such as the resolution.
38    /// In most cases, you can use `func@PangoCairo.font_map_get_default]
39    /// instead.
40    ///
41    /// Note that the type of the returned object will depend
42    /// on the particular font backend Cairo was compiled to use;
43    /// You generally should only use the [`pango::FontMap`][crate::pango::FontMap] and
44    /// [`FontMap`][crate::FontMap] interfaces on the returned object.
45    ///
46    /// You can override the type of backend returned by using an
47    /// environment variable `PANGOCAIRO_BACKEND`. Supported types,
48    /// based on your build, are fc (fontconfig), win32, and coretext.
49    /// If requested type is not available, NULL is returned. Ie.
50    /// this is only useful for testing, when at least two backends
51    /// are compiled in.
52    ///
53    /// # Returns
54    ///
55    /// the newly allocated [`pango::FontMap`][crate::pango::FontMap],
56    ///   which should be freed with g_object_unref().
57    #[allow(clippy::new_ret_no_self)]
58    #[doc(alias = "pango_cairo_font_map_new")]
59    pub fn new() -> pango::FontMap {
60        unsafe { from_glib_full(ffi::pango_cairo_font_map_new()) }
61    }
62
63    #[doc(alias = "pango_cairo_font_map_set_default")]
64    pub fn set_default(font_map: Option<&Self>) {
65        unsafe {
66            ffi::pango_cairo_font_map_set_default(font_map.as_ref().to_glib_none().0);
67        }
68    }
69}