[librsvg] Extract function to check the status of a Cairo context



commit 6dc6e975cb0da671a02b03aa83825be2ba690902
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Feb 19 18:07:27 2019 -0600

    Extract function to check the status of a Cairo context

 rsvg_internals/src/handle.rs | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index ee43ca8a..fb5095c8 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -505,16 +505,7 @@ impl Handle {
         cr: &cairo::Context,
         id: Option<&str>,
     ) -> Result<(), RenderingError> {
-        let status = cr.status();
-        if status != Status::Success {
-            let msg = format!(
-                "cannot render on a cairo_t with a failure status (status={:?})",
-                status,
-            );
-
-            rsvg_g_warning(&msg);
-            return Err(RenderingError::Cairo(status));
-        }
+        check_cairo_context(cr)?;
 
         let node = if let Some(id) = id {
             Some(self.lookup_node(id).map_err(RenderingError::InvalidId)?)
@@ -568,6 +559,21 @@ impl Handle {
     }
 }
 
+fn check_cairo_context(cr: &cairo::Context) -> Result<(), RenderingError> {
+    let status = cr.status();
+    if status == Status::Success {
+        Ok(())
+    } else {
+        let msg = format!(
+            "cannot render on a cairo_t with a failure status (status={:?})",
+            status,
+        );
+
+        rsvg_g_warning(&msg);
+        Err(RenderingError::Cairo(status))
+    }
+}
+
 // Keep these in sync with rsvg.h:RsvgHandleFlags
 const RSVG_HANDLE_FLAG_UNLIMITED: u32 = 1 << 0;
 const RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA: u32 = 1 << 1;


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