[librsvg: 8/19] Parse the scale transform
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 8/19] Parse the scale transform
- Date: Mon, 22 Jan 2018 19:28:37 +0000 (UTC)
commit 6bf7e12bb5806189a7b8c9ab69b38bab96b1e5e1
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Jan 19 21:21:35 2018 -0600
Parse the scale transform
rust/src/transform.rs | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/rust/src/transform.rs b/rust/src/transform.rs
index 6072d8e..3e3b4c0 100644
--- a/rust/src/transform.rs
+++ b/rust/src/transform.rs
@@ -115,7 +115,17 @@ fn parse_translate_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeE
}
fn parse_scale_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeError> {
- unimplemented!();
+ parser.parse_nested_block(|p| {
+ let x = p.expect_number()?;
+
+ let y = p.try(|p| -> Result<f32, CssParseError<()>> {
+ optional_comma(p);
+ Ok(p.expect_number()?)
+ }).unwrap_or(x);
+
+ Ok(cairo::Matrix::new(x as f64, 0.0, 0.0, y as f64, 0.0, 0.0))
+ }).map_err(CssParseError::<()>::basic)
+ .map_err(|e| AttributeError::from(e))
}
fn parse_rotate_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeError> {
@@ -263,16 +273,15 @@ mod parser_tests {
}
#[test]
- #[ignore]
- fn parses_scale () {
+ fn parses_scale() {
+ assert_eq! (parse_transform ("scale (-1)").unwrap (),
+ cairo::Matrix::new (-1.0, 0.0, 0.0, -1.0, 0.0, 0.0));
+
assert_eq! (parse_transform ("scale(-1 -2)").unwrap (),
cairo::Matrix::new (-1.0, 0.0, 0.0, -2.0, 0.0, 0.0));
assert_eq! (parse_transform ("scale(-1, -2)").unwrap (),
cairo::Matrix::new (-1.0, 0.0, 0.0, -2.0, 0.0, 0.0));
-
- assert_eq! (parse_transform ("scale(-1)").unwrap (),
- cairo::Matrix::new (-1.0, 0.0, 0.0, -1.0, 0.0, 0.0));
}
#[test]
@@ -280,7 +289,7 @@ mod parser_tests {
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));
- assert_eq! (parse_transform ("rotate (30, -1, -2)").unwrap (), make_rotation_matrix (30.0, -1.0,
-2.0));
+ assert_eq! (parse_transform ("rotate(30, -1, -2)").unwrap (), make_rotation_matrix (30.0, -1.0,
-2.0));
}
fn make_skew_x_matrix (angle_degrees: f64) -> cairo::Matrix {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]