1use glib::object::IsA;
6use glib::translate::*;
7use pango_sys;
8use std::fmt;
9use Coverage;
10use EngineShape;
11use FontDescription;
12use FontMap;
13use FontMetrics;
14use Glyph;
15use Language;
16use Rectangle;
17
18glib_wrapper! {
19 pub struct Font(Object<pango_sys::PangoFont, pango_sys::PangoFontClass, FontClass>);
20
21 match fn {
22 get_type => || pango_sys::pango_font_get_type(),
23 }
24}
25
26pub const NONE_FONT: Option<&Font> = None;
27
28pub trait FontExt: 'static {
29 fn describe(&self) -> Option<FontDescription>;
30
31 fn describe_with_absolute_size(&self) -> Option<FontDescription>;
32
33 fn find_shaper(&self, language: &Language, ch: u32) -> Option<EngineShape>;
34
35 fn get_coverage(&self, language: &Language) -> Option<Coverage>;
36
37 fn get_font_map(&self) -> Option<FontMap>;
38
39 fn get_glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle);
40
41 fn get_metrics(&self, language: Option<&Language>) -> Option<FontMetrics>;
42}
43
44impl<O: IsA<Font>> FontExt for O {
45 fn describe(&self) -> Option<FontDescription> {
46 unsafe {
47 from_glib_full(pango_sys::pango_font_describe(
48 self.as_ref().to_glib_none().0,
49 ))
50 }
51 }
52
53 fn describe_with_absolute_size(&self) -> Option<FontDescription> {
54 unsafe {
55 from_glib_full(pango_sys::pango_font_describe_with_absolute_size(
56 self.as_ref().to_glib_none().0,
57 ))
58 }
59 }
60
61 fn find_shaper(&self, language: &Language, ch: u32) -> Option<EngineShape> {
62 unsafe {
63 from_glib_none(pango_sys::pango_font_find_shaper(
64 self.as_ref().to_glib_none().0,
65 mut_override(language.to_glib_none().0),
66 ch,
67 ))
68 }
69 }
70
71 fn get_coverage(&self, language: &Language) -> Option<Coverage> {
72 unsafe {
73 from_glib_full(pango_sys::pango_font_get_coverage(
74 self.as_ref().to_glib_none().0,
75 mut_override(language.to_glib_none().0),
76 ))
77 }
78 }
79
80 fn get_font_map(&self) -> Option<FontMap> {
81 unsafe {
82 from_glib_none(pango_sys::pango_font_get_font_map(
83 self.as_ref().to_glib_none().0,
84 ))
85 }
86 }
87
88 fn get_glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle) {
89 unsafe {
90 let mut ink_rect = Rectangle::uninitialized();
91 let mut logical_rect = Rectangle::uninitialized();
92 pango_sys::pango_font_get_glyph_extents(
93 self.as_ref().to_glib_none().0,
94 glyph,
95 ink_rect.to_glib_none_mut().0,
96 logical_rect.to_glib_none_mut().0,
97 );
98 (ink_rect, logical_rect)
99 }
100 }
101
102 fn get_metrics(&self, language: Option<&Language>) -> Option<FontMetrics> {
103 unsafe {
104 from_glib_full(pango_sys::pango_font_get_metrics(
105 self.as_ref().to_glib_none().0,
106 mut_override(language.to_glib_none().0),
107 ))
108 }
109 }
110}
111
112impl fmt::Display for Font {
113 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
114 write!(f, "Font")
115 }
116}