[librsvg: 2/7] clip_path: move cairo clipping in drawing_ctx



commit e0c4fb11b767e44650ef3b08d9d26b827abb12d8
Author: Paolo Borelli <pborelli gnome org>
Date:   Thu Jan 2 10:34:44 2020 +0100

    clip_path: move cairo clipping in drawing_ctx
    
    This is another small step forward decoupling nodes from cairo
    specifics.

 rsvg_internals/src/clip_path.rs   | 51 +--------------------------------------
 rsvg_internals/src/drawing_ctx.rs | 41 ++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 53 deletions(-)
---
diff --git a/rsvg_internals/src/clip_path.rs b/rsvg_internals/src/clip_path.rs
index df1997cc..4bdfcb1e 100644
--- a/rsvg_internals/src/clip_path.rs
+++ b/rsvg_internals/src/clip_path.rs
@@ -1,13 +1,9 @@
 //! The `clipPath` element.
 
-use cairo;
 use markup5ever::{expanded_name, local_name, namespace_url, ns};
 
-use crate::bbox::BoundingBox;
 use crate::coord_units::CoordUnits;
-use crate::drawing_ctx::DrawingCtx;
-use crate::error::RenderingError;
-use crate::node::{CascadedValues, NodeDraw, NodeResult, NodeTrait, RsvgNode};
+use crate::node::{NodeResult, NodeTrait, RsvgNode};
 use crate::parsers::ParseValue;
 use crate::property_bag::PropertyBag;
 
@@ -22,51 +18,6 @@ impl ClipPath {
     pub fn get_units(&self) -> CoordUnits {
         CoordUnits::from(self.units)
     }
-
-    pub fn to_cairo_context(
-        &self,
-        node: &RsvgNode,
-        draw_ctx: &mut DrawingCtx,
-        bbox: &BoundingBox,
-    ) -> Result<(), RenderingError> {
-        if self.units == ClipPathUnits(CoordUnits::ObjectBoundingBox) && bbox.rect.is_none() {
-            // The node being clipped is empty / doesn't have a
-            // bounding box, so there's nothing to clip!
-            return Ok(());
-        }
-
-        let cascaded = CascadedValues::new_from_node(node);
-
-        draw_ctx
-            .with_saved_matrix(&mut |dc| {
-                let cr = dc.get_cairo_context();
-
-                if self.units == ClipPathUnits(CoordUnits::ObjectBoundingBox) {
-                    let bbox_rect = bbox.rect.as_ref().unwrap();
-
-                    cr.transform(cairo::Matrix::new(
-                        bbox_rect.width(),
-                        0.0,
-                        0.0,
-                        bbox_rect.height(),
-                        bbox_rect.x0,
-                        bbox_rect.y0,
-                    ))
-                }
-
-                // here we don't push a layer because we are clipping
-                let res = node.draw_children(&cascaded, dc, true);
-
-                cr.clip();
-
-                res
-            })
-            .and_then(|_bbox|
-                      // Clipping paths do not contribute to bounding boxes (they should,
-                      // but we need Real Computational Geometry(tm), so ignore the
-                      // bbox from the clip path.
-                      Ok(()))
-    }
 }
 
 impl NodeTrait for ClipPath {
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index d58f1031..1f53e4ce 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -365,9 +365,44 @@ impl DrawingCtx {
         bbox: &BoundingBox,
     ) -> Result<(), RenderingError> {
         if let Some(node) = clip_node {
-            let node_data = node.borrow();
-            let clip_path = node_data.get_impl::<ClipPath>();
-            clip_path.to_cairo_context(&node, self, &bbox)
+            let units = node.borrow().get_impl::<ClipPath>().get_units();
+
+            if units == CoordUnits::ObjectBoundingBox && bbox.rect.is_none() {
+                // The node being clipped is empty / doesn't have a
+                // bounding box, so there's nothing to clip!
+                return Ok(());
+            }
+
+            let cascaded = CascadedValues::new_from_node(node);
+
+            self.with_saved_matrix(&mut |dc| {
+                let cr = dc.get_cairo_context();
+
+                if units == CoordUnits::ObjectBoundingBox {
+                    let bbox_rect = bbox.rect.as_ref().unwrap();
+
+                    cr.transform(cairo::Matrix::new(
+                        bbox_rect.width(),
+                        0.0,
+                        0.0,
+                        bbox_rect.height(),
+                        bbox_rect.x0,
+                        bbox_rect.y0,
+                    ))
+                }
+
+                // here we don't push a layer because we are clipping
+                let res = node.draw_children(&cascaded, dc, true);
+
+                cr.clip();
+
+                res
+            })
+            .and_then(|_bbox|
+                // Clipping paths do not contribute to bounding boxes (they should,
+                // but we need Real Computational Geometry(tm), so ignore the
+                // bbox from the clip path.
+                Ok(()))
         } else {
             Ok(())
         }


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