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



commit ba8264a7fc85bf448f23a0809d86b3f99c7eb2db
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 22 07:30:54 2017 -0600

    parse_transform.lalrpop: Parse the "matrix" transform

 rust/Cargo.lock                  |   52 +++++++++++++++++++-------------------
 rust/Cargo.toml                  |   10 ++++---
 rust/src/lib.rs                  |    1 +
 rust/src/parse_transform.lalrpop |   20 ++++++++++++++-
 rust/src/parsers.rs              |   18 +++++++++++++
 5 files changed, 70 insertions(+), 31 deletions(-)
---
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 2b32a3a..d9b1aa7 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2,14 +2,14 @@
 name = "rsvg_internals"
 version = "0.0.1"
 dependencies = [
- "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "cairo-rs 0.1.1 (git+https://github.com/gtk-rs/cairo.git)",
- "cairo-sys-rs 0.3.2 (git+https://github.com/gtk-rs/cairo.git)",
+ "bitflags 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cairo-rs 0.1.1 (git+https://github.com/federicomenaquintero/cairo.git)",
+ "cairo-sys-rs 0.3.2 (git+https://github.com/federicomenaquintero/cairo.git)",
  "downcast-rs 1.0.0 (git+https://github.com/marcianx/downcast-rs)",
  "glib 0.1.1 (git+https://github.com/gtk-rs/glib)",
  "lalrpop 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "lalrpop-util 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "nom 2.1.0 (git+https://github.com/federicomenaquintero/nom.git)",
  "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -36,7 +36,7 @@ version = "0.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 dependencies = [
  "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -65,7 +65,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 
 [[package]]
 name = "bitflags"
-version = "0.7.0"
+version = "0.8.0"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 
 [[package]]
@@ -76,21 +76,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 [[package]]
 name = "cairo-rs"
 version = "0.1.1"
-source = "git+https://github.com/gtk-rs/cairo.git#411ffb9c719fc686e948bf5f5ff3b0236a6456f3";
+source = "git+https://github.com/federicomenaquintero/cairo.git#c86b8d01dfab410a7917f5db266c1f30a0ef7f10";
 dependencies = [
  "c_vec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "cairo-sys-rs 0.3.2 (git+https://github.com/gtk-rs/cairo.git)",
+ "cairo-sys-rs 0.3.2 (git+https://github.com/federicomenaquintero/cairo.git)",
  "glib 0.1.1 (git+https://github.com/gtk-rs/glib)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "cairo-sys-rs"
 version = "0.3.2"
-source = "git+https://github.com/gtk-rs/cairo.git#411ffb9c719fc686e948bf5f5ff3b0236a6456f3";
+source = "git+https://github.com/federicomenaquintero/cairo.git#c86b8d01dfab410a7917f5db266c1f30a0ef7f10";
 dependencies = [
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -124,32 +124,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 [[package]]
 name = "glib"
 version = "0.1.1"
-source = "git+https://github.com/gtk-rs/glib#91f2ceb47cdc2d3b209ce3b6c96e3de928223842";
+source = "git+https://github.com/gtk-rs/glib#6dabedc25e9c86f44c8c51e284b518791b5e89f6";
 dependencies = [
  "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "glib-sys 0.3.2 (git+https://github.com/gtk-rs/sys)",
  "gobject-sys 0.3.2 (git+https://github.com/gtk-rs/sys)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "glib-sys"
 version = "0.3.2"
-source = "git+https://github.com/gtk-rs/sys#9e646efc356e3895576dad548c505ee9b37323a1";
+source = "git+https://github.com/gtk-rs/sys#aaa2a305c0ec8c93a9baaa366a7bdbe7dfb44e10";
 dependencies = [
  "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "gobject-sys"
 version = "0.3.2"
-source = "git+https://github.com/gtk-rs/sys#9e646efc356e3895576dad548c505ee9b37323a1";
+source = "git+https://github.com/gtk-rs/sys#aaa2a305c0ec8c93a9baaa366a7bdbe7dfb44e10";
 dependencies = [
  "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "glib-sys 0.3.2 (git+https://github.com/gtk-rs/sys)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -227,7 +227,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 
 [[package]]
 name = "libc"
-version = "0.2.20"
+version = "0.2.21"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 
 [[package]]
@@ -235,7 +235,7 @@ name = "memchr"
 version = "0.1.11"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 dependencies = [
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -243,7 +243,7 @@ name = "memchr"
 version = "1.0.1"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 dependencies = [
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -328,7 +328,7 @@ version = "2.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 dependencies = [
  "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -337,7 +337,7 @@ version = "3.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 dependencies = [
  "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -403,10 +403,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = 
"5b97c2c8e8bbb4251754f559df8af22fb264853c7d009084a576cdf12565089d"
 "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
 "checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
-"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
+"checksum bitflags 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"826e1ab483fc81a8143faa7203c4a3c02888ebd1a782e37e41fa34753ba9a162"
 "checksum c_vec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"0059f5a658f62a4bd3937a7addc52ccfda144b75cce7a92b187e528629cdc507"
-"checksum cairo-rs 0.1.1 (git+https://github.com/gtk-rs/cairo.git)" = "<none>"
-"checksum cairo-sys-rs 0.3.2 (git+https://github.com/gtk-rs/cairo.git)" = "<none>"
+"checksum cairo-rs 0.1.1 (git+https://github.com/federicomenaquintero/cairo.git)" = "<none>"
+"checksum cairo-sys-rs 0.3.2 (git+https://github.com/federicomenaquintero/cairo.git)" = "<none>"
 "checksum diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = 
"0a515461b6c8c08419850ced27bc29e86166dcdcde8fbe76f8b1f0589bb49472"
 "checksum docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)" = 
"4a7ef30445607f6fc8720f0a0a2c7442284b629cf0d049286860fae23e71c4d9"
 "checksum downcast-rs 1.0.0 (git+https://github.com/marcianx/downcast-rs)" = "<none>"
@@ -421,7 +421,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum lalrpop-snap 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)" = 
"e82554f7abfe767e8a22286e7ca6d1ea7d873e91f0259981e15c7c6754d7340d"
 "checksum lalrpop-util 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)" = 
"36497edf44be49f4663ebd9cfb154a81c84491986a62773c62624911efd3d84d"
 "checksum lazy_static 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = 
"7291b1dd97d331f752620b02dfdbc231df7fc01bf282a00769e1cdb963c460dc"
-"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = 
"684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
+"checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = 
"88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135"
 "checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = 
"d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
 "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
 "checksum nom 2.1.0 (git+https://github.com/federicomenaquintero/nom.git)" = "<none>"
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 5e9d2ff..bb85a74 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -9,14 +9,16 @@ libc = "0.2"
 bitflags = ""
 
 [dependencies.cairo-sys-rs]
-git = "https://github.com/gtk-rs/cairo.git";
-#git = "https://github.com/federicomenaquintero/cairo.git";
+#git = "https://github.com/gtk-rs/cairo.git";
+git = "https://github.com/federicomenaquintero/cairo.git";
+#branch = "matrix-try-invert"
 #git = "file:///home/federico/src/gtk-rs/cairo"
 #features = ["png"]
 
 [dependencies.cairo-rs]
-git = "https://github.com/gtk-rs/cairo.git";
-#git = "https://github.com/federicomenaquintero/cairo.git";
+#git = "https://github.com/gtk-rs/cairo.git";
+git = "https://github.com/federicomenaquintero/cairo.git";
+#branch = "matrix-try-invert"
 #git = "file:///home/federico/src/gtk-rs/cairo"
 #features = ["png"]
 
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 1a04315..5d1e75b 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -113,6 +113,7 @@ mod length;
 mod marker;
 mod node;
 mod paint_server;
+mod pt;
 mod parsers;
 mod parse_transform;
 mod path_builder;
diff --git a/rust/src/parse_transform.lalrpop b/rust/src/parse_transform.lalrpop
index 655ba68..50b61da 100644
--- a/rust/src/parse_transform.lalrpop
+++ b/rust/src/parse_transform.lalrpop
@@ -2,6 +2,24 @@
 
 use std::str::FromStr;
 
+use pt::cairo;
+use pt::cairo::MatrixTrait;
+
 grammar;
 
-pub Num: f64 = <s:r"[+-]?([0-9]*\.[0-9]+|[0-9]+(\.[0-9]*)?)([Ee][+-]?[0-9]+)?"> => f64::from_str (s).unwrap 
();
+pub Transform: cairo::Matrix = {
+    Matrix,
+//    Translate,
+//    Scale,
+//    Rotate,
+//    SkewX,
+//    SkewY
+};
+
+pub Matrix: cairo::Matrix = "matrix" "(" <Num> comma? <Num> comma? <Num> comma? <Num> comma? <Num> comma? 
<Num> ")" =>
+    cairo::Matrix::new (<>);
+
+pub Num: f64 = <s:r"[+-]?([0-9]*\.[0-9]+|[0-9]+(\.[0-9]*)?)([Ee][+-]?[0-9]+)?"> =>
+    f64::from_str (s).unwrap ();
+
+comma: () = ",";
diff --git a/rust/src/parsers.rs b/rust/src/parsers.rs
index 7253d85..ae70d7a 100644
--- a/rust/src/parsers.rs
+++ b/rust/src/parsers.rs
@@ -1,9 +1,13 @@
+extern crate cairo;
+
 use nom::{IResult, double, is_alphabetic};
 use std::str;
 use std::f64::consts::*;
 
 use parse_transform::*;
 
+use self::cairo::MatrixTrait;
+
 // I don't know how to copy a nom::IError for long-term storage
 // (i.e. when it can no longer reference the &[u8]).  So, we explode a
 // nom::IError into a simple error struct that can be passed around.
@@ -268,6 +272,8 @@ mod tests {
 
 #[cfg(test)]
 mod parse_transform_tests {
+    use super::*;
+
     #[test]
     fn parses_numbers () {
         assert_eq! (parse_Num ("0"),          Ok (0.0));
@@ -286,4 +292,16 @@ mod parse_transform_tests {
         assert_eq! (parse_Num ("-123.25e-2"), Ok (-1.2325));
         assert_eq! (parse_Num ("123.25E-2"),  Ok (1.2325));
     }
+
+    #[test]
+    fn parses_matrix () {
+        assert_eq! (parse_Matrix ("matrix (1 2 3 4 5 6)").unwrap (),
+                    cairo::Matrix::new (1.0, 2.0, 3.0, 4.0, 5.0, 6.0));
+
+        assert_eq! (parse_Matrix ("matrix (1,2,3,4 5 6)").unwrap (),
+                    cairo::Matrix::new (1.0, 2.0, 3.0, 4.0, 5.0, 6.0));
+
+        assert_eq! (parse_Matrix ("matrix (1,2.25,-3.25e2,4 5 6)").unwrap (),
+                    cairo::Matrix::new (1.0, 2.25, -325.0, 4.0, 5.0, 6.0));
+    }
 }


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