[librsvg/librsvg-2.50] (#718): Negative rx/ry in rect element should be ignored



commit 0726c2b0ca5e9e616a4e8033abfdd109ffb083d9
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Apr 28 20:55:26 2021 -0500

    (#718): Negative rx/ry in rect element should be ignored
    
    We were setting the whole element in error; negative values for rx/ry
    should resolve to "auto", or in our case, to None.
    
    Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/718

 rsvg_internals/src/shapes.rs                       |  41 ++++++++++++---------
 .../reftests/bugs/718-rect-negative-rx-ry-ref.png  | Bin 0 -> 658 bytes
 .../reftests/bugs/718-rect-negative-rx-ry.svg      |  11 ++++++
 3 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index 6bb563c6..0b84f233 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -377,14 +377,10 @@ impl SetAttributes for Rect {
                         attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?
                 }
                 expanded_name!("", "rx") => {
-                    self.rx = attr
-                        .parse_and_validate(value, Length::<Horizontal>::check_nonnegative)
-                        .map(Some)?
+                    self.rx = attr.parse(value).map(Some)?;
                 }
                 expanded_name!("", "ry") => {
-                    self.ry = attr
-                        .parse_and_validate(value, Length::<Vertical>::check_nonnegative)
-                        .map(Some)?
+                    self.ry = attr.parse(value).map(Some)?;
                 }
                 _ => (),
             }
@@ -423,28 +419,42 @@ impl Rect {
         let w = self.w.normalize(values, &params);
         let h = self.h.normalize(values, &params);
 
+        let specified_rx = self.rx.map(|l| l.normalize(values, &params));
+        let specified_ry = self.ry.map(|l| l.normalize(values, &params));
+
+        fn nonnegative_or_none(l: f64) -> Option<f64> {
+            if l < 0.0 {
+                None
+            } else {
+                Some(l)
+            }
+        }
+
+        let norm_rx = specified_rx.and_then(nonnegative_or_none);
+        let norm_ry = specified_ry.and_then(nonnegative_or_none);
+
         let mut rx;
         let mut ry;
 
-        match (self.rx, self.ry) {
+        match (norm_rx, norm_ry) {
             (None, None) => {
                 rx = 0.0;
                 ry = 0.0;
             }
 
             (Some(_rx), None) => {
-                rx = _rx.normalize(values, &params);
-                ry = _rx.normalize(values, &params);
+                rx = _rx;
+                ry = _rx;
             }
 
             (None, Some(_ry)) => {
-                rx = _ry.normalize(values, &params);
-                ry = _ry.normalize(values, &params);
+                rx = _ry;
+                ry = _ry;
             }
 
             (Some(_rx), Some(_ry)) => {
-                rx = _rx.normalize(values, &params);
-                ry = _ry.normalize(values, &params);
+                rx = _rx;
+                ry = _ry;
             }
         }
 
@@ -455,11 +465,6 @@ impl Rect {
             return builder.into_path();
         }
 
-        // ... and rx,ry must be nonnegative
-        if rx < 0.0 || ry < 0.0 {
-            return builder.into_path();
-        }
-
         let half_w = w / 2.0;
         let half_h = h / 2.0;
 
diff --git a/tests/fixtures/reftests/bugs/718-rect-negative-rx-ry-ref.png 
b/tests/fixtures/reftests/bugs/718-rect-negative-rx-ry-ref.png
new file mode 100644
index 00000000..5fd1b8cf
Binary files /dev/null and b/tests/fixtures/reftests/bugs/718-rect-negative-rx-ry-ref.png differ
diff --git a/tests/fixtures/reftests/bugs/718-rect-negative-rx-ry.svg 
b/tests/fixtures/reftests/bugs/718-rect-negative-rx-ry.svg
new file mode 100644
index 00000000..1f526d16
--- /dev/null
+++ b/tests/fixtures/reftests/bugs/718-rect-negative-rx-ry.svg
@@ -0,0 +1,11 @@
+<svg xmlns="http://www.w3.org/2000/svg"; width="300" height="100">
+<!-- Negative values for rx/ry should be ignored -->
+  <rect x="20" y="20" width="60" height="60" fill="red"/>
+  <rect x="10" y="10" width="80" height="80" rx="-10" ry="5" fill="lime"/>
+
+  <rect x="120" y="20" width="60" height="60" fill="red"/>
+  <rect x="110" y="10" width="80" height="80" rx="5" ry="-10" fill="lime"/>
+
+  <rect x="220" y="20" width="60" height="60" fill="red"/>
+  <rect x="210" y="10" width="80" height="80" rx="-5" ry="-10" fill="lime"/>
+</svg>


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