pangocairo/
font_map.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{prelude::*, translate::*};

use crate::{ffi, FontMap};

pub trait PangoCairoFontMapExtManual: IsA<FontMap> + 'static {
    /// Gets the type of Cairo font backend that @self uses.
    ///
    /// # Returns
    ///
    /// the [`cairo::FontType`][crate::cairo::FontType] cairo font backend type
    #[doc(alias = "pango_cairo_font_map_get_font_type")]
    #[doc(alias = "get_font_type")]
    fn font_type(&self) -> cairo::FontType {
        unsafe { ffi::pango_cairo_font_map_get_font_type(self.as_ref().to_glib_none().0).into() }
    }
}

impl<O: IsA<FontMap>> PangoCairoFontMapExtManual for O {}

impl FontMap {
    #[doc(alias = "pango_cairo_font_map_new_for_font_type")]
    #[doc(alias = "new_for_font_type")]
    pub fn for_font_type(fonttype: cairo::FontType) -> Option<pango::FontMap> {
        unsafe { from_glib_full(ffi::pango_cairo_font_map_new_for_font_type(fonttype.into())) }
    }

    /// Creates a new [`FontMap`][crate::FontMap] object.
    ///
    /// A fontmap is used to cache information about available fonts,
    /// and holds certain global parameters such as the resolution.
    /// In most cases, you can use `func@PangoCairo.font_map_get_default]
    /// instead.
    ///
    /// Note that the type of the returned object will depend
    /// on the particular font backend Cairo was compiled to use;
    /// You generally should only use the [`pango::FontMap`][crate::pango::FontMap] and
    /// [`FontMap`][crate::FontMap] interfaces on the returned object.
    ///
    /// You can override the type of backend returned by using an
    /// environment variable `PANGOCAIRO_BACKEND`. Supported types,
    /// based on your build, are fc (fontconfig), win32, and coretext.
    /// If requested type is not available, NULL is returned. Ie.
    /// this is only useful for testing, when at least two backends
    /// are compiled in.
    ///
    /// # Returns
    ///
    /// the newly allocated [`pango::FontMap`][crate::pango::FontMap],
    ///   which should be freed with g_object_unref().
    #[allow(clippy::new_ret_no_self)]
    #[doc(alias = "pango_cairo_font_map_new")]
    pub fn new() -> pango::FontMap {
        unsafe { from_glib_full(ffi::pango_cairo_font_map_new()) }
    }

    #[doc(alias = "pango_cairo_font_map_set_default")]
    pub fn set_default(font_map: Option<&Self>) {
        unsafe {
            ffi::pango_cairo_font_map_set_default(font_map.as_ref().to_glib_none().0);
        }
    }
}