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
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::AttrIterator;
use crate::Attribute;
use crate::FontDescription;
use crate::Language;
use glib::translate::*;

use std::ptr;

impl AttrIterator {
    /// Get the font and other attributes at the current iterator position.
    /// ## `desc`
    /// a [`FontDescription`][crate::FontDescription] to fill in with the current values.
    ///  The family name in this structure will be set using
    ///  `pango_font_description_set_family_static()` using values from
    ///  an attribute in the [`AttrList`][crate::AttrList] associated with the iterator,
    ///  so if you plan to keep it around, you must call:
    ///  `<literal>`pango_font_description_set_family (desc, pango_font_description_get_family (desc))`</literal>`.
    /// ## `language`
    /// if non-[`None`], location to store language tag for item, or [`None`]
    ///  if none is found.
    /// ## `extra_attrs`
    /// if non-[`None`],
    ///  location in which to store a list of non-font
    ///  attributes at the the current position; only the highest priority
    ///  value of each attribute will be added to this list. In order
    ///  to free this value, you must call `pango_attribute_destroy()` on
    ///  each member.
    #[doc(alias = "pango_attr_iterator_get_font")]
    #[doc(alias = "get_font")]
    pub fn font(
        &mut self,
        desc: &mut FontDescription,
        language: Option<&Language>,
        extra_attrs: &[&Attribute],
    ) {
        unsafe {
            let stash_vec: Vec<_> = extra_attrs.iter().rev().map(|v| v.to_glib_none()).collect();
            let mut list: *mut glib::ffi::GSList = ptr::null_mut();
            for stash in &stash_vec {
                list = glib::ffi::g_slist_prepend(list, Ptr::to(stash.0));
            }

            ffi::pango_attr_iterator_get_font(
                self.to_glib_none_mut().0,
                desc.to_glib_none_mut().0,
                &mut language.to_glib_none().0,
                &mut list,
            );
        }
    }
}