pango/auto/matrix.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 [`Matrix`][crate::Matrix] specifies a transformation between user-space
10 /// and device coordinates.
11 ///
12 /// The transformation is given by
13 ///
14 /// ```text
15 /// x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0;
16 /// y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0;
17 /// ```
18 pub struct Matrix(BoxedInline<ffi::PangoMatrix>);
19
20 match fn {
21 copy => |ptr| ffi::pango_matrix_copy(ptr),
22 free => |ptr| ffi::pango_matrix_free(ptr),
23 type_ => || ffi::pango_matrix_get_type(),
24 }
25}
26
27impl Matrix {
28 /// Changes the transformation represented by @self to be the
29 /// transformation given by first applying transformation
30 /// given by @new_matrix then applying the original transformation.
31 /// ## `new_matrix`
32 /// a [`Matrix`][crate::Matrix]
33 #[doc(alias = "pango_matrix_concat")]
34 pub fn concat(&mut self, new_matrix: &Matrix) {
35 unsafe {
36 ffi::pango_matrix_concat(self.to_glib_none_mut().0, new_matrix.to_glib_none().0);
37 }
38 }
39
40 /// Returns the scale factor of a matrix on the height of the font.
41 ///
42 /// That is, the scale factor in the direction perpendicular to the
43 /// vector that the X coordinate is mapped to. If the scale in the X
44 /// coordinate is needed as well, use [`font_scale_factors()`][Self::font_scale_factors()].
45 ///
46 /// # Returns
47 ///
48 /// the scale factor of @self on the height of the font,
49 /// or 1.0 if @self is [`None`].
50 #[doc(alias = "pango_matrix_get_font_scale_factor")]
51 #[doc(alias = "get_font_scale_factor")]
52 pub fn font_scale_factor(&self) -> f64 {
53 unsafe { ffi::pango_matrix_get_font_scale_factor(self.to_glib_none().0) }
54 }
55
56 /// Calculates the scale factor of a matrix on the width and height of the font.
57 ///
58 /// That is, @xscale is the scale factor in the direction of the X coordinate,
59 /// and @yscale is the scale factor in the direction perpendicular to the
60 /// vector that the X coordinate is mapped to.
61 ///
62 /// Note that output numbers will always be non-negative.
63 ///
64 /// # Returns
65 ///
66 ///
67 /// ## `xscale`
68 /// output scale factor in the x direction
69 ///
70 /// ## `yscale`
71 /// output scale factor perpendicular to the x direction
72 #[doc(alias = "pango_matrix_get_font_scale_factors")]
73 #[doc(alias = "get_font_scale_factors")]
74 pub fn font_scale_factors(&self) -> (f64, f64) {
75 unsafe {
76 let mut xscale = std::mem::MaybeUninit::uninit();
77 let mut yscale = std::mem::MaybeUninit::uninit();
78 ffi::pango_matrix_get_font_scale_factors(
79 self.to_glib_none().0,
80 xscale.as_mut_ptr(),
81 yscale.as_mut_ptr(),
82 );
83 (xscale.assume_init(), yscale.assume_init())
84 }
85 }
86
87 /// Gets the slant ratio of a matrix.
88 ///
89 /// For a simple shear matrix in the form:
90 ///
91 /// 1 λ
92 /// 0 1
93 ///
94 /// this is simply λ.
95 ///
96 /// # Returns
97 ///
98 /// the slant ratio of @self
99 #[cfg(feature = "v1_50")]
100 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
101 #[doc(alias = "pango_matrix_get_slant_ratio")]
102 #[doc(alias = "get_slant_ratio")]
103 pub fn slant_ratio(&self) -> f64 {
104 unsafe { ffi::pango_matrix_get_slant_ratio(self.to_glib_none().0) }
105 }
106
107 /// Changes the transformation represented by @self to be the
108 /// transformation given by first rotating by @degrees degrees
109 /// counter-clockwise then applying the original transformation.
110 /// ## `degrees`
111 /// degrees to rotate counter-clockwise
112 #[doc(alias = "pango_matrix_rotate")]
113 pub fn rotate(&mut self, degrees: f64) {
114 unsafe {
115 ffi::pango_matrix_rotate(self.to_glib_none_mut().0, degrees);
116 }
117 }
118
119 /// Changes the transformation represented by @self to be the
120 /// transformation given by first scaling by @sx in the X direction
121 /// and @sy in the Y direction then applying the original
122 /// transformation.
123 /// ## `scale_x`
124 /// amount to scale by in X direction
125 /// ## `scale_y`
126 /// amount to scale by in Y direction
127 #[doc(alias = "pango_matrix_scale")]
128 pub fn scale(&mut self, scale_x: f64, scale_y: f64) {
129 unsafe {
130 ffi::pango_matrix_scale(self.to_glib_none_mut().0, scale_x, scale_y);
131 }
132 }
133
134 /// Transforms the distance vector (@dx,@dy) by @self.
135 ///
136 /// This is similar to [`transform_point()`][Self::transform_point()],
137 /// except that the translation components of the transformation
138 /// are ignored. The calculation of the returned vector is as follows:
139 ///
140 /// ```text
141 /// dx2 = dx1 * xx + dy1 * xy;
142 /// dy2 = dx1 * yx + dy1 * yy;
143 /// ```
144 ///
145 /// Affine transformations are position invariant, so the same vector
146 /// always transforms to the same vector. If (@x1,@y1) transforms
147 /// to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to
148 /// (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2.
149 /// ## `dx`
150 /// in/out X component of a distance vector
151 /// ## `dy`
152 /// in/out Y component of a distance vector
153 #[doc(alias = "pango_matrix_transform_distance")]
154 pub fn transform_distance(&self, dx: &mut f64, dy: &mut f64) {
155 unsafe {
156 ffi::pango_matrix_transform_distance(self.to_glib_none().0, dx, dy);
157 }
158 }
159
160 /// Transforms the point (@x, @y) by @self.
161 /// ## `x`
162 /// in/out X position
163 /// ## `y`
164 /// in/out Y position
165 #[doc(alias = "pango_matrix_transform_point")]
166 pub fn transform_point(&self, x: &mut f64, y: &mut f64) {
167 unsafe {
168 ffi::pango_matrix_transform_point(self.to_glib_none().0, x, y);
169 }
170 }
171
172 /// Changes the transformation represented by @self to be the
173 /// transformation given by first translating by (@tx, @ty)
174 /// then applying the original transformation.
175 /// ## `tx`
176 /// amount to translate in the X direction
177 /// ## `ty`
178 /// amount to translate in the Y direction
179 #[doc(alias = "pango_matrix_translate")]
180 pub fn translate(&mut self, tx: f64, ty: f64) {
181 unsafe {
182 ffi::pango_matrix_translate(self.to_glib_none_mut().0, tx, ty);
183 }
184 }
185}