[librsvg] parse_transform.lalrpop: Parse chained transform lists
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] parse_transform.lalrpop: Parse chained transform lists
- Date: Wed, 22 Mar 2017 18:00:10 +0000 (UTC)
commit 03138e684e09130747293a0e7a2946a2c311000c
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Mar 22 09:20:45 2017 -0600
parse_transform.lalrpop: Parse chained transform lists
rust/src/parse_transform.lalrpop | 27 +++++++++++++++++++++------
rust/src/parsers.rs | 17 +++++++++++++++++
2 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/rust/src/parse_transform.lalrpop b/rust/src/parse_transform.lalrpop
index 9da4537..a99df98 100644
--- a/rust/src/parse_transform.lalrpop
+++ b/rust/src/parse_transform.lalrpop
@@ -12,13 +12,28 @@ use pt::cairo::MatrixTrait;
grammar;
-pub Transform: cairo::Matrix = {
+pub TransformList: cairo::Matrix = {
+ // Note that the grammar in https://www.w3.org/TR/SVG/coords.html#TransformAttribute
+ // has this:
+ //
+ // transforms:
+ // transform
+ // | transform comma-wsp+ transforms
+ //
+ // I think the "comma-wsp+" should really be "comma-wsp" as in the
+ // rest of the SVG grammar. Here we will use our usual "comma?" and
+ // hope that the SVG test suite catches errors in our grammar.
+ <a: TransformList> comma? <b: Transform> => cairo::Matrix::multiply (&b, &a),
+ Transform
+};
+
+Transform: cairo::Matrix = {
Matrix,
-// Translate,
-// Scale,
-// Rotate,
-// SkewX,
-// SkewY
+ Translate,
+ Scale,
+ Rotate,
+ SkewX,
+ SkewY
};
pub Matrix: cairo::Matrix = "matrix" "(" <Num> comma? <Num> comma? <Num> comma? <Num> comma? <Num> comma?
<Num> ")" =>
diff --git a/rust/src/parsers.rs b/rust/src/parsers.rs
index 09b47fd..9675db3 100644
--- a/rust/src/parsers.rs
+++ b/rust/src/parsers.rs
@@ -372,4 +372,21 @@ mod parse_transform_tests {
fn parses_skew_y () {
assert_eq! (parse_SkewY ("skewY (30)").unwrap (), make_skew_y_matrix (30.0));
}
+
+ #[test]
+ fn parses_transform_list () {
+ let t = cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, 20.0, 30.0);
+ let s = cairo::Matrix::new (10.0, 0.0, 0.0, 10.0, 0.0, 0.0);
+ let r = make_rotation_matrix (30.0, 10.0, 10.0);
+
+ assert_eq! (parse_TransformList ("scale(10)rotate(30, 10, 10)").unwrap (),
+ cairo::Matrix::multiply (&r, &s));
+
+ assert_eq! (parse_TransformList ("translate(20, 30), scale (10)").unwrap (),
+ cairo::Matrix::multiply (&s, &t));
+
+ let a = cairo::Matrix::multiply (&s, &t);
+ assert_eq! (parse_TransformList ("translate(20, 30), scale (10) rotate (30 10 10)").unwrap (),
+ cairo::Matrix::multiply (&r, &a));
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]