[librsvg] Let aspect.viewport_to_viewbox_transform() deal with whether the vbox exists or not



commit 884dfb1ad5a8c6cd78e3ac123fe2256268fea2ad
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Feb 20 12:55:42 2019 -0600

    Let aspect.viewport_to_viewbox_transform() deal with whether the vbox exists or not

 rsvg_internals/src/aspect_ratio.rs |  2 ++
 rsvg_internals/src/drawing_ctx.rs  | 31 +++++++++++++------------------
 2 files changed, 15 insertions(+), 18 deletions(-)
---
diff --git a/rsvg_internals/src/aspect_ratio.rs b/rsvg_internals/src/aspect_ratio.rs
index 7c1352b8..77d8c185 100644
--- a/rsvg_internals/src/aspect_ratio.rs
+++ b/rsvg_internals/src/aspect_ratio.rs
@@ -155,6 +155,8 @@ impl AspectRatio {
         vbox: Option<ViewBox>,
         viewport: &cairo::Rectangle,
     ) -> Option<cairo::Matrix> {
+        // the preserveAspectRatio attribute is only used if viewBox is specified
+        // https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
         if let Some(vbox) = vbox {
             if vbox.width.approx_eq_cairo(&0.0) || vbox.height.approx_eq_cairo(&0.0) {
                 // Width or height of 0 for the viewBox disables rendering of the element
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 630e7207..c159bc48 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -239,33 +239,28 @@ impl DrawingCtx {
             }
         }
 
-        if let Some(vbox) = vbox {
-            // the preserveAspectRatio attribute is only used if viewBox is specified
-            // https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
-
-            if let Some(matrix) =
-                preserve_aspect_ratio.viewport_to_viewbox_transform(Some(vbox), viewport)
-            {
-                let params = self.push_view_box(vbox.width, vbox.height);
+        if let Some(matrix) = preserve_aspect_ratio.viewport_to_viewbox_transform(vbox, viewport) {
+            let params = if let Some(ref vbox) = vbox {
+                self.push_view_box(vbox.width, vbox.height)
+            } else {
+                self.get_view_params()
+            };
 
-                self.cr.transform(matrix);
+            self.cr.transform(matrix);
 
+            if let Some(ref vbox) = vbox {
                 if let Some(ref clip) = clip_mode {
                     if *clip == ClipMode::ClipToVbox {
                         self.clip(vbox.x, vbox.y, vbox.width, vbox.height);
                     }
                 }
-
-                Some(params)
-            } else {
-                // Width or height of 0 for the viewBox disables rendering of the element
-                // https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
-                return None;
             }
-        } else {
-            let params = self.push_view_box(viewport.width, viewport.height);
-            self.cr.translate(viewport.x, viewport.y);
+
             Some(params)
+        } else {
+            // Width or height of 0 for the viewBox disables rendering of the element
+            // https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
+            None
         }
     }
 


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