[librsvg: 4/19] Parse "matrix" transforms



commit b1c33fc9c09dc56226324087045894fad5726de2
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Nov 22 10:54:18 2017 -0600

    Parse "matrix" transforms

 rust/src/parsers.rs   |  2 +-
 rust/src/transform.rs | 27 +++++++++++++++++++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/rust/src/parsers.rs b/rust/src/parsers.rs
index 27067d1..87a2f59 100644
--- a/rust/src/parsers.rs
+++ b/rust/src/parsers.rs
@@ -71,7 +71,7 @@ pub fn angle_degrees (s: &str) -> Result <f64, ParseError> {
     Ok (angle)
 }
 
-fn optional_comma (parser: &mut Parser) {
+pub fn optional_comma (parser: &mut Parser) {
     let _ = parser.try (|p| p.expect_comma ());
 }
 
diff --git a/rust/src/transform.rs b/rust/src/transform.rs
index a94459b..92184ca 100644
--- a/rust/src/transform.rs
+++ b/rust/src/transform.rs
@@ -7,11 +7,10 @@ use ::libc;
 use std::f64::consts::*;
 
 use cairo::MatrixTrait;
-use cssparser::{Parser, ParserInput, Token, BasicParseError};
+use cssparser::{self, Parser, ParserInput};
 
 use error::*;
-use parsers::ParseError;
-use parsers::Parse;
+use parsers::{ParseError, Parse, optional_comma};
 
 impl Parse for cairo::Matrix {
     type Data = ();
@@ -41,7 +40,27 @@ pub fn parse_transform(s: &str) -> Result<cairo::Matrix, AttributeError> {
 }
 
 fn parse_matrix_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeError> {
-    unimplemented!();
+    parser.parse_nested_block(|p| {
+        let xx = p.expect_number()? as f64;
+        optional_comma(p);
+
+        let yx = p.expect_number()? as f64;
+        optional_comma(p);
+
+        let xy = p.expect_number()? as f64;
+        optional_comma(p);
+
+        let yy = p.expect_number()? as f64;
+        optional_comma(p);
+
+        let x0 = p.expect_number()? as f64;
+        optional_comma(p);
+
+        let y0 = p.expect_number()? as f64;
+
+        Ok(cairo::Matrix::new(xx, yx, xy, yy, x0, y0))
+    }).map_err(cssparser::ParseError::<()>::basic)
+        .map_err(|e| AttributeError::from(e))
 }
 
 fn parse_translate_args(parser: &mut Parser) -> Result<cairo::Matrix, AttributeError> {


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