[librsvg: 30/90] DrawingCtx.with_saved_matrix() - new function



commit 2bef6ae69126da374d42551d07efba3b0f48ab17
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 13 17:46:09 2019 -0600

    DrawingCtx.with_saved_matrix() - new function

 rsvg_internals/src/drawing_ctx.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index ade1012c..001d7d54 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -528,6 +528,22 @@ impl DrawingCtx {
         }
     }
 
+    /// Saves the current Cairo matrix, runs the draw_fn, and restores the matrix
+    ///
+    /// This is slightly cheaper than a `cr.save()` / `cr.restore()`
+    /// pair, but more importantly, it does not reset the whole
+    /// graphics state, i.e. it leaves a clipping path in place if it
+    /// was set by the `draw_fn`.
+    pub fn with_saved_matrix(
+        &mut self,
+        draw_fn: &mut FnMut(&mut DrawingCtx) -> Result<(), RenderingError>,
+    ) -> Result<(), RenderingError> {
+        let matrix = self.cr.get_matrix();
+        let res = draw_fn(self);
+        self.cr.set_matrix(matrix);
+        res
+    }
+
     fn run_filter(
         &mut self,
         filter_uri: &Fragment,


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