[librsvg: 8/21] impl Parse for Transform: don't ensure that it is invertible




commit 5e038674e7f36049ef489467815a4bd7c4550aee
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Aug 19 20:41:46 2021 -0500

    impl Parse for Transform: don't ensure that it is invertible
    
    This is a general change in strategy.  We parse e.g.
    matrix(0, 0, 0, 0, 0, 0) as a Transform, but leave it up to the caller
    to ensure that the transform is usable.
    
    This happens in drawing_ctx, where it uses the transform from the
    StackingCtx.  Per the CSS Transforms spec, objects should just not be
    rendered if the transform is not invertible, but that condition should
    not set the element to be in error.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/576>

 src/drawing_ctx.rs |  9 +++++++++
 src/transform.rs   | 19 +------------------
 2 files changed, 10 insertions(+), 18 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 57edfbbb..64e8fc31 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -666,6 +666,15 @@ impl DrawingCtx {
             &mut DrawingCtx,
         ) -> Result<BoundingBox, RenderingError>,
     ) -> Result<BoundingBox, RenderingError> {
+        if !stacking_ctx.transform.is_invertible() {
+            // https://www.w3.org/TR/css-transforms-1/#transform-function-lists
+            //
+            // "If a transform function causes the current transformation matrix of an
+            // object to be non-invertible, the object and its content do not get
+            // displayed."
+            return Ok(self.empty_bbox());
+        }
+
         let orig_transform = self.get_transform();
 
         self.cr.transform(stacking_ctx.transform.into());
diff --git a/src/transform.rs b/src/transform.rs
index 91e359e1..1b72fde6 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -454,17 +454,7 @@ impl Default for Transform {
 
 impl Parse for Transform {
     fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Transform, ParseError<'i>> {
-        let loc = parser.current_source_location();
-
-        let t = parse_transform_list(parser)?;
-
-        if !t.is_invertible() {
-            return Err(loc.new_custom_error(ValueErrorKind::Value(
-                "invalid transformation matrix".to_string(),
-            )));
-        }
-
-        Ok(t)
+        parse_transform_list(parser)
     }
 }
 
@@ -715,13 +705,6 @@ mod tests {
         assert_parse_error("skewY");
     }
 
-    #[test]
-    fn invalid_transform_yields_value_error() {
-        assert!(parse_transform("matrix (0 0 0 0 0 0)").is_err());
-        assert!(parse_transform("scale (0), translate (10, 10)").is_err());
-        assert!(parse_transform("scale (0), skewX (90)").is_err());
-    }
-
     #[test]
     fn parses_matrix() {
         assert_transform_eq(


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