[librsvg/wip/dimensions-api] draw_in_viewport(): represent do_clip/clip_mode with an Option<ClipMode>



commit ee14ee918e6e69d408e4359f4948293dd0f0976c
Author: Federico Mena Quintero <federico gnome org>
Date:   Sat Feb 9 11:09:11 2019 -0600

    draw_in_viewport(): represent do_clip/clip_mode with an Option<ClipMode>

 rsvg_internals/src/structure.rs | 21 ++++++++++++++-------
 rsvg_internals/src/viewport.rs  | 17 ++++++++++-------
 2 files changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index e2a89d92..5df520fe 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -230,12 +230,15 @@ impl NodeTrait for NodeSvg {
             self.h.get().normalize(values, &params),
         );
 
-        let do_clip = !values.is_overflow() && node.get_parent().is_some();
+        let clip_mode = if !values.is_overflow() && node.get_parent().is_some() {
+            Some(ClipMode::ClipToViewport)
+        } else {
+            None
+        };
 
         draw_in_viewport(
             &viewport,
-            ClipMode::ClipToViewport,
-            do_clip,
+            clip_mode,
             self.vbox.get(),
             self.preserve_aspect_ratio.get(),
             node,
@@ -379,13 +382,17 @@ impl NodeTrait for NodeUse {
             })
         } else {
             child.with_impl(|symbol: &NodeSymbol| {
-                let do_clip = !values.is_overflow()
-                    || (values.overflow == Overflow::Visible && child.is_overflow());
+                let clip_mode = if !values.is_overflow()
+                    || (values.overflow == Overflow::Visible && child.is_overflow())
+                {
+                    Some(ClipMode::ClipToVbox)
+                } else {
+                    None
+                };
 
                 draw_in_viewport(
                     &viewport,
-                    ClipMode::ClipToVbox,
-                    do_clip,
+                    clip_mode,
                     symbol.vbox.get(),
                     symbol.preserve_aspect_ratio.get(),
                     node,
diff --git a/rsvg_internals/src/viewport.rs b/rsvg_internals/src/viewport.rs
index 25203fec..4dec4bae 100644
--- a/rsvg_internals/src/viewport.rs
+++ b/rsvg_internals/src/viewport.rs
@@ -17,8 +17,7 @@ pub enum ClipMode {
 
 pub fn draw_in_viewport(
     viewport: &Rectangle,
-    clip_mode: ClipMode,
-    do_clip: bool,
+    clip_mode: Option<ClipMode>,
     vbox: Option<ViewBox>,
     preserve_aspect_ratio: AspectRatio,
     node: &RsvgNode,
@@ -39,9 +38,11 @@ pub fn draw_in_viewport(
     }
 
     draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
-        if do_clip && clip_mode == ClipMode::ClipToViewport {
-            dc.get_cairo_context().set_matrix(affine);
-            dc.clip(viewport.x, viewport.y, viewport.width, viewport.height);
+        if let Some(ref clip) = clip_mode {
+            if *clip == ClipMode::ClipToViewport {
+                dc.get_cairo_context().set_matrix(affine);
+                dc.clip(viewport.x, viewport.y, viewport.width, viewport.height);
+            }
         }
 
         let _params = if let Some(vbox) = vbox {
@@ -64,8 +65,10 @@ pub fn draw_in_viewport(
 
             dc.get_cairo_context().set_matrix(affine);
 
-            if do_clip && clip_mode == ClipMode::ClipToVbox {
-                dc.clip(vbox.x, vbox.y, vbox.width, vbox.height);
+            if let Some(ref clip) = clip_mode {
+                if *clip == ClipMode::ClipToVbox {
+                    dc.clip(vbox.x, vbox.y, vbox.width, vbox.height);
+                }
             }
 
             params


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