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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{Font, FontMetrics};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// A [`Fontset`][crate::Fontset] represents a set of [`Font`][crate::Font] to use when rendering text.
    ///
    /// A [`Fontset`][crate::Fontset] is the result of resolving a [`FontDescription`][crate::FontDescription]
    /// against a particular [`Context`][crate::Context]. It has operations for finding the
    /// component font for a particular Unicode character, and for finding a
    /// composite set of metrics for the entire fontset.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`FontsetExt`][trait@crate::prelude::FontsetExt]
    #[doc(alias = "PangoFontset")]
    pub struct Fontset(Object<ffi::PangoFontset, ffi::PangoFontsetClass>);

    match fn {
        type_ => || ffi::pango_fontset_get_type(),
    }
}

impl Fontset {
    pub const NONE: Option<&'static Fontset> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Fontset>> Sealed for T {}
}

/// Trait containing all [`struct@Fontset`] methods.
///
/// # Implementors
///
/// [`FontsetSimple`][struct@crate::FontsetSimple], [`Fontset`][struct@crate::Fontset]
pub trait FontsetExt: IsA<Fontset> + sealed::Sealed + 'static {
    /// Iterates through all the fonts in a fontset, calling @func for
    /// each one.
    ///
    /// If @func returns [`true`], that stops the iteration.
    /// ## `func`
    /// Callback function
    #[doc(alias = "pango_fontset_foreach")]
    fn foreach<P: FnMut(&Fontset, &Font) -> bool>(&self, func: P) {
        let func_data: P = func;
        unsafe extern "C" fn func_func<P: FnMut(&Fontset, &Font) -> bool>(
            fontset: *mut ffi::PangoFontset,
            font: *mut ffi::PangoFont,
            user_data: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let fontset = from_glib_borrow(fontset);
            let font = from_glib_borrow(font);
            let callback = user_data as *mut P;
            (*callback)(&fontset, &font).into_glib()
        }
        let func = Some(func_func::<P> as _);
        let super_callback0: &P = &func_data;
        unsafe {
            ffi::pango_fontset_foreach(
                self.as_ref().to_glib_none().0,
                func,
                super_callback0 as *const _ as *mut _,
            );
        }
    }

    /// Returns the font in the fontset that contains the best
    /// glyph for a Unicode character.
    /// ## `wc`
    /// a Unicode character
    ///
    /// # Returns
    ///
    /// a [`Font`][crate::Font]
    #[doc(alias = "pango_fontset_get_font")]
    #[doc(alias = "get_font")]
    fn font(&self, wc: u32) -> Font {
        unsafe {
            from_glib_full(ffi::pango_fontset_get_font(
                self.as_ref().to_glib_none().0,
                wc,
            ))
        }
    }

    /// Get overall metric information for the fonts in the fontset.
    ///
    /// # Returns
    ///
    /// a [`FontMetrics`][crate::FontMetrics] object
    #[doc(alias = "pango_fontset_get_metrics")]
    #[doc(alias = "get_metrics")]
    fn metrics(&self) -> FontMetrics {
        unsafe {
            from_glib_full(ffi::pango_fontset_get_metrics(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<Fontset>> FontsetExt for O {}