[librsvg: 33/90] DrawingCtx.with_saved_cr() - new function



commit 1bddf634962c4c9af6060f01fa16e002620d270a
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 13 18:14:05 2019 -0600

    DrawingCtx.with_saved_cr() - new function

 rsvg_internals/src/drawing_ctx.rs | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 001d7d54..56e3ec14 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -544,6 +544,17 @@ impl DrawingCtx {
         res
     }
 
+    /// Saves the current Cairo context, runs the draw_fn, and restores the context
+    pub fn with_saved_cr(
+        &mut self,
+        draw_fn: &mut FnMut(&mut DrawingCtx) -> Result<(), RenderingError>,
+    ) -> Result<(), RenderingError> {
+        self.cr.save();
+        let res = draw_fn(self);
+        self.cr.restore();
+        res
+    }
+
     fn run_filter(
         &mut self,
         filter_uri: &Fragment,


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