[librsvg/librsvg-2.46] (#521): Compute geometries correctly if there is a viewBox attribute



commit 6a1258a00a4cac4fb0f43b7bb32783c537a8af94
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Oct 22 10:51:18 2019 -0500

    (#521): Compute geometries correctly if there is a viewBox attribute
    
    Commit a2b34631 broke geometry computation of elements when the
    toplevel SVG has a viewBox attribute.
    
    Every time we change the matrix to draw, we need to retransform the
    drawings's resulting bbox to the original matrix.
    
    Fixes https://gitlab.gnome.org/GNOME/librsvg/issues/521

 rsvg_internals/src/drawing_ctx.rs              | 9 ++++++++-
 tests/dimensions.c                             | 7 +++++++
 tests/fixtures/dimensions/521-with-viewbox.svg | 4 ++++
 3 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index d8b24cc3..a06af390 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -546,7 +546,14 @@ impl DrawingCtx {
         let matrix = self.cr.get_matrix();
         let res = draw_fn(self);
         self.cr.set_matrix(matrix);
-        res
+
+        if let Ok(bbox) = res {
+            let mut orig_matrix_bbox = BoundingBox::new(&matrix);
+            orig_matrix_bbox.insert(&bbox);
+            Ok(orig_matrix_bbox)
+        } else {
+            res
+        }
     }
 
     /// Saves the current Cairo context, runs the draw_fn, and restores the context
diff --git a/tests/dimensions.c b/tests/dimensions.c
index b070b22f..186d66ad 100644
--- a/tests/dimensions.c
+++ b/tests/dimensions.c
@@ -113,6 +113,13 @@ static FixtureData fixtures[] =
         80, 48.90, 0, 0,
         TRUE, FALSE
     },
+    {
+        "/dimensions/with-viewbox",
+        "dimensions/521-with-viewbox.svg",
+        "#foo",
+        50.0, 60.0, 70.0, 80.0,
+        TRUE, TRUE
+    },
 };
 
 static const gint n_fixtures = G_N_ELEMENTS (fixtures);
diff --git a/tests/fixtures/dimensions/521-with-viewbox.svg b/tests/fixtures/dimensions/521-with-viewbox.svg
new file mode 100644
index 00000000..c3f34e6d
--- /dev/null
+++ b/tests/fixtures/dimensions/521-with-viewbox.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="200" height="100" viewBox="0 0 2000 1000">
+  <rect id="foo" x="500" y="600" width="700" height="800"/>
+</svg>


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