[librsvg: 9/19] Parse the rotate transform
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 9/19] Parse the rotate transform
- Date: Mon, 22 Jan 2018 19:28:42 +0000 (UTC)
commit de4b0d1f3ac8bce1e9d5970f099446b663cd1553
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Jan 22 12:15:23 2018 -0600
Parse the rotate transform
rust/src/transform.rs | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/rust/src/transform.rs b/rust/src/transform.rs
index 3e3b4c0..018a2d0 100644
--- a/rust/src/transform.rs
+++ b/rust/src/transform.rs
@@ -3,7 +3,6 @@ use ::glib::translate::*;
use ::glib_sys;
use ::libc;
-#[cfg(test)]
use std::f64::consts::*;
use cairo::MatrixTrait;
@@ -129,7 +128,27 @@ fn parse_scale_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeError
}
fn parse_rotate_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeError> {
- unimplemented!();
+ parser.parse_nested_block(|p| {
+ let angle = p.expect_number()? as f64 * PI / 180.0;
+ let (s, c) = angle.sin_cos();
+
+ let (tx, ty) = p.try(|p| -> Result<_, CssParseError<()>> {
+ optional_comma(p);
+ let tx = p.expect_number()? as f64;
+
+ optional_comma(p);
+ let ty = p.expect_number()? as f64;
+
+ Ok((tx, ty))
+ }).unwrap_or((0.0, 0.0));
+
+ let mut m = cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, tx, ty);
+
+ m = cairo::Matrix::multiply (&cairo::Matrix::new (c, s, -s, c, 0.0, 0.0), &m);
+ m = cairo::Matrix::multiply (&cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, -tx, -ty), &m);
+ Ok(m)
+ }).map_err(CssParseError::<()>::basic)
+ .map_err(|e| AttributeError::from(e))
}
fn parse_skewX_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeError> {
@@ -285,7 +304,6 @@ mod parser_tests {
}
#[test]
- #[ignore]
fn parses_rotate () {
assert_eq! (parse_transform ("rotate (30)").unwrap (), make_rotation_matrix (30.0, 0.0, 0.0));
assert_eq! (parse_transform ("rotate (30,-1,-2)").unwrap (), make_rotation_matrix (30.0, -1.0,
-2.0));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]