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
use std::mem;

#[repr(C)]
pub struct Matrix {
  xx: f64,
  yx: f64,
  xy: f64,
  yy: f64,
  x0: f64,
  y0: f64
}

impl Matrix {
  pub fn new(xx: f64, yx: f64, xy: f64, yy: f64, x0: f64, y0: f64) -> Matrix {
    unsafe {
      let mut this:Matrix = mem::zeroed();
      cairo_matrix_init(&mut this, xx, yx, xy, yy, x0, y0);
      return this;
    }
  }

  pub fn identity() -> Matrix {
    unsafe {
      let mut this:Matrix = mem::zeroed();
      cairo_matrix_init_identity(&mut this);
      return this;
    }
  }

  pub fn for_translation(x0: f64, y0: f64) -> Matrix {
    unsafe {
      let mut this:Matrix = mem::zeroed();
      cairo_matrix_init_translate(&mut this, x0, y0);
      return this;
    }
  }

  pub fn for_scale(sx: f64, sy: f64) -> Matrix {
    unsafe {
      let mut this:Matrix = mem::zeroed();
      cairo_matrix_init_scale(&mut this, sx, sy);
      return this;
    }
  }

  pub fn for_rotation(radians: f64) -> Matrix {
    unsafe {
      let mut this:Matrix = mem::zeroed();
      cairo_matrix_init_rotate(&mut this, radians);
      return this;
    }
  }

  pub fn multiply(a: &mut Matrix, b: &mut Matrix) -> Matrix {
    unsafe {
      let mut this:Matrix = mem::zeroed();
      cairo_matrix_multiply(&mut this, a, b);
      return this;
    }
  }

  pub fn translate(&mut self, x0: f64, y0: f64) {
    unsafe {
      cairo_matrix_translate(self, x0, y0);
    }
  }

  pub fn scale(&mut self, sx: f64, sy: f64) {
    unsafe {
      cairo_matrix_scale(self, sx, sy);
    }
  }

  pub fn rotate(&mut self, radians: f64) {
    unsafe {
      cairo_matrix_rotate(self, radians);
    }
  }

  pub fn transform_distance(&mut self) -> (f64, f64) {
    unsafe {
      let mut dx:f64 = mem::zeroed();
      let mut dy:f64 = mem::zeroed();
      cairo_matrix_transform_distance(self, &mut dx, &mut dy);
      return (dx, dy);
    }
  }

  pub fn transform_point(&mut self) -> (f64, f64) {
    unsafe {
      let mut x:f64 = mem::zeroed();
      let mut y:f64 = mem::zeroed();
      cairo_matrix_transform_point(self, &mut x, &mut y);
      return (x, y);
    }
  }

  pub fn invert(&mut self) -> super::Status {
    unsafe {
      let foreign_result = cairo_matrix_invert(self);
      return foreign_result;
    }
  }
}

extern {
  fn cairo_matrix_init(this: *mut Matrix, xx: f64, yx: f64, xy: f64, yy: f64, x0: f64, y0: f64);
  fn cairo_matrix_init_identity(this: *mut Matrix);
  fn cairo_matrix_init_translate(this: *mut Matrix, x0: f64, y0: f64);
  fn cairo_matrix_init_scale(this: *mut Matrix, sx: f64, sy: f64);
  fn cairo_matrix_init_rotate(this: *mut Matrix, radians: f64);
  fn cairo_matrix_multiply(this: *mut Matrix, a: *mut Matrix, b: *mut Matrix);
  fn cairo_matrix_translate(self_arg: *mut Matrix, x0: f64, y0: f64);
  fn cairo_matrix_scale(self_arg: *mut Matrix, sx: f64, sy: f64);
  fn cairo_matrix_rotate(self_arg: *mut Matrix, radians: f64);
  fn cairo_matrix_transform_distance(self_arg: *mut Matrix, dx: *mut f64, dy: *mut f64);
  fn cairo_matrix_transform_point(self_arg: *mut Matrix, x: *mut f64, y: *mut f64);
  fn cairo_matrix_invert(self_arg: *mut Matrix) -> super::Status;
}