pango/auto/
glyph_item.rs

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
// 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::{ffi, AttrList};
use glib::translate::*;

glib::wrapper! {
    /// A [`GlyphItem`][crate::GlyphItem] is a pair of a [`Item`][crate::Item] and the glyphs
    /// resulting from shaping the items text.
    ///
    /// As an example of the usage of [`GlyphItem`][crate::GlyphItem], the results
    /// of shaping text with [`Layout`][crate::Layout] is a list of [`LayoutLine`][crate::LayoutLine],
    /// each of which contains a list of [`GlyphItem`][crate::GlyphItem].
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct GlyphItem(Boxed<ffi::PangoGlyphItem>);

    match fn {
        copy => |ptr| ffi::pango_glyph_item_copy(mut_override(ptr)),
        free => |ptr| ffi::pango_glyph_item_free(ptr),
        type_ => || ffi::pango_glyph_item_get_type(),
    }
}

impl GlyphItem {
    /// Splits a shaped item ([`GlyphItem`][crate::GlyphItem]) into multiple items based
    /// on an attribute list.
    ///
    /// The idea is that if you have attributes that don't affect shaping,
    /// such as color or underline, to avoid affecting shaping, you filter
    /// them out ([`AttrList::filter()`][crate::AttrList::filter()]), apply the shaping process
    /// and then reapply them to the result using this function.
    ///
    /// All attributes that start or end inside a cluster are applied
    /// to that cluster; for instance, if half of a cluster is underlined
    /// and the other-half strikethrough, then the cluster will end
    /// up with both underline and strikethrough attributes. In these
    /// cases, it may happen that @item->extra_attrs for some of the
    /// result items can have multiple attributes of the same type.
    ///
    /// This function takes ownership of @self; it will be reused
    /// as one of the elements in the list.
    /// ## `text`
    /// text that @list applies to
    /// ## `list`
    /// a [`AttrList`][crate::AttrList]
    ///
    /// # Returns
    ///
    /// a
    ///   list of glyph items resulting from splitting @self. Free
    ///   the elements using `Pango::GlyphItem::free()`, the list using
    ///   g_slist_free().
    #[doc(alias = "pango_glyph_item_apply_attrs")]
    pub fn apply_attrs(&mut self, text: &str, list: &AttrList) -> Vec<GlyphItem> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::pango_glyph_item_apply_attrs(
                self.to_glib_none_mut().0,
                text.to_glib_none().0,
                list.to_glib_none().0,
            ))
        }
    }

    //#[doc(alias = "pango_glyph_item_letter_space")]
    //pub fn letter_space(&mut self, text: &str, log_attrs: /*Ignored*/&[LogAttr], letter_spacing: i32) {
    //    unsafe { TODO: call ffi:pango_glyph_item_letter_space() }
    //}

    /// Modifies @self to cover only the text after @split_index, and
    /// returns a new item that covers the text before @split_index that
    /// used to be in @self.
    ///
    /// You can think of @split_index as the length of the returned item.
    /// @split_index may not be 0, and it may not be greater than or equal
    /// to the length of @self (that is, there must be at least one byte
    /// assigned to each item, you can't create a zero-length item).
    ///
    /// This function is similar in function to pango_item_split() (and uses
    /// it internally.)
    /// ## `text`
    /// text to which positions in @self apply
    /// ## `split_index`
    /// byte index of position to split item, relative to the
    ///   start of the item
    ///
    /// # Returns
    ///
    /// the newly allocated item
    ///   representing text before @split_index, which should be freed
    ///   with pango_glyph_item_free().
    #[doc(alias = "pango_glyph_item_split")]
    #[must_use]
    pub fn split(&mut self, text: &str, split_index: i32) -> Option<GlyphItem> {
        unsafe {
            from_glib_full(ffi::pango_glyph_item_split(
                self.to_glib_none_mut().0,
                text.to_glib_none().0,
                split_index,
            ))
        }
    }
}