1use glib::object::IsA;
6use glib::translate::*;
7use glib::GString;
8use pango_sys;
9use std::fmt;
10use std::mem;
11use std::ptr;
12use Context;
13use Font;
14use FontDescription;
15use FontFamily;
16use Fontset;
17use Language;
18
19glib_wrapper! {
20 pub struct FontMap(Object<pango_sys::PangoFontMap, pango_sys::PangoFontMapClass, FontMapClass>);
21
22 match fn {
23 get_type => || pango_sys::pango_font_map_get_type(),
24 }
25}
26
27pub const NONE_FONT_MAP: Option<&FontMap> = None;
28
29pub trait FontMapExt: 'static {
30 fn changed(&self);
31
32 fn create_context(&self) -> Option<Context>;
33
34 fn get_serial(&self) -> u32;
35
36 #[cfg_attr(feature = "v1_38", deprecated)]
37 fn get_shape_engine_type(&self) -> Option<GString>;
38
39 fn list_families(&self) -> Vec<FontFamily>;
40
41 fn load_font(&self, context: &Context, desc: &FontDescription) -> Option<Font>;
42
43 fn load_fontset(
44 &self,
45 context: &Context,
46 desc: &FontDescription,
47 language: &Language,
48 ) -> Option<Fontset>;
49}
50
51impl<O: IsA<FontMap>> FontMapExt for O {
52 fn changed(&self) {
53 unsafe {
54 pango_sys::pango_font_map_changed(self.as_ref().to_glib_none().0);
55 }
56 }
57
58 fn create_context(&self) -> Option<Context> {
59 unsafe {
60 from_glib_full(pango_sys::pango_font_map_create_context(
61 self.as_ref().to_glib_none().0,
62 ))
63 }
64 }
65
66 fn get_serial(&self) -> u32 {
67 unsafe { pango_sys::pango_font_map_get_serial(self.as_ref().to_glib_none().0) }
68 }
69
70 fn get_shape_engine_type(&self) -> Option<GString> {
71 unsafe {
72 from_glib_none(pango_sys::pango_font_map_get_shape_engine_type(
73 self.as_ref().to_glib_none().0,
74 ))
75 }
76 }
77
78 fn list_families(&self) -> Vec<FontFamily> {
79 unsafe {
80 let mut families = ptr::null_mut();
81 let mut n_families = mem::uninitialized();
82 pango_sys::pango_font_map_list_families(
83 self.as_ref().to_glib_none().0,
84 &mut families,
85 &mut n_families,
86 );
87 FromGlibContainer::from_glib_container_num(families, n_families as usize)
88 }
89 }
90
91 fn load_font(&self, context: &Context, desc: &FontDescription) -> Option<Font> {
92 unsafe {
93 from_glib_full(pango_sys::pango_font_map_load_font(
94 self.as_ref().to_glib_none().0,
95 context.to_glib_none().0,
96 desc.to_glib_none().0,
97 ))
98 }
99 }
100
101 fn load_fontset(
102 &self,
103 context: &Context,
104 desc: &FontDescription,
105 language: &Language,
106 ) -> Option<Fontset> {
107 unsafe {
108 from_glib_full(pango_sys::pango_font_map_load_fontset(
109 self.as_ref().to_glib_none().0,
110 context.to_glib_none().0,
111 desc.to_glib_none().0,
112 mut_override(language.to_glib_none().0),
113 ))
114 }
115 }
116}
117
118impl fmt::Display for FontMap {
119 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120 write!(f, "FontMap")
121 }
122}