[librsvg: 18/38] Store a complete ViewBox in ViewParams, not just the size




commit f1a7cc2d947ea986c3e3dd263390f23600b1166b
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Sep 22 11:10:13 2020 -0500

    Store a complete ViewBox in ViewParams, not just the size
    
    We'll move to a model where we pass the current viewport around, which
    is partly defined by a ViewBox.

 rsvg_internals/src/drawing_ctx.rs | 20 ++++++++------------
 rsvg_internals/src/length.rs      |  3 +--
 2 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index f4717bf4..3b41b1ca 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -54,8 +54,7 @@ use crate::viewbox::ViewBox;
 /// previous viewport.
 pub struct ViewParams {
     pub dpi: Dpi,
-    pub view_box_width: f64,
-    pub view_box_height: f64,
+    pub vbox: ViewBox,
     view_box_stack: Option<Weak<RefCell<Vec<ViewBox>>>>,
 }
 
@@ -63,8 +62,7 @@ impl ViewParams {
     pub fn new(dpi: Dpi, view_box_width: f64, view_box_height: f64) -> ViewParams {
         ViewParams {
             dpi,
-            view_box_width,
-            view_box_height,
+            vbox: ViewBox::from(Rect::from_size(view_box_width, view_box_height)),
             view_box_stack: None,
         }
     }
@@ -294,12 +292,11 @@ impl DrawingCtx {
     pub fn get_view_params(&self) -> ViewParams {
         let view_box_stack = self.view_box_stack.borrow();
         let last = view_box_stack.len() - 1;
-        let top_rect = &view_box_stack[last];
+        let vbox = view_box_stack[last];
 
         ViewParams {
             dpi: self.dpi,
-            view_box_width: top_rect.width(),
-            view_box_height: top_rect.height(),
+            vbox,
             view_box_stack: None,
         }
     }
@@ -312,14 +309,13 @@ impl DrawingCtx {
     /// The viewport will stay in place, and will be the one returned by
     /// `get_view_params()`, until the returned `ViewParams` is dropped.
     pub fn push_view_box(&self, width: f64, height: f64) -> ViewParams {
-        self.view_box_stack
-            .borrow_mut()
-            .push(ViewBox::from(Rect::from_size(width, height)));
+        let vbox = ViewBox::from(Rect::from_size(width, height));
+
+        self.view_box_stack.borrow_mut().push(vbox);
 
         ViewParams {
             dpi: self.dpi,
-            view_box_width: width,
-            view_box_height: height,
+            vbox,
             view_box_stack: Some(Rc::downgrade(&self.view_box_stack)),
         }
     }
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index aadc5c64..85d5d2ae 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -321,8 +321,7 @@ impl<N: Normalize> Length<N> {
             LengthUnit::Px => self.length,
 
             LengthUnit::Percent => {
-                self.length
-                    * <N as Normalize>::normalize(params.view_box_width, params.view_box_height)
+                self.length * <N as Normalize>::normalize(params.vbox.width(), params.vbox.height())
             }
 
             LengthUnit::Em => self.length * font_size_from_values(values, params),


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