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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// 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::Coverage;
use crate::FontDescription;
#[cfg(any(feature = "v1_46", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
use crate::FontFace;
use crate::FontMap;
use crate::FontMetrics;
use crate::Glyph;
use crate::Language;
use crate::Rectangle;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// The [`Font`][crate::Font] structure is used to represent
    /// a font in a rendering-system-independent matter.
    /// To create an implementation of a [`Font`][crate::Font],
    /// the rendering-system specific code should allocate
    /// a larger structure that contains a nested
    /// [`Font`][crate::Font], fill in the `<structfield>`klass`</structfield>` member of
    /// the nested [`Font`][crate::Font] with a pointer to
    /// a appropriate `PangoFontClass`, then call
    /// `pango_font_init()` on the structure.
    ///
    /// The [`Font`][crate::Font] structure contains one member
    /// which the implementation fills in.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`FontExt`][trait@crate::prelude::FontExt]
    #[doc(alias = "PangoFont")]
    pub struct Font(Object<ffi::PangoFont, ffi::PangoFontClass>);

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

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

/// Trait containing all [`struct@Font`] methods.
///
/// # Implementors
///
/// [`Font`][struct@crate::Font]
pub trait FontExt: 'static {
    /// Returns a description of the font, with font size set in points.
    /// Use [`describe_with_absolute_size()`][Self::describe_with_absolute_size()] if you want the font
    /// size in device units.
    ///
    /// # Returns
    ///
    /// a newly-allocated [`FontDescription`][crate::FontDescription] object.
    #[doc(alias = "pango_font_describe")]
    fn describe(&self) -> Option<FontDescription>;

    /// Returns a description of the font, with absolute font size set
    /// (in device units). Use [`describe()`][Self::describe()] if you want the font
    /// size in points.
    ///
    /// # Returns
    ///
    /// a newly-allocated [`FontDescription`][crate::FontDescription] object.
    #[doc(alias = "pango_font_describe_with_absolute_size")]
    fn describe_with_absolute_size(&self) -> Option<FontDescription>;

    //#[doc(alias = "pango_font_find_shaper")]
    //fn find_shaper(&self, language: &Language, ch: u32) -> /*Ignored*/Option<EngineShape>;

    /// Computes the coverage map for a given font and language tag.
    /// ## `language`
    /// the language tag
    ///
    /// # Returns
    ///
    /// a newly-allocated [`Coverage`][crate::Coverage]
    ///  object.
    #[doc(alias = "pango_font_get_coverage")]
    #[doc(alias = "get_coverage")]
    fn coverage(&self, language: &Language) -> Option<Coverage>;

    /// Gets the [`FontFace`][crate::FontFace] to which `self` belongs.
    ///
    /// # Returns
    ///
    /// the [`FontFace`][crate::FontFace]
    #[cfg(any(feature = "v1_46", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
    #[doc(alias = "pango_font_get_face")]
    #[doc(alias = "get_face")]
    fn face(&self) -> Option<FontFace>;

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

    /// Gets the font map for which the font was created.
    ///
    /// Note that the font maintains a `<firstterm>`weak`</firstterm>` reference
    /// to the font map, so if all references to font map are dropped, the font
    /// map will be finalized even if there are fonts created with the font
    /// map that are still alive. In that case this function will return [`None`].
    /// It is the responsibility of the user to ensure that the font map is kept
    /// alive. In most uses this is not an issue as a [`Context`][crate::Context] holds
    /// a reference to the font map.
    ///
    /// # Returns
    ///
    /// the [`FontMap`][crate::FontMap] for the
    ///  font, or [`None`] if `self` is [`None`].
    #[doc(alias = "pango_font_get_font_map")]
    #[doc(alias = "get_font_map")]
    fn font_map(&self) -> Option<FontMap>;

    /// Gets the logical and ink extents of a glyph within a font. The
    /// coordinate system for each rectangle has its origin at the
    /// base line and horizontal origin of the character with increasing
    /// coordinates extending to the right and down. The macros PANGO_ASCENT(),
    /// PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert
    /// from the extents rectangle to more traditional font metrics. The units
    /// of the rectangles are in 1/PANGO_SCALE of a device unit.
    ///
    /// If `self` is [`None`], this function gracefully sets some sane values in the
    /// output variables and returns.
    /// ## `glyph`
    /// the glyph index
    ///
    /// # Returns
    ///
    ///
    /// ## `ink_rect`
    /// rectangle used to store the extents of the glyph
    ///  as drawn or [`None`] to indicate that the result is not needed.
    ///
    /// ## `logical_rect`
    /// rectangle used to store the logical extents of
    ///  the glyph or [`None`] to indicate that the result is not needed.
    #[doc(alias = "pango_font_get_glyph_extents")]
    #[doc(alias = "get_glyph_extents")]
    fn glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle);

    //#[cfg(any(feature = "v1_44", feature = "dox"))]
    //#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
    //#[doc(alias = "pango_font_get_hb_font")]
    //#[doc(alias = "get_hb_font")]
    //fn hb_font(&self) -> /*Ignored*/Option<harf_buzz::font_t>;

    /// Gets overall metric information for a font. Since the metrics may be
    /// substantially different for different scripts, a language tag can
    /// be provided to indicate that the metrics should be retrieved that
    /// correspond to the script(s) used by that language.
    ///
    /// If `self` is [`None`], this function gracefully sets some sane values in the
    /// output variables and returns.
    /// ## `language`
    /// language tag used to determine which script to get the metrics
    ///  for, or [`None`] to indicate to get the metrics for the entire font.
    ///
    /// # Returns
    ///
    /// a [`FontMetrics`][crate::FontMetrics] object. The caller must call `pango_font_metrics_unref()`
    ///  when finished using the object.
    #[doc(alias = "pango_font_get_metrics")]
    #[doc(alias = "get_metrics")]
    fn metrics(&self, language: Option<&Language>) -> Option<FontMetrics>;

    /// Returns whether the font provides a glyph for this character.
    ///
    /// Returns [`true`] if `self` can render `wc`
    /// ## `wc`
    /// a Unicode character
    #[cfg(any(feature = "v1_44", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
    #[doc(alias = "pango_font_has_char")]
    fn has_char(&self, wc: char) -> bool;
}

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

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

    //fn find_shaper(&self, language: &Language, ch: u32) -> /*Ignored*/Option<EngineShape> {
    //    unsafe { TODO: call ffi:pango_font_find_shaper() }
    //}

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

    #[cfg(any(feature = "v1_46", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
    fn face(&self) -> Option<FontFace> {
        unsafe { from_glib_none(ffi::pango_font_get_face(self.as_ref().to_glib_none().0)) }
    }

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

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

    fn glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle) {
        unsafe {
            let mut ink_rect = Rectangle::uninitialized();
            let mut logical_rect = Rectangle::uninitialized();
            ffi::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"))]
    //#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
    //fn hb_font(&self) -> /*Ignored*/Option<harf_buzz::font_t> {
    //    unsafe { TODO: call ffi:pango_font_get_hb_font() }
    //}

    fn metrics(&self, language: Option<&Language>) -> Option<FontMetrics> {
        unsafe {
            from_glib_full(ffi::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"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
    fn has_char(&self, wc: char) -> bool {
        unsafe {
            from_glib(ffi::pango_font_has_char(
                self.as_ref().to_glib_none().0,
                wc.into_glib(),
            ))
        }
    }
}

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