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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// 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 glib::object::IsA;
use glib::translate::*;
use pango_sys;
use std::fmt;
use Coverage;
use EngineShape;
use FontDescription;
use FontMap;
use FontMetrics;
use Glyph;
use Language;
use Rectangle;

glib_wrapper! {
    pub struct Font(Object<pango_sys::PangoFont, pango_sys::PangoFontClass, FontClass>);

    match fn {
        get_type => || pango_sys::pango_font_get_type(),
    }
}

pub const NONE_FONT: Option<&Font> = None;

pub trait FontExt: 'static {
    fn describe(&self) -> Option<FontDescription>;

    fn describe_with_absolute_size(&self) -> Option<FontDescription>;

    fn find_shaper(&self, language: &Language, ch: u32) -> Option<EngineShape>;

    fn get_coverage(&self, language: &Language) -> Option<Coverage>;

    //#[cfg(any(feature = "v1_44", feature = "dox"))]
    //fn get_features(&self, features: /*Unimplemented*/&mut Fundamental: Pointer, num_features: &mut u32) -> u32;

    fn get_font_map(&self) -> Option<FontMap>;

    fn get_glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle);

    //#[cfg(any(feature = "v1_44", feature = "dox"))]
    //fn get_hb_font(&self) -> /*Unimplemented*/Option<Fundamental: Pointer>;

    fn get_metrics(&self, language: Option<&Language>) -> Option<FontMetrics>;

    #[cfg(any(feature = "v1_44", feature = "dox"))]
    fn has_char(&self, wc: char) -> bool;
}

impl<O: IsA<Font>> FontExt for O {
    fn describe(&self) -> Option<FontDescription> {
        unsafe {
            from_glib_full(pango_sys::pango_font_describe(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn describe_with_absolute_size(&self) -> Option<FontDescription> {
        unsafe {
            from_glib_full(pango_sys::pango_font_describe_with_absolute_size(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn find_shaper(&self, language: &Language, ch: u32) -> Option<EngineShape> {
        unsafe {
            from_glib_none(pango_sys::pango_font_find_shaper(
                self.as_ref().to_glib_none().0,
                mut_override(language.to_glib_none().0),
                ch,
            ))
        }
    }

    fn get_coverage(&self, language: &Language) -> Option<Coverage> {
        unsafe {
            from_glib_full(pango_sys::pango_font_get_coverage(
                self.as_ref().to_glib_none().0,
                mut_override(language.to_glib_none().0),
            ))
        }
    }

    //#[cfg(any(feature = "v1_44", feature = "dox"))]
    //fn get_features(&self, features: /*Unimplemented*/&mut Fundamental: Pointer, num_features: &mut u32) -> u32 {
    //    unsafe { TODO: call pango_sys:pango_font_get_features() }
    //}

    fn get_font_map(&self) -> Option<FontMap> {
        unsafe {
            from_glib_none(pango_sys::pango_font_get_font_map(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle) {
        unsafe {
            let mut ink_rect = Rectangle::uninitialized();
            let mut logical_rect = Rectangle::uninitialized();
            pango_sys::pango_font_get_glyph_extents(
                self.as_ref().to_glib_none().0,
                glyph,
                ink_rect.to_glib_none_mut().0,
                logical_rect.to_glib_none_mut().0,
            );
            (ink_rect, logical_rect)
        }
    }

    //#[cfg(any(feature = "v1_44", feature = "dox"))]
    //fn get_hb_font(&self) -> /*Unimplemented*/Option<Fundamental: Pointer> {
    //    unsafe { TODO: call pango_sys:pango_font_get_hb_font() }
    //}

    fn get_metrics(&self, language: Option<&Language>) -> Option<FontMetrics> {
        unsafe {
            from_glib_full(pango_sys::pango_font_get_metrics(
                self.as_ref().to_glib_none().0,
                mut_override(language.to_glib_none().0),
            ))
        }
    }

    #[cfg(any(feature = "v1_44", feature = "dox"))]
    fn has_char(&self, wc: char) -> bool {
        unsafe {
            from_glib(pango_sys::pango_font_has_char(
                self.as_ref().to_glib_none().0,
                wc.to_glib(),
            ))
        }
    }
}

impl fmt::Display for Font {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Font")
    }
}