[librsvg: 11/15] Inline part of DrawingCtx::new into its only caller, draw_tree




commit 8a64f76b0cf7bb8b46db7df605f43eb37ff84fb3
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Nov 18 10:07:11 2020 -0600

    Inline part of DrawingCtx::new into its only caller, draw_tree
    
    The idea is to compute the initial transform in the caller.

 src/drawing_ctx.rs | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index b693e083..9aa4239a 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -185,10 +185,32 @@ pub fn draw_tree(
 
     let cascaded = CascadedValues::new_from_node(&node);
 
+    // Preserve the user's transform and use it for the outermost bounding box.  All bounds/extents
+    // will be converted to this transform in the end.
+    let user_transform = Transform::from(cr.get_matrix());
+    let mut bbox = BoundingBox::new().with_transform(user_transform);
+
+    // https://www.w3.org/TR/SVG2/coords.html#InitialCoordinateSystem
+    //
+    // "For the outermost svg element, the SVG user agent must
+    // determine an initial viewport coordinate system and an
+    // initial user coordinate system such that the two
+    // coordinates systems are identical. The origin of both
+    // coordinate systems must be at the origin of the SVG
+    // viewport."
+    //
+    // "... the initial viewport coordinate system (and therefore
+    // the initial user coordinate system) must have its origin at
+    // the top/left of the viewport"
+
+    // Translate so (0, 0) is at the viewport's upper-left corner.
+    cr.translate(viewport.x0, viewport.y0);
     let transform = Transform::from(cr.get_matrix());
-    let mut bbox = BoundingBox::new().with_transform(transform);
 
-    let mut draw_ctx = DrawingCtx::new(cr, viewport, dpi, measuring, testing, drawsub_stack);
+    // Per the spec, so the viewport has (0, 0) as upper-left.
+    let viewport = viewport.translate((-viewport.x0, -viewport.y0));
+
+    let mut draw_ctx = DrawingCtx::new(cr, transform, viewport, dpi, measuring, testing, drawsub_stack);
 
     let content_bbox = draw_ctx.draw_node_from_stack(&node, acquired_nodes, &cascaded, false)?;
 
@@ -200,33 +222,14 @@ pub fn draw_tree(
 impl DrawingCtx {
     fn new(
         cr: &cairo::Context,
+        transform: Transform,
         viewport: Rect,
         dpi: Dpi,
         measuring: bool,
         testing: bool,
         drawsub_stack: Vec<Node>,
     ) -> DrawingCtx {
-        // https://www.w3.org/TR/SVG2/coords.html#InitialCoordinateSystem
-        //
-        // "For the outermost svg element, the SVG user agent must
-        // determine an initial viewport coordinate system and an
-        // initial user coordinate system such that the two
-        // coordinates systems are identical. The origin of both
-        // coordinate systems must be at the origin of the SVG
-        // viewport."
-        //
-        // "... the initial viewport coordinate system (and therefore
-        // the initial user coordinate system) must have its origin at
-        // the top/left of the viewport"
-
-        // Translate so (0, 0) is at the viewport's upper-left corner.
-        cr.translate(viewport.x0, viewport.y0);
-        let transform = Transform::from(cr.get_matrix());
-
-        // Per the spec, so the viewport has (0, 0) as upper-left.
-        let viewport = viewport.translate((-viewport.x0, -viewport.y0));
         let vbox = ViewBox::from(viewport);
-
         let initial_viewport = Viewport { transform, vbox };
 
         let mut viewport_stack = Vec::new();


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