pango/auto/
font.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v1_50")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
7use crate::Context;
8#[cfg(feature = "v1_46")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
10use crate::FontFace;
11use crate::{ffi, Coverage, FontDescription, FontMap, FontMetrics, Glyph, Language, Rectangle};
12use glib::{prelude::*, translate::*};
13
14glib::wrapper! {
15    /// A [`Font`][crate::Font] is used to represent a font in a
16    /// rendering-system-independent manner.
17    ///
18    /// This is an Abstract Base Class, you cannot instantiate it.
19    ///
20    /// # Implements
21    ///
22    /// [`FontExt`][trait@crate::prelude::FontExt]
23    #[doc(alias = "PangoFont")]
24    pub struct Font(Object<ffi::PangoFont, ffi::PangoFontClass>);
25
26    match fn {
27        type_ => || ffi::pango_font_get_type(),
28    }
29}
30
31impl Font {
32    pub const NONE: Option<&'static Font> = None;
33
34    /// Loads data previously created via [`FontExt::serialize()`][crate::prelude::FontExt::serialize()].
35    ///
36    /// For a discussion of the supported format, see that function.
37    ///
38    /// Note: to verify that the returned font is identical to
39    /// the one that was serialized, you can compare @bytes to the
40    /// result of serializing the font again.
41    /// ## `context`
42    /// a [`Context`][crate::Context]
43    /// ## `bytes`
44    /// the bytes containing the data
45    ///
46    /// # Returns
47    ///
48    /// a new [`Font`][crate::Font]
49    #[cfg(feature = "v1_50")]
50    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
51    #[doc(alias = "pango_font_deserialize")]
52    pub fn deserialize(
53        context: &Context,
54        bytes: &glib::Bytes,
55    ) -> Result<Option<Font>, glib::Error> {
56        unsafe {
57            let mut error = std::ptr::null_mut();
58            let ret = ffi::pango_font_deserialize(
59                context.to_glib_none().0,
60                bytes.to_glib_none().0,
61                &mut error,
62            );
63            if error.is_null() {
64                Ok(from_glib_full(ret))
65            } else {
66                Err(from_glib_full(error))
67            }
68        }
69    }
70}
71
72/// Trait containing all [`struct@Font`] methods.
73///
74/// # Implementors
75///
76/// [`Font`][struct@crate::Font]
77pub trait FontExt: IsA<Font> + 'static {
78    /// Returns a description of the font, with font size set in points.
79    ///
80    /// Use [`describe_with_absolute_size()`][Self::describe_with_absolute_size()] if you want
81    /// the font size in device units.
82    ///
83    /// # Returns
84    ///
85    /// a newly-allocated [`FontDescription`][crate::FontDescription] object.
86    #[doc(alias = "pango_font_describe")]
87    fn describe(&self) -> FontDescription {
88        unsafe { from_glib_full(ffi::pango_font_describe(self.as_ref().to_glib_none().0)) }
89    }
90
91    /// Returns a description of the font, with absolute font size set
92    /// in device units.
93    ///
94    /// Use [`describe()`][Self::describe()] if you want the font size in points.
95    ///
96    /// # Returns
97    ///
98    /// a newly-allocated [`FontDescription`][crate::FontDescription] object.
99    #[doc(alias = "pango_font_describe_with_absolute_size")]
100    fn describe_with_absolute_size(&self) -> FontDescription {
101        unsafe {
102            from_glib_full(ffi::pango_font_describe_with_absolute_size(
103                self.as_ref().to_glib_none().0,
104            ))
105        }
106    }
107
108    /// Computes the coverage map for a given font and language tag.
109    /// ## `language`
110    /// the language tag
111    ///
112    /// # Returns
113    ///
114    /// a newly-allocated [`Coverage`][crate::Coverage]
115    ///   object.
116    #[doc(alias = "pango_font_get_coverage")]
117    #[doc(alias = "get_coverage")]
118    fn coverage(&self, language: &Language) -> Coverage {
119        unsafe {
120            from_glib_full(ffi::pango_font_get_coverage(
121                self.as_ref().to_glib_none().0,
122                mut_override(language.to_glib_none().0),
123            ))
124        }
125    }
126
127    /// Gets the [`FontFace`][crate::FontFace] to which @self belongs.
128    ///
129    /// Note that this function can return `NULL` in cases
130    /// where the font outlives its font map.
131    ///
132    /// # Returns
133    ///
134    /// the [`FontFace`][crate::FontFace]
135    #[cfg(feature = "v1_46")]
136    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
137    #[doc(alias = "pango_font_get_face")]
138    #[doc(alias = "get_face")]
139    fn face(&self) -> Option<FontFace> {
140        unsafe { from_glib_none(ffi::pango_font_get_face(self.as_ref().to_glib_none().0)) }
141    }
142
143    //#[cfg(feature = "v1_44")]
144    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
145    //#[doc(alias = "pango_font_get_features")]
146    //#[doc(alias = "get_features")]
147    //fn features(&self, features: /*Unimplemented*/&mut Basic: Pointer, len: u32, num_features: &mut u32) {
148    //    unsafe { TODO: call ffi:pango_font_get_features() }
149    //}
150
151    /// Gets the font map for which the font was created.
152    ///
153    /// Note that the font maintains a *weak* reference to
154    /// the font map, so if all references to font map are
155    /// dropped, the font map will be finalized even if there
156    /// are fonts created with the font map that are still alive.
157    /// In that case this function will return [`None`].
158    ///
159    /// It is the responsibility of the user to ensure that the
160    /// font map is kept alive. In most uses this is not an issue
161    /// as a [`Context`][crate::Context] holds a reference to the font map.
162    ///
163    /// # Returns
164    ///
165    /// the [`FontMap`][crate::FontMap]
166    ///   for the font
167    #[doc(alias = "pango_font_get_font_map")]
168    #[doc(alias = "get_font_map")]
169    fn font_map(&self) -> Option<FontMap> {
170        unsafe { from_glib_none(ffi::pango_font_get_font_map(self.as_ref().to_glib_none().0)) }
171    }
172
173    /// Gets the logical and ink extents of a glyph within a font.
174    ///
175    /// The coordinate system for each rectangle has its origin at the
176    /// base line and horizontal origin of the character with increasing
177    /// coordinates extending to the right and down. The macros PANGO_ASCENT(),
178    /// PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert
179    /// from the extents rectangle to more traditional font metrics. The units
180    /// of the rectangles are in 1/PANGO_SCALE of a device unit.
181    ///
182    /// If @self is [`None`], this function gracefully sets some sane values in the
183    /// output variables and returns.
184    /// ## `glyph`
185    /// the glyph index
186    ///
187    /// # Returns
188    ///
189    ///
190    /// ## `ink_rect`
191    /// rectangle used to store the extents of the glyph as drawn
192    ///
193    /// ## `logical_rect`
194    /// rectangle used to store the logical extents of the glyph
195    #[doc(alias = "pango_font_get_glyph_extents")]
196    #[doc(alias = "get_glyph_extents")]
197    fn glyph_extents(&self, glyph: Glyph) -> (Rectangle, Rectangle) {
198        unsafe {
199            let mut ink_rect = Rectangle::uninitialized();
200            let mut logical_rect = Rectangle::uninitialized();
201            ffi::pango_font_get_glyph_extents(
202                self.as_ref().to_glib_none().0,
203                glyph,
204                ink_rect.to_glib_none_mut().0,
205                logical_rect.to_glib_none_mut().0,
206            );
207            (ink_rect, logical_rect)
208        }
209    }
210
211    //#[cfg(feature = "v1_44")]
212    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
213    //#[doc(alias = "pango_font_get_hb_font")]
214    //#[doc(alias = "get_hb_font")]
215    //fn hb_font(&self) -> /*Ignored*/Option<harf_buzz::font_t> {
216    //    unsafe { TODO: call ffi:pango_font_get_hb_font() }
217    //}
218
219    /// Returns the languages that are supported by @self.
220    ///
221    /// If the font backend does not provide this information,
222    /// [`None`] is returned. For the fontconfig backend, this
223    /// corresponds to the FC_LANG member of the FcPattern.
224    ///
225    /// The returned array is only valid as long as the font
226    /// and its fontmap are valid.
227    ///
228    /// # Returns
229    ///
230    /// an array of [`Language`][crate::Language]
231    #[cfg(feature = "v1_50")]
232    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
233    #[doc(alias = "pango_font_get_languages")]
234    #[doc(alias = "get_languages")]
235    fn languages(&self) -> Vec<Language> {
236        unsafe {
237            FromGlibPtrContainer::from_glib_none(ffi::pango_font_get_languages(
238                self.as_ref().to_glib_none().0,
239            ))
240        }
241    }
242
243    /// Gets overall metric information for a font.
244    ///
245    /// Since the metrics may be substantially different for different scripts,
246    /// a language tag can be provided to indicate that the metrics should be
247    /// retrieved that correspond to the script(s) used by that language.
248    ///
249    /// If @self is [`None`], this function gracefully sets some sane values in the
250    /// output variables and returns.
251    /// ## `language`
252    /// language tag used to determine which script
253    ///   to get the metrics for, or [`None`] to indicate to get the metrics for
254    ///   the entire font.
255    ///
256    /// # Returns
257    ///
258    /// a [`FontMetrics`][crate::FontMetrics] object. The caller must call
259    ///   `Pango::FontMetrics::unref()` when finished using the object.
260    #[doc(alias = "pango_font_get_metrics")]
261    #[doc(alias = "get_metrics")]
262    fn metrics(&self, language: Option<&Language>) -> FontMetrics {
263        unsafe {
264            from_glib_full(ffi::pango_font_get_metrics(
265                self.as_ref().to_glib_none().0,
266                mut_override(language.to_glib_none().0),
267            ))
268        }
269    }
270
271    /// Returns whether the font provides a glyph for this character.
272    /// ## `wc`
273    /// a Unicode character
274    ///
275    /// # Returns
276    ///
277    /// `TRUE` if @self can render @wc
278    #[cfg(feature = "v1_44")]
279    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
280    #[doc(alias = "pango_font_has_char")]
281    fn has_char(&self, wc: char) -> bool {
282        unsafe {
283            from_glib(ffi::pango_font_has_char(
284                self.as_ref().to_glib_none().0,
285                wc.into_glib(),
286            ))
287        }
288    }
289
290    /// Serializes the @self in a way that can be uniquely identified.
291    ///
292    /// There are no guarantees about the format of the output across different
293    /// versions of Pango.
294    ///
295    /// The intended use of this function is testing, benchmarking and debugging.
296    /// The format is not meant as a permanent storage format.
297    ///
298    /// To recreate a font from its serialized form, use [`Font::deserialize()`][crate::Font::deserialize()].
299    ///
300    /// # Returns
301    ///
302    /// a `GBytes` containing the serialized form of @self
303    #[cfg(feature = "v1_50")]
304    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
305    #[doc(alias = "pango_font_serialize")]
306    fn serialize(&self) -> glib::Bytes {
307        unsafe { from_glib_full(ffi::pango_font_serialize(self.as_ref().to_glib_none().0)) }
308    }
309}
310
311impl<O: IsA<Font>> FontExt for O {}