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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
// 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 glib::translate::*;
glib::wrapper! {
/// A [`Matrix`][crate::Matrix] specifies a transformation between user-space
/// and device coordinates.
///
/// The transformation is given by
///
/// ```text
/// x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0;
/// y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0;
/// ```
pub struct Matrix(BoxedInline<ffi::PangoMatrix>);
match fn {
copy => |ptr| ffi::pango_matrix_copy(ptr),
free => |ptr| ffi::pango_matrix_free(ptr),
type_ => || ffi::pango_matrix_get_type(),
}
}
impl Matrix {
/// Changes the transformation represented by @self to be the
/// transformation given by first applying transformation
/// given by @new_matrix then applying the original transformation.
/// ## `new_matrix`
/// a [`Matrix`][crate::Matrix]
#[doc(alias = "pango_matrix_concat")]
pub fn concat(&mut self, new_matrix: &Matrix) {
unsafe {
ffi::pango_matrix_concat(self.to_glib_none_mut().0, new_matrix.to_glib_none().0);
}
}
/// Returns the scale factor of a matrix on the height of the font.
///
/// That is, the scale factor in the direction perpendicular to the
/// vector that the X coordinate is mapped to. If the scale in the X
/// coordinate is needed as well, use [`font_scale_factors()`][Self::font_scale_factors()].
///
/// # Returns
///
/// the scale factor of @self on the height of the font,
/// or 1.0 if @self is [`None`].
#[doc(alias = "pango_matrix_get_font_scale_factor")]
#[doc(alias = "get_font_scale_factor")]
pub fn font_scale_factor(&self) -> f64 {
unsafe { ffi::pango_matrix_get_font_scale_factor(self.to_glib_none().0) }
}
/// Calculates the scale factor of a matrix on the width and height of the font.
///
/// That is, @xscale is the scale factor in the direction of the X coordinate,
/// and @yscale is the scale factor in the direction perpendicular to the
/// vector that the X coordinate is mapped to.
///
/// Note that output numbers will always be non-negative.
///
/// # Returns
///
///
/// ## `xscale`
/// output scale factor in the x direction
///
/// ## `yscale`
/// output scale factor perpendicular to the x direction
#[doc(alias = "pango_matrix_get_font_scale_factors")]
#[doc(alias = "get_font_scale_factors")]
pub fn font_scale_factors(&self) -> (f64, f64) {
unsafe {
let mut xscale = std::mem::MaybeUninit::uninit();
let mut yscale = std::mem::MaybeUninit::uninit();
ffi::pango_matrix_get_font_scale_factors(
self.to_glib_none().0,
xscale.as_mut_ptr(),
yscale.as_mut_ptr(),
);
(xscale.assume_init(), yscale.assume_init())
}
}
/// Gets the slant ratio of a matrix.
///
/// For a simple shear matrix in the form:
///
/// 1 λ
/// 0 1
///
/// this is simply λ.
///
/// # Returns
///
/// the slant ratio of @self
#[cfg(feature = "v1_50")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
#[doc(alias = "pango_matrix_get_slant_ratio")]
#[doc(alias = "get_slant_ratio")]
pub fn slant_ratio(&self) -> f64 {
unsafe { ffi::pango_matrix_get_slant_ratio(self.to_glib_none().0) }
}
/// Changes the transformation represented by @self to be the
/// transformation given by first rotating by @degrees degrees
/// counter-clockwise then applying the original transformation.
/// ## `degrees`
/// degrees to rotate counter-clockwise
#[doc(alias = "pango_matrix_rotate")]
pub fn rotate(&mut self, degrees: f64) {
unsafe {
ffi::pango_matrix_rotate(self.to_glib_none_mut().0, degrees);
}
}
/// Changes the transformation represented by @self to be the
/// transformation given by first scaling by @sx in the X direction
/// and @sy in the Y direction then applying the original
/// transformation.
/// ## `scale_x`
/// amount to scale by in X direction
/// ## `scale_y`
/// amount to scale by in Y direction
#[doc(alias = "pango_matrix_scale")]
pub fn scale(&mut self, scale_x: f64, scale_y: f64) {
unsafe {
ffi::pango_matrix_scale(self.to_glib_none_mut().0, scale_x, scale_y);
}
}
/// Transforms the distance vector (@dx,@dy) by @self.
///
/// This is similar to [`transform_point()`][Self::transform_point()],
/// except that the translation components of the transformation
/// are ignored. The calculation of the returned vector is as follows:
///
/// ```text
/// dx2 = dx1 * xx + dy1 * xy;
/// dy2 = dx1 * yx + dy1 * yy;
/// ```
///
/// Affine transformations are position invariant, so the same vector
/// always transforms to the same vector. If (@x1,@y1) transforms
/// to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to
/// (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2.
/// ## `dx`
/// in/out X component of a distance vector
/// ## `dy`
/// in/out Y component of a distance vector
#[doc(alias = "pango_matrix_transform_distance")]
pub fn transform_distance(&self, dx: &mut f64, dy: &mut f64) {
unsafe {
ffi::pango_matrix_transform_distance(self.to_glib_none().0, dx, dy);
}
}
/// Transforms the point (@x, @y) by @self.
/// ## `x`
/// in/out X position
/// ## `y`
/// in/out Y position
#[doc(alias = "pango_matrix_transform_point")]
pub fn transform_point(&self, x: &mut f64, y: &mut f64) {
unsafe {
ffi::pango_matrix_transform_point(self.to_glib_none().0, x, y);
}
}
/// Changes the transformation represented by @self to be the
/// transformation given by first translating by (@tx, @ty)
/// then applying the original transformation.
/// ## `tx`
/// amount to translate in the X direction
/// ## `ty`
/// amount to translate in the Y direction
#[doc(alias = "pango_matrix_translate")]
pub fn translate(&mut self, tx: f64, ty: f64) {
unsafe {
ffi::pango_matrix_translate(self.to_glib_none_mut().0, tx, ty);
}
}
}