[librsvg] Svg.get_size() - use length.normalize(), not hand_normalize()



commit 8779fed0484aa14ca3acd096b55a64a95aac3814
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Feb 19 13:47:37 2019 -0600

    Svg.get_size() - use length.normalize(), not hand_normalize()
    
    To do this, we construct a ViewParams out-of-band with the NodeSvg's
    viewBox.  This should eventually go away.

 rsvg_internals/src/drawing_ctx.rs |  1 -
 rsvg_internals/src/structure.rs   | 19 +++++++++++++------
 2 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 69255fc7..59899667 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -54,7 +54,6 @@ pub struct ViewParams {
 }
 
 impl ViewParams {
-    #[cfg(test)]
     pub fn new(dpi_x: f64, dpi_y: f64, view_box_width: f64, view_box_height: f64) -> ViewParams {
         ViewParams {
             dpi_x,
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index c020e973..f67c2a51 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -140,14 +140,21 @@ impl NodeSvg {
         let (_, _, w, h) = self.get_unnormalized_viewport();
 
         match (w, h, self.vbox.get()) {
-            (w, h, Some(vbox)) => Some((
-                w.hand_normalize(dpi.x(), vbox.width, 12.0).round() as i32,
-                h.hand_normalize(dpi.y(), vbox.height, 12.0).round() as i32,
-            )),
+            (w, h, Some(vbox)) => {
+                let params = ViewParams::new(dpi.x(), dpi.y(), vbox.width, vbox.height);
+
+                Some((
+                    w.normalize(values, &params).round() as i32,
+                    h.normalize(values, &params).round() as i32,
+                ))
+            }
+
             (w, h, None) if w.unit() != LengthUnit::Percent && h.unit() != LengthUnit::Percent => {
+                let params = ViewParams::new(dpi.x(), dpi.y(), 0.0, 0.0);
+
                 Some((
-                    w.hand_normalize(dpi.x(), 0.0, 12.0).round() as i32,
-                    h.hand_normalize(dpi.y(), 0.0, 12.0).round() as i32,
+                    w.normalize(values, &params).round() as i32,
+                    h.normalize(values, &params).round() as i32,
                 ))
             }
             (_, _, _) => None,


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