pango/auto/
glyph_item.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
5use crate::{ffi, AttrList};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A [`GlyphItem`][crate::GlyphItem] is a pair of a [`Item`][crate::Item] and the glyphs
10    /// resulting from shaping the items text.
11    ///
12    /// As an example of the usage of [`GlyphItem`][crate::GlyphItem], the results
13    /// of shaping text with [`Layout`][crate::Layout] is a list of [`LayoutLine`][crate::LayoutLine],
14    /// each of which contains a list of [`GlyphItem`][crate::GlyphItem].
15    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
16    pub struct GlyphItem(Boxed<ffi::PangoGlyphItem>);
17
18    match fn {
19        copy => |ptr| ffi::pango_glyph_item_copy(mut_override(ptr)),
20        free => |ptr| ffi::pango_glyph_item_free(ptr),
21        type_ => || ffi::pango_glyph_item_get_type(),
22    }
23}
24
25impl GlyphItem {
26    /// Splits a shaped item ([`GlyphItem`][crate::GlyphItem]) into multiple items based
27    /// on an attribute list.
28    ///
29    /// The idea is that if you have attributes that don't affect shaping,
30    /// such as color or underline, to avoid affecting shaping, you filter
31    /// them out ([`AttrList::filter()`][crate::AttrList::filter()]), apply the shaping process
32    /// and then reapply them to the result using this function.
33    ///
34    /// All attributes that start or end inside a cluster are applied
35    /// to that cluster; for instance, if half of a cluster is underlined
36    /// and the other-half strikethrough, then the cluster will end
37    /// up with both underline and strikethrough attributes. In these
38    /// cases, it may happen that @item->extra_attrs for some of the
39    /// result items can have multiple attributes of the same type.
40    ///
41    /// This function takes ownership of @self; it will be reused
42    /// as one of the elements in the list.
43    /// ## `text`
44    /// text that @list applies to
45    /// ## `list`
46    /// a [`AttrList`][crate::AttrList]
47    ///
48    /// # Returns
49    ///
50    /// a
51    ///   list of glyph items resulting from splitting @self. Free
52    ///   the elements using `Pango::GlyphItem::free()`, the list using
53    ///   g_slist_free().
54    #[doc(alias = "pango_glyph_item_apply_attrs")]
55    pub fn apply_attrs(&mut self, text: &str, list: &AttrList) -> Vec<GlyphItem> {
56        unsafe {
57            FromGlibPtrContainer::from_glib_full(ffi::pango_glyph_item_apply_attrs(
58                self.to_glib_none_mut().0,
59                text.to_glib_none().0,
60                list.to_glib_none().0,
61            ))
62        }
63    }
64
65    //#[doc(alias = "pango_glyph_item_letter_space")]
66    //pub fn letter_space(&mut self, text: &str, log_attrs: /*Ignored*/&[LogAttr], letter_spacing: i32) {
67    //    unsafe { TODO: call ffi:pango_glyph_item_letter_space() }
68    //}
69
70    /// Modifies @self to cover only the text after @split_index, and
71    /// returns a new item that covers the text before @split_index that
72    /// used to be in @self.
73    ///
74    /// You can think of @split_index as the length of the returned item.
75    /// @split_index may not be 0, and it may not be greater than or equal
76    /// to the length of @self (that is, there must be at least one byte
77    /// assigned to each item, you can't create a zero-length item).
78    ///
79    /// This function is similar in function to pango_item_split() (and uses
80    /// it internally.)
81    /// ## `text`
82    /// text to which positions in @self apply
83    /// ## `split_index`
84    /// byte index of position to split item, relative to the
85    ///   start of the item
86    ///
87    /// # Returns
88    ///
89    /// the newly allocated item
90    ///   representing text before @split_index, which should be freed
91    ///   with pango_glyph_item_free().
92    #[doc(alias = "pango_glyph_item_split")]
93    #[must_use]
94    pub fn split(&mut self, text: &str, split_index: i32) -> Option<GlyphItem> {
95        unsafe {
96            from_glib_full(ffi::pango_glyph_item_split(
97                self.to_glib_none_mut().0,
98                text.to_glib_none().0,
99                split_index,
100            ))
101        }
102    }
103}