[librsvg/librsvg-2.54: 2/5] (#880): Accept patterns with userSpaceOnUse units even if there is no object bounding box




commit ec83ec1cd1758a496e3fa38777a2fef908847039
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Jul 11 10:48:42 2022 -0500

    (#880): Accept patterns with userSpaceOnUse units even if there is no object bounding box
    
    Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/880

 src/pattern.rs                                     | 34 +++++++++++++---------
 tests/Makefile.am                                  |  1 +
 .../bugs-reftests/880-stroke-wide-line-ref.svg     |  4 +++
 .../bugs-reftests/880-stroke-wide-line.svg         | 13 +++++++++
 tests/src/reference.rs                             |  6 ++++
 5 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/src/pattern.rs b/src/pattern.rs
index 24635546b..42f6aeb3a 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -307,6 +307,14 @@ impl UnresolvedChildren {
     }
 }
 
+fn nonempty_rect_from_bbox(bbox: &BoundingBox) -> Option<Rect> {
+    match bbox.rect {
+        None => None,
+        Some(r) if r.is_empty() => None,
+        Some(r) => Some(r),
+    }
+}
+
 impl ResolvedPattern {
     fn node_with_children(&self) -> Option<Node> {
         match self.children {
@@ -340,22 +348,19 @@ impl ResolvedPattern {
 
         let rect = self.get_rect(&params);
 
-        let bbrect = match bbox.rect {
-            None => return None,
-            Some(r) if r.is_empty() => return None,
-            Some(r) => r,
-        };
-
         // Create the pattern coordinate system
         let (width, height, coord_transform) = match self.units {
-            PatternUnits(CoordUnits::ObjectBoundingBox) => (
-                rect.width() * bbrect.width(),
-                rect.height() * bbrect.height(),
-                Transform::new_translate(
-                    bbrect.x0 + rect.x0 * bbrect.width(),
-                    bbrect.y0 + rect.y0 * bbrect.height(),
-                ),
-            ),
+            PatternUnits(CoordUnits::ObjectBoundingBox) => {
+                let bbrect = nonempty_rect_from_bbox(bbox)?;
+                (
+                    rect.width() * bbrect.width(),
+                    rect.height() * bbrect.height(),
+                    Transform::new_translate(
+                        bbrect.x0 + rect.x0 * bbrect.width(),
+                        bbrect.y0 + rect.y0 * bbrect.height(),
+                    ),
+                )
+            }
             PatternUnits(CoordUnits::UserSpaceOnUse) => (
                 rect.width(),
                 rect.height(),
@@ -381,6 +386,7 @@ impl ResolvedPattern {
         } else {
             match self.content_units {
                 PatternContentUnits(CoordUnits::ObjectBoundingBox) => {
+                    let bbrect = nonempty_rect_from_bbox(bbox)?;
                     Transform::new_scale(bbrect.width(), bbrect.height())
                 }
                 PatternContentUnits(CoordUnits::UserSpaceOnUse) => Transform::identity(),
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6cbc21b63..62ad4544a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -76,6 +76,7 @@ test_fixtures =                                                               \
        $(wildcard $(srcdir)/fixtures/reftests/svg1.1/resources/*)      \
        $(wildcard $(srcdir)/fixtures/reftests/svg2/*.svg)              \
        $(wildcard $(srcdir)/fixtures/reftests/svg2/*.png)              \
+       $(wildcard $(srcdir)/fixtures/reftests/bugs-reftests/*.svg)     \
        $(wildcard $(srcdir)/fixtures/reftests/svg2-reftests/*.svg)     \
        $(wildcard $(srcdir)/fixtures/render-crash/*.svg)               \
        $(wildcard $(srcdir)/fixtures/text/*.svg)                       \
diff --git a/tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line-ref.svg 
b/tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line-ref.svg
new file mode 100644
index 000000000..a80e56324
--- /dev/null
+++ b/tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line-ref.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; width="400" height="400">
+  <rect x="0" y="0" width="400" height="400" fill="lime"/>
+</svg>
diff --git a/tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line.svg 
b/tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line.svg
new file mode 100644
index 000000000..4e22470f6
--- /dev/null
+++ b/tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line.svg
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; width="400" height="400">
+  <!-- Two lines, one horizontal and one vertical, that have an empty objectBoundingBox.
+       However, they have a stroke with a userSpaceOnUse pattern, which *should* be drawn.
+  -->
+
+  <pattern id="pat" x="0" y="0" width="400" height="400" patternUnits="userSpaceOnUse">
+    <rect x="0" y="0" width="400" height="400" fill="lime"/>
+  </pattern>
+
+  <line x1="0" y1="100" x2="400" y2="100" stroke="url(#pat)" stroke-width="200"/>
+  <line x1="200" y1="200" x2="200" y2="400" stroke="url(#pat)" stroke-width="400"/>
+</svg>
diff --git a/tests/src/reference.rs b/tests/src/reference.rs
index 1eb088a01..665baec01 100644
--- a/tests/src/reference.rs
+++ b/tests/src/reference.rs
@@ -400,3 +400,9 @@ test_svg_reference!(
     "tests/fixtures/reftests/svg2-reftests/mask-and-opacity.svg",
     "tests/fixtures/reftests/svg2-reftests/mask-and-opacity-ref.svg"
 );
+
+test_svg_reference!(
+    bug_880_horizontal_vertical_stroked_lines,
+    "tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line.svg",
+    "tests/fixtures/reftests/bugs-reftests/880-stroke-wide-line-ref.svg"
+);


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