pango/glyph_item.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, GlyphItem, GlyphString, Item};
6
7impl GlyphItem {
8 pub fn item(&self) -> Item {
9 unsafe { from_glib_none((*self.as_ptr()).item) }
10 }
11
12 pub fn glyph_string(&self) -> GlyphString {
13 unsafe { from_glib_none((*self.as_ptr()).glyphs) }
14 }
15
16 /// Given a [`GlyphItem`][crate::GlyphItem] and the corresponding text, determine the
17 /// width corresponding to each character.
18 ///
19 /// When multiple characters compose a single cluster, the width of the
20 /// entire cluster is divided equally among the characters.
21 ///
22 /// See also [`GlyphString::logical_widths()`][crate::GlyphString::logical_widths()].
23 /// ## `text`
24 /// text that @self corresponds to
25 /// (glyph_item->item->offset is an offset from the
26 /// start of @text)
27 ///
28 /// # Returns
29 ///
30 ///
31 /// ## `logical_widths`
32 /// an array whose length
33 /// is the number of characters in glyph_item (equal to
34 /// `glyph_item->item->num_chars`) to be filled in with the resulting
35 /// character widths.
36 #[doc(alias = "pango_glyph_item_get_logical_widths")]
37 #[doc(alias = "get_logical_widths")]
38 pub fn logical_widths(&self, text: &str) -> Vec<i32> {
39 let count = text.chars().count();
40 unsafe {
41 let mut logical_widths = Vec::with_capacity(count);
42 ffi::pango_glyph_item_get_logical_widths(
43 mut_override(self.to_glib_none().0),
44 text.to_glib_none().0,
45 logical_widths.as_mut_ptr(),
46 );
47 logical_widths.set_len(count);
48 logical_widths
49 }
50 }
51}