pango/auto/font_metrics.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;
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A [`FontMetrics`][crate::FontMetrics] structure holds the overall metric information
10 /// for a font.
11 ///
12 /// The information in a [`FontMetrics`][crate::FontMetrics] structure may be restricted
13 /// to a script. The fields of this structure are private to implementations
14 /// of a font backend. See the documentation of the corresponding getters
15 /// for documentation of their meaning.
16 ///
17 /// For an overview of the most important metrics, see:
18 ///
19 /// <picture>
20 /// <source srcset="fontmetrics-dark.png" media="(prefers-color-scheme: dark)">
21 /// <img alt="Font metrics" src="fontmetrics-light.png">
22 /// </picture>
23 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
24 pub struct FontMetrics(Shared<ffi::PangoFontMetrics>);
25
26 match fn {
27 ref => |ptr| ffi::pango_font_metrics_ref(ptr),
28 unref => |ptr| ffi::pango_font_metrics_unref(ptr),
29 type_ => || ffi::pango_font_metrics_get_type(),
30 }
31}
32
33impl FontMetrics {
34 /// Gets the approximate character width for a font metrics structure.
35 ///
36 /// This is merely a representative value useful, for example, for
37 /// determining the initial size for a window. Actual characters in
38 /// text will be wider and narrower than this.
39 ///
40 /// # Returns
41 ///
42 /// the character width, in Pango units.
43 #[doc(alias = "pango_font_metrics_get_approximate_char_width")]
44 #[doc(alias = "get_approximate_char_width")]
45 pub fn approximate_char_width(&self) -> i32 {
46 unsafe { ffi::pango_font_metrics_get_approximate_char_width(self.to_glib_none().0) }
47 }
48
49 /// Gets the approximate digit width for a font metrics structure.
50 ///
51 /// This is merely a representative value useful, for example, for
52 /// determining the initial size for a window. Actual digits in
53 /// text can be wider or narrower than this, though this value
54 /// is generally somewhat more accurate than the result of
55 /// pango_font_metrics_get_approximate_char_width() for digits.
56 ///
57 /// # Returns
58 ///
59 /// the digit width, in Pango units.
60 #[doc(alias = "pango_font_metrics_get_approximate_digit_width")]
61 #[doc(alias = "get_approximate_digit_width")]
62 pub fn approximate_digit_width(&self) -> i32 {
63 unsafe { ffi::pango_font_metrics_get_approximate_digit_width(self.to_glib_none().0) }
64 }
65
66 /// Gets the ascent from a font metrics structure.
67 ///
68 /// The ascent is the distance from the baseline to the logical top
69 /// of a line of text. (The logical top may be above or below the top
70 /// of the actual drawn ink. It is necessary to lay out the text to
71 /// figure where the ink will be.)
72 ///
73 /// # Returns
74 ///
75 /// the ascent, in Pango units.
76 #[doc(alias = "pango_font_metrics_get_ascent")]
77 #[doc(alias = "get_ascent")]
78 pub fn ascent(&self) -> i32 {
79 unsafe { ffi::pango_font_metrics_get_ascent(self.to_glib_none().0) }
80 }
81
82 /// Gets the descent from a font metrics structure.
83 ///
84 /// The descent is the distance from the baseline to the logical bottom
85 /// of a line of text. (The logical bottom may be above or below the
86 /// bottom of the actual drawn ink. It is necessary to lay out the text
87 /// to figure where the ink will be.)
88 ///
89 /// # Returns
90 ///
91 /// the descent, in Pango units.
92 #[doc(alias = "pango_font_metrics_get_descent")]
93 #[doc(alias = "get_descent")]
94 pub fn descent(&self) -> i32 {
95 unsafe { ffi::pango_font_metrics_get_descent(self.to_glib_none().0) }
96 }
97
98 /// Gets the line height from a font metrics structure.
99 ///
100 /// The line height is the recommended distance between successive
101 /// baselines in wrapped text using this font.
102 ///
103 /// If the line height is not available, 0 is returned.
104 ///
105 /// # Returns
106 ///
107 /// the height, in Pango units
108 #[cfg(feature = "v1_44")]
109 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
110 #[doc(alias = "pango_font_metrics_get_height")]
111 #[doc(alias = "get_height")]
112 pub fn height(&self) -> i32 {
113 unsafe { ffi::pango_font_metrics_get_height(self.to_glib_none().0) }
114 }
115
116 /// Gets the suggested position to draw the strikethrough.
117 ///
118 /// The value returned is the distance *above* the
119 /// baseline of the top of the strikethrough.
120 ///
121 /// # Returns
122 ///
123 /// the suggested strikethrough position, in Pango units.
124 #[doc(alias = "pango_font_metrics_get_strikethrough_position")]
125 #[doc(alias = "get_strikethrough_position")]
126 pub fn strikethrough_position(&self) -> i32 {
127 unsafe { ffi::pango_font_metrics_get_strikethrough_position(self.to_glib_none().0) }
128 }
129
130 /// Gets the suggested thickness to draw for the strikethrough.
131 ///
132 /// # Returns
133 ///
134 /// the suggested strikethrough thickness, in Pango units.
135 #[doc(alias = "pango_font_metrics_get_strikethrough_thickness")]
136 #[doc(alias = "get_strikethrough_thickness")]
137 pub fn strikethrough_thickness(&self) -> i32 {
138 unsafe { ffi::pango_font_metrics_get_strikethrough_thickness(self.to_glib_none().0) }
139 }
140
141 /// Gets the suggested position to draw the underline.
142 ///
143 /// The value returned is the distance *above* the baseline of the top
144 /// of the underline. Since most fonts have underline positions beneath
145 /// the baseline, this value is typically negative.
146 ///
147 /// # Returns
148 ///
149 /// the suggested underline position, in Pango units.
150 #[doc(alias = "pango_font_metrics_get_underline_position")]
151 #[doc(alias = "get_underline_position")]
152 pub fn underline_position(&self) -> i32 {
153 unsafe { ffi::pango_font_metrics_get_underline_position(self.to_glib_none().0) }
154 }
155
156 /// Gets the suggested thickness to draw for the underline.
157 ///
158 /// # Returns
159 ///
160 /// the suggested underline thickness, in Pango units.
161 #[doc(alias = "pango_font_metrics_get_underline_thickness")]
162 #[doc(alias = "get_underline_thickness")]
163 pub fn underline_thickness(&self) -> i32 {
164 unsafe { ffi::pango_font_metrics_get_underline_thickness(self.to_glib_none().0) }
165 }
166}