1use glib::object::IsA;
6use glib::translate::*;
7use pango_sys;
8use std::fmt;
9use Font;
10use FontMetrics;
11
12glib_wrapper! {
13 pub struct Fontset(Object<pango_sys::PangoFontset, pango_sys::PangoFontsetClass, FontsetClass>);
14
15 match fn {
16 get_type => || pango_sys::pango_fontset_get_type(),
17 }
18}
19
20pub const NONE_FONTSET: Option<&Fontset> = None;
21
22pub trait FontsetExt: 'static {
23 fn foreach<P: FnMut(&Fontset, &Font) -> bool>(&self, func: P);
24
25 fn get_font(&self, wc: u32) -> Option<Font>;
26
27 fn get_metrics(&self) -> Option<FontMetrics>;
28}
29
30impl<O: IsA<Fontset>> FontsetExt for O {
31 fn foreach<P: FnMut(&Fontset, &Font) -> bool>(&self, func: P) {
32 let func_data: P = func;
33 unsafe extern "C" fn func_func<P: FnMut(&Fontset, &Font) -> bool>(
34 fontset: *mut pango_sys::PangoFontset,
35 font: *mut pango_sys::PangoFont,
36 user_data: glib_sys::gpointer,
37 ) -> glib_sys::gboolean {
38 let fontset = from_glib_borrow(fontset);
39 let font = from_glib_borrow(font);
40 let callback: *mut P = user_data as *const _ as usize as *mut P;
41 let res = (*callback)(&fontset, &font);
42 res.to_glib()
43 }
44 let func = Some(func_func::<P> as _);
45 let super_callback0: &P = &func_data;
46 unsafe {
47 pango_sys::pango_fontset_foreach(
48 self.as_ref().to_glib_none().0,
49 func,
50 super_callback0 as *const _ as usize as *mut _,
51 );
52 }
53 }
54
55 fn get_font(&self, wc: u32) -> Option<Font> {
56 unsafe {
57 from_glib_full(pango_sys::pango_fontset_get_font(
58 self.as_ref().to_glib_none().0,
59 wc,
60 ))
61 }
62 }
63
64 fn get_metrics(&self) -> Option<FontMetrics> {
65 unsafe {
66 from_glib_full(pango_sys::pango_fontset_get_metrics(
67 self.as_ref().to_glib_none().0,
68 ))
69 }
70 }
71}
72
73impl fmt::Display for Fontset {
74 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
75 write!(f, "Fontset")
76 }
77}