[librsvg] parse_transform.lalrpop: Parse the "scale" transform



commit 368b887bd98b498e60f54585035fc9df7dd12b8f
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 22 08:08:07 2017 -0600

    parse_transform.lalrpop: Parse the "scale" transform

 rust/src/parse_transform.lalrpop |    5 +++++
 rust/src/parsers.rs              |   12 ++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/parse_transform.lalrpop b/rust/src/parse_transform.lalrpop
index 4f09f79..db065b4 100644
--- a/rust/src/parse_transform.lalrpop
+++ b/rust/src/parse_transform.lalrpop
@@ -24,6 +24,11 @@ pub Translate: cairo::Matrix = {
     "translate" "(" <Num> comma? <Num> ")" => cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, <>)
 };
 
+pub Scale: cairo::Matrix = {
+    "scale" "(" <Num> ")" => cairo::Matrix::new (<>, 0.0, 0.0, <>, 0.0, 0.0),
+    "scale" "(" <sx: Num> comma? <sy: Num> ")" => cairo::Matrix::new (sx, 0.0, 0.0, sy, 0.0, 0.0),
+};
+
 pub Num: f64 = <s:r"[+-]?([0-9]*\.[0-9]+|[0-9]+(\.[0-9]*)?)([Ee][+-]?[0-9]+)?"> =>
     f64::from_str (s).unwrap ();
 
diff --git a/rust/src/parsers.rs b/rust/src/parsers.rs
index 0a131d6..2511227 100644
--- a/rust/src/parsers.rs
+++ b/rust/src/parsers.rs
@@ -316,4 +316,16 @@ mod parse_transform_tests {
         assert_eq! (parse_Translate ("translate(-1)").unwrap (),
                     cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, -1.0, 0.0));
     }
+
+    #[test]
+    fn parses_scale () {
+        assert_eq! (parse_Scale ("scale(-1 -2)").unwrap (),
+                    cairo::Matrix::new (-1.0, 0.0, 0.0, -2.0, 0.0, 0.0));
+
+        assert_eq! (parse_Scale ("scale(-1, -2)").unwrap (),
+                    cairo::Matrix::new (-1.0, 0.0, 0.0, -2.0, 0.0, 0.0));
+
+        assert_eq! (parse_Scale ("scale(-1)").unwrap (),
+                    cairo::Matrix::new (-1.0, 0.0, 0.0, -1.0, 0.0, 0.0));
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]