[librsvg: 7/14] initial port to gtk-rs 0.9




commit 28b0b281f7b7bd81016087694064baa587208de9
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Thu Jul 9 23:58:53 2020 +0200

    initial port to gtk-rs 0.9

 src/api.rs                          |  2 +-
 src/bin/rsvg-convert.rs             | 10 +++----
 src/c_api/handle.rs                 | 12 +++-----
 src/document.rs                     | 10 +++----
 src/drawing_ctx.rs                  |  6 ++--
 src/error.rs                        |  6 ++--
 src/filters/context.rs              |  2 +-
 src/filters/error.rs                |  8 ++---
 src/handle.rs                       | 10 +------
 src/io.rs                           |  2 +-
 src/path_builder.rs                 | 13 +++-----
 src/surface_utils/shared_surface.rs | 59 ++++++++++++++++---------------------
 src/surface_utils/srgb.rs           |  6 ++--
 src/util.rs                         | 20 +++++++++++++
 tests/src/compare_surfaces.rs       |  2 +-
 tests/src/reference.rs              |  2 +-
 tests/src/utils.rs                  |  2 +-
 17 files changed, 83 insertions(+), 89 deletions(-)
---
diff --git a/src/api.rs b/src/api.rs
index 228a1d61..053c7b2a 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -61,7 +61,7 @@
 //!             </svg>
 //!         "#
 //!     );
-//!     let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
+//!     let stream = gio::MemoryInputStream::from_bytes(&bytes);
 //!
 //!     let handle = librsvg::Loader::new().read_stream(
 //!         &stream,
diff --git a/src/bin/rsvg-convert.rs b/src/bin/rsvg-convert.rs
index fd113c65..04b70815 100644
--- a/src/bin/rsvg-convert.rs
+++ b/src/bin/rsvg-convert.rs
@@ -21,10 +21,10 @@ impl std::fmt::Display for Error {
     }
 }
 
-impl From<cairo::Status> for Error {
-    fn from(s: cairo::Status) -> Self {
+impl From<cairo::Error> for Error {
+    fn from(s: cairo::Error) -> Self {
         match s {
-            cairo::Status::InvalidSize => Self(String::from(
+            cairo::Error::InvalidSize => Self(String::from(
                 "The resulting image would be larger than 32767 pixels on either dimension.\n\
                 Librsvg currently cannot render to images bigger than that.\n\
                 Please specify a smaller size.",
@@ -296,8 +296,8 @@ impl Surface {
     }
 }
 
-fn checked_i32(x: f64) -> Result<i32, cairo::Status> {
-    cast::i32(x).map_err(|_| cairo::Status::InvalidSize)
+fn checked_i32(x: f64) -> Result<i32, cairo::Error> {
+    cast::i32(x).map_err(|_| cairo::Error::InvalidSize)
 }
 
 mod metadata {
diff --git a/src/c_api/handle.rs b/src/c_api/handle.rs
index 23fe626e..e05535fe 100644
--- a/src/c_api/handle.rs
+++ b/src/c_api/handle.rs
@@ -546,8 +546,8 @@ impl ObjectImpl for CHandle {
 }
 
 // Keep in sync with tests/src/reference.rs
-pub(crate) fn checked_i32(x: f64) -> Result<i32, cairo::Status> {
-    cast::i32(x).map_err(|_| cairo::Status::InvalidSize)
+pub(crate) fn checked_i32(x: f64) -> Result<i32, cairo::Error> {
+    cast::i32(x).map_err(|_| cairo::Error::InvalidSize)
 }
 
 // Keep in sync with rsvg.h:RsvgPositionData
@@ -794,7 +794,7 @@ impl CHandle {
 
             LoadState::Loading { ref buffer } => {
                 let bytes = Bytes::from(&*buffer);
-                let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
+                let stream = gio::MemoryInputStream::from_bytes(&bytes);
 
                 let base_file = inner.base_url.get_gfile();
                 self.read_stream(state, &stream.upcast(), base_file.as_ref(), None)
@@ -1956,8 +1956,6 @@ pub unsafe extern "C" fn rsvg_handle_get_geometry_for_layer(
             if !out_logical_rect.is_null() {
                 *out_logical_rect = logical_rect;
             }
-
-            ()
         })
         .into_gerror(error)
 }
@@ -2016,8 +2014,6 @@ pub unsafe extern "C" fn rsvg_handle_get_geometry_for_element(
             if !out_logical_rect.is_null() {
                 *out_logical_rect = logical_rect;
             }
-
-            ()
         })
         .into_gerror(error)
 }
@@ -2168,7 +2164,7 @@ fn check_cairo_context(cr: *mut cairo_sys::cairo_t) -> Result<cairo::Context, Re
     if status == cairo_sys::STATUS_SUCCESS {
         Ok(unsafe { from_glib_none(cr) })
     } else {
-        let status: cairo::Status = status.into();
+        let status: cairo::Error = status.into();
 
         let msg = format!(
             "cannot render on a cairo_t with a failure status (status={:?})",
diff --git a/src/document.rs b/src/document.rs
index bce51a77..2720717d 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -112,7 +112,7 @@ impl Document {
         use glib::prelude::*;
 
         let bytes = glib::Bytes::from_static(input);
-        let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
+        let stream = gio::MemoryInputStream::from_bytes(&bytes);
 
         Document::load_from_stream(
             &LoadOptions::new(UrlResolver::new(None)),
@@ -260,7 +260,7 @@ fn load_image(
     let content_type = content_type_for_gdk_pixbuf(&mime_type);
 
     let loader = if let Some(ref content_type) = content_type {
-        PixbufLoader::new_with_mime_type(content_type)?
+        PixbufLoader::with_mime_type(content_type)?
     } else {
         PixbufLoader::new()
     };
@@ -308,12 +308,12 @@ fn human_readable_url(aurl: &AllowedUrl) -> &str {
     }
 }
 
-fn image_loading_error_from_cairo(status: cairo::Status, aurl: &AllowedUrl) -> LoadingError {
+fn image_loading_error_from_cairo(status: cairo::Error, aurl: &AllowedUrl) -> LoadingError {
     let url = human_readable_url(aurl);
 
     match status {
-        cairo::Status::NoMemory => LoadingError::OutOfMemory(format!("loading image: {}", url)),
-        cairo::Status::InvalidSize => LoadingError::Other(format!("image too big: {}", url)),
+        cairo::Error::NoMemory => LoadingError::OutOfMemory(format!("loading image: {}", url)),
+        cairo::Error::InvalidSize => LoadingError::Other(format!("image too big: {}", url)),
         _ => LoadingError::Other(format!("cairo error: {}", status)),
     }
 }
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 7f84d654..99d07188 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -111,7 +111,7 @@ impl<'a> PathHelper<'a> {
         }
     }
 
-    pub fn set(&mut self) -> Result<(), cairo::Status> {
+    pub fn set(&mut self) -> Result<(), RenderingError> {
         match self.has_path {
             Some(false) | None => {
                 self.has_path = Some(true);
@@ -1145,7 +1145,7 @@ impl DrawingCtx {
         height: i32,
         acquired_nodes: &mut AcquiredNodes<'_>,
         paint_source: &UserSpacePaintSource,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let mut surface = ExclusiveImageSurface::new(width, height, SurfaceType::SRgb)?;
 
         surface.draw(&mut |cr| {
@@ -1477,7 +1477,7 @@ impl DrawingCtx {
         &self,
         width: i32,
         height: i32,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         // TODO: as far as I can tell this should not render elements past the last (topmost) one
         // with enable-background: new (because technically we shouldn't have been caching them).
         // Right now there are no enable-background checks whatsoever.
diff --git a/src/error.rs b/src/error.rs
index f3d1b246..75bd25b4 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -161,10 +161,8 @@ impl fmt::Display for RenderingError {
     }
 }
 
-impl From<cairo::Status> for RenderingError {
-    fn from(e: cairo::Status) -> RenderingError {
-        assert!(e != cairo::Status::Success);
-
+impl From<cairo::Error> for RenderingError {
+    fn from(e: cairo::Error) -> RenderingError {
         RenderingError::Rendering(format!("{:?}", e))
     }
 }
diff --git a/src/filters/context.rs b/src/filters/context.rs
index e377289c..54c38671 100644
--- a/src/filters/context.rs
+++ b/src/filters/context.rs
@@ -256,7 +256,7 @@ impl FilterContext {
     /// The returned surface is in the sRGB color space.
     // TODO: sRGB conversion should probably be done by the caller.
     #[inline]
-    pub fn into_output(self) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn into_output(self) -> Result<SharedImageSurface, cairo::Error> {
         match self.last_result {
             Some(FilterOutput { surface, bounds }) => surface.to_srgb(bounds),
             None => SharedImageSurface::empty(
diff --git a/src/filters/error.rs b/src/filters/error.rs
index 82bf4ee2..2e30ce1a 100644
--- a/src/filters/error.rs
+++ b/src/filters/error.rs
@@ -12,12 +12,12 @@ pub enum FilterError {
     /// The filter was passed an invalid parameter.
     InvalidParameter(String),
     /// The filter input surface has an unsuccessful status.
-    BadInputSurfaceStatus(cairo::Status),
+    BadInputSurfaceStatus(cairo::Error),
     /// A Cairo error.
     ///
     /// This means that either a failed intermediate surface creation or bad intermediate surface
     /// status.
-    CairoError(cairo::Status),
+    CairoError(cairo::Error),
     /// Error from the rendering backend.
     Rendering(RenderingError),
     /// A lighting filter has none or multiple light sources.
@@ -52,9 +52,9 @@ impl fmt::Display for FilterError {
     }
 }
 
-impl From<cairo::Status> for FilterError {
+impl From<cairo::Error> for FilterError {
     #[inline]
-    fn from(x: cairo::Status) -> Self {
+    fn from(x: cairo::Error) -> Self {
         FilterError::CairoError(x)
     }
 }
diff --git a/src/handle.rs b/src/handle.rs
index 0d13da26..2f9c0e70 100644
--- a/src/handle.rs
+++ b/src/handle.rs
@@ -12,6 +12,7 @@ use crate::node::{CascadedValues, Node, NodeBorrow};
 use crate::rect::Rect;
 use crate::structure::IntrinsicDimensions;
 use crate::url_resolver::{AllowedUrl, UrlResolver};
+use crate::util::check_cairo_context;
 
 /// Loading options for SVG documents.
 #[derive(Clone)]
@@ -368,15 +369,6 @@ impl Handle {
     }
 }
 
-fn check_cairo_context(cr: &cairo::Context) -> Result<(), RenderingError> {
-    let status = cr.status();
-    if status == cairo::Status::Success {
-        Ok(())
-    } else {
-        Err(RenderingError::from(status))
-    }
-}
-
 fn unit_rectangle() -> Rect {
     Rect::from_size(1.0, 1.0)
 }
diff --git a/src/io.rs b/src/io.rs
index bb787bbe..8d6067d0 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -81,7 +81,7 @@ pub fn acquire_stream(
         //            file.write_all(&data).unwrap();
         //        }
 
-        let stream = MemoryInputStream::new_from_bytes(&GBytes::from_owned(data));
+        let stream = MemoryInputStream::from_bytes(&GBytes::from_owned(data));
         Ok(stream.upcast::<InputStream>())
     } else {
         let file = GFile::new_for_uri(uri);
diff --git a/src/path_builder.rs b/src/path_builder.rs
index 0c74bb3f..f393e2c0 100644
--- a/src/path_builder.rs
+++ b/src/path_builder.rs
@@ -6,8 +6,9 @@ use std::f64;
 use std::f64::consts::*;
 use std::slice;
 
+use crate::error::RenderingError;
 use crate::float_eq_cairo::ApproxEqCairo;
-use crate::util::clamp;
+use crate::util::{check_cairo_context, clamp};
 
 #[derive(Debug, Copy, Clone, PartialEq)]
 pub struct LargeArc(pub bool);
@@ -638,7 +639,7 @@ impl Path {
         &self,
         cr: &cairo::Context,
         is_square_linecap: bool,
-    ) -> Result<(), cairo::Status> {
+    ) -> Result<(), RenderingError> {
         assert!(!self.is_empty());
 
         let mut coords = self.coords.iter();
@@ -680,13 +681,7 @@ impl Path {
         // * The *next* call to the cr will probably be something that actually checks the status
         //   (i.e. in cairo-rs), and we don't want to panic there.
 
-        let status = cr.status();
-
-        if status == cairo::Status::Success {
-            Ok(())
-        } else {
-            Err(status)
-        }
+        check_cairo_context(&cr)
     }
 }
 
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index c561ce25..b1949d4a 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -176,7 +176,7 @@ impl ImageSurface<Shared> {
     pub fn wrap(
         surface: cairo::ImageSurface,
         surface_type: SurfaceType,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         // get_pixel() assumes ARgb32.
         assert_eq!(surface.get_format(), cairo::Format::ARgb32);
 
@@ -192,9 +192,6 @@ impl ImageSurface<Shared> {
         assert!(width > 0 && height > 0);
 
         surface.flush();
-        if surface.status() != cairo::Status::Success {
-            return Err(surface.status());
-        }
 
         let data_ptr =
             NonNull::new(unsafe { cairo_sys::cairo_image_surface_get_data(surface.to_raw_none()) })
@@ -216,7 +213,7 @@ impl ImageSurface<Shared> {
     /// Creates a `SharedImageSurface` copying from a `cairo::ImageSurface`, even if it
     /// does not have a reference count of 1.
     #[inline]
-    pub fn copy_from_surface(surface: &cairo::ImageSurface) -> Result<Self, cairo::Status> {
+    pub fn copy_from_surface(surface: &cairo::ImageSurface) -> Result<Self, cairo::Error> {
         let copy = cairo::ImageSurface::create(
             cairo::Format::ARgb32,
             surface.get_width(),
@@ -234,11 +231,7 @@ impl ImageSurface<Shared> {
 
     /// Creates an empty `SharedImageSurface` of the given size and `type`.
     #[inline]
-    pub fn empty(
-        width: i32,
-        height: i32,
-        surface_type: SurfaceType,
-    ) -> Result<Self, cairo::Status> {
+    pub fn empty(width: i32, height: i32, surface_type: SurfaceType) -> Result<Self, cairo::Error> {
         let s = cairo::ImageSurface::create(cairo::Format::ARgb32, width, height)?;
 
         SharedImageSurface::wrap(s, surface_type)
@@ -246,7 +239,7 @@ impl ImageSurface<Shared> {
 
     /// Converts this `SharedImageSurface` back into a Cairo image surface.
     #[inline]
-    pub fn into_image_surface(self) -> Result<cairo::ImageSurface, cairo::Status> {
+    pub fn into_image_surface(self) -> Result<cairo::ImageSurface, cairo::Error> {
         let reference_count =
             unsafe { cairo_sys::cairo_surface_get_reference_count(self.surface.to_raw_none()) };
 
@@ -262,7 +255,7 @@ impl ImageSurface<Shared> {
         pixbuf: &Pixbuf,
         content_type: Option<&str>,
         mime_data: Option<Vec<u8>>,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         assert!(pixbuf.get_colorspace() == Colorspace::Rgb);
         assert!(pixbuf.get_bits_per_sample() == 8);
 
@@ -384,7 +377,7 @@ impl ImageSurface<Shared> {
 
     /// Returns a new `cairo::ImageSurface` with the same contents as the one stored in this
     /// `SharedImageSurface` within the given bounds.
-    fn copy_surface(&self, bounds: IRect) -> Result<cairo::ImageSurface, cairo::Status> {
+    fn copy_surface(&self, bounds: IRect) -> Result<cairo::ImageSurface, cairo::Error> {
         let output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
@@ -408,7 +401,7 @@ impl ImageSurface<Shared> {
         bounds: IRect,
         x: f64,
         y: f64,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface = cairo::ImageSurface::create(cairo::Format::ARgb32, width, height)?;
 
         {
@@ -432,7 +425,7 @@ impl ImageSurface<Shared> {
         bounds: IRect,
         x: f64,
         y: f64,
-    ) -> Result<(SharedImageSurface, IRect), cairo::Status> {
+    ) -> Result<(SharedImageSurface, IRect), cairo::Error> {
         let new_width = (f64::from(self.width) * x).ceil() as i32;
         let new_height = (f64::from(self.height) * y).ceil() as i32;
         let new_bounds = bounds.scale(x, y);
@@ -444,7 +437,7 @@ impl ImageSurface<Shared> {
     }
 
     /// Returns a surface with black background and alpha channel matching this surface.
-    pub fn extract_alpha(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn extract_alpha(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Error> {
         let mut output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
@@ -472,7 +465,7 @@ impl ImageSurface<Shared> {
     /// useful luminance data.
     ///
     /// This is to get a mask suitable for use with cairo_mask_surface().
-    pub fn to_mask(&self, opacity: UnitInterval) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn to_mask(&self, opacity: UnitInterval) -> Result<SharedImageSurface, cairo::Error> {
         let bounds = IRect::from_size(self.width, self.height);
 
         let mut output_surface =
@@ -495,7 +488,7 @@ impl ImageSurface<Shared> {
     ///
     /// HACK: this is storing unpremultiplied pixels in an ARGB32 image surface (which is supposed
     /// to be premultiplied pixels).
-    pub fn unpremultiply(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn unpremultiply(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Error> {
         // Unpremultiplication doesn't affect the alpha channel.
         if self.is_alpha_only() {
             return Ok(self.clone());
@@ -518,7 +511,7 @@ impl ImageSurface<Shared> {
 
     /// Converts the surface to the linear sRGB color space.
     #[inline]
-    pub fn to_linear_rgb(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn to_linear_rgb(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Error> {
         match self.surface_type {
             SurfaceType::LinearRgb | SurfaceType::AlphaOnly => Ok(self.clone()),
             _ => srgb::linearize_surface(self, bounds),
@@ -527,7 +520,7 @@ impl ImageSurface<Shared> {
 
     /// Converts the surface to the sRGB color space.
     #[inline]
-    pub fn to_srgb(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn to_srgb(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Error> {
         match self.surface_type {
             SurfaceType::SRgb | SurfaceType::AlphaOnly => Ok(self.clone()),
             _ => srgb::unlinearize_surface(self, bounds),
@@ -552,7 +545,7 @@ impl ImageSurface<Shared> {
         target: (i32, i32),
         kernel: &Matrix<f64, R, C, S>,
         edge_mode: EdgeMode,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         assert!(kernel.nrows() >= 1);
         assert!(kernel.ncols() >= 1);
 
@@ -949,7 +942,7 @@ impl ImageSurface<Shared> {
         bounds: IRect,
         kernel_size: usize,
         target: usize,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let mut output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
@@ -968,7 +961,7 @@ impl ImageSurface<Shared> {
         &self,
         bounds: IRect,
         color: cssparser::RGBA,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
@@ -997,7 +990,7 @@ impl ImageSurface<Shared> {
         bounds: IRect,
         dx: f64,
         dy: f64,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
@@ -1027,7 +1020,7 @@ impl ImageSurface<Shared> {
         bounds: Rect,
         image: &SharedImageSurface,
         rect: Option<Rect>,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
@@ -1061,7 +1054,7 @@ impl ImageSurface<Shared> {
 
     /// Creates a new surface with the size and content specified in `bounds`
     #[inline]
-    pub fn tile(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn tile(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, bounds.width(), bounds.height())?;
 
@@ -1083,7 +1076,7 @@ impl ImageSurface<Shared> {
         image: &SharedImageSurface,
         x: i32,
         y: i32,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
@@ -1118,7 +1111,7 @@ impl ImageSurface<Shared> {
         other: &SharedImageSurface,
         bounds: IRect,
         operator: cairo::Operator,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let output_surface = other.copy_surface(bounds)?;
 
         {
@@ -1154,7 +1147,7 @@ impl ImageSurface<Shared> {
         k2: f64,
         k3: f64,
         k4: f64,
-    ) -> Result<SharedImageSurface, cairo::Status> {
+    ) -> Result<SharedImageSurface, cairo::Error> {
         let mut output_surface = ExclusiveImageSurface::new(
             self.width,
             self.height,
@@ -1280,7 +1273,7 @@ impl ImageSurface<Exclusive> {
         width: i32,
         height: i32,
         surface_type: SurfaceType,
-    ) -> Result<ExclusiveImageSurface, cairo::Status> {
+    ) -> Result<ExclusiveImageSurface, cairo::Error> {
         let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, width, height)?;
 
         let (width, height) = (surface.get_width(), surface.get_height());
@@ -1308,7 +1301,7 @@ impl ImageSurface<Exclusive> {
     }
 
     #[inline]
-    pub fn share(self) -> Result<SharedImageSurface, cairo::Status> {
+    pub fn share(self) -> Result<SharedImageSurface, cairo::Error> {
         SharedImageSurface::wrap(self.surface, self.surface_type)
     }
 
@@ -1331,8 +1324,8 @@ impl ImageSurface<Exclusive> {
     #[inline]
     pub fn draw(
         &mut self,
-        draw_fn: &mut dyn FnMut(&cairo::Context) -> Result<(), cairo::Status>,
-    ) -> Result<(), cairo::Status> {
+        draw_fn: &mut dyn FnMut(&cairo::Context) -> Result<(), cairo::Error>,
+    ) -> Result<(), cairo::Error> {
         let cr = cairo::Context::new(&self.surface);
         draw_fn(&cr)
     }
diff --git a/src/surface_utils/srgb.rs b/src/surface_utils/srgb.rs
index a6676a57..0f6e110f 100644
--- a/src/surface_utils/srgb.rs
+++ b/src/surface_utils/srgb.rs
@@ -64,7 +64,7 @@ fn map_unpremultiplied_components<F: Fn(u8) -> u8>(
     bounds: IRect,
     f: F,
     new_type: SurfaceType,
-) -> Result<SharedImageSurface, cairo::Status> {
+) -> Result<SharedImageSurface, cairo::Error> {
     let (width, height) = (surface.width(), surface.height());
     let mut output_surface = ExclusiveImageSurface::new(width, height, new_type)?;
     map_unpremultiplied_components_loop(surface, &mut output_surface, bounds, f);
@@ -77,7 +77,7 @@ fn map_unpremultiplied_components<F: Fn(u8) -> u8>(
 pub fn linearize_surface(
     surface: &SharedImageSurface,
     bounds: IRect,
-) -> Result<SharedImageSurface, cairo::Status> {
+) -> Result<SharedImageSurface, cairo::Error> {
     assert_eq!(surface.surface_type(), SurfaceType::SRgb);
 
     map_unpremultiplied_components(surface, bounds, linearize, SurfaceType::LinearRgb)
@@ -88,7 +88,7 @@ pub fn linearize_surface(
 pub fn unlinearize_surface(
     surface: &SharedImageSurface,
     bounds: IRect,
-) -> Result<SharedImageSurface, cairo::Status> {
+) -> Result<SharedImageSurface, cairo::Error> {
     assert_eq!(surface.surface_type(), SurfaceType::LinearRgb);
 
     map_unpremultiplied_components(surface, bounds, unlinearize, SurfaceType::SRgb)
diff --git a/src/util.rs b/src/util.rs
index e308359a..bd5e29bf 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -4,6 +4,8 @@ use std::borrow::Cow;
 use std::ffi::CStr;
 use std::str;
 
+use crate::error::RenderingError;
+
 /// Converts a `char *` which is known to be valid UTF-8 into a `&str`
 ///
 /// The usual `from_glib_none(s)` allocates an owned String.  The
@@ -53,3 +55,21 @@ macro_rules! enum_default {
         }
     };
 }
+
+/// Return an error if a Cairo context is in error.
+///
+/// https://github.com/gtk-rs/gtk-rs/issues/74 - with cairo-rs 0.9.0, the `Context` objet
+/// lost the ability to get its error status queried.  So we do it by hand with `cairo_sys`.
+pub fn check_cairo_context(cr: &cairo::Context) -> Result<(), RenderingError> {
+    unsafe {
+        let cr_raw = cr.to_raw_none();
+
+        let status = cairo_sys::cairo_status(cr_raw);
+        if status == cairo_sys::STATUS_SUCCESS {
+            Ok(())
+        } else {
+            let status: cairo::Error = status.into();
+            Err(RenderingError::from(status))
+        }
+    }
+}
diff --git a/tests/src/compare_surfaces.rs b/tests/src/compare_surfaces.rs
index 7a8c87f5..0f94fd4e 100644
--- a/tests/src/compare_surfaces.rs
+++ b/tests/src/compare_surfaces.rs
@@ -55,7 +55,7 @@ fn emphasize(p: &Pixel) -> Pixel {
 pub fn compare_surfaces(
     surf_a: &SharedImageSurface,
     surf_b: &SharedImageSurface,
-) -> Result<BufferDiff, cairo::Status> {
+) -> Result<BufferDiff, cairo::Error> {
     let a_width = surf_a.width();
     let a_height = surf_a.height();
 
diff --git a/tests/src/reference.rs b/tests/src/reference.rs
index 5237911e..2c1a02e1 100644
--- a/tests/src/reference.rs
+++ b/tests/src/reference.rs
@@ -104,7 +104,7 @@ fn extract_rectangle(
     y: i32,
     w: i32,
     h: i32,
-) -> Result<cairo::ImageSurface, cairo::Status> {
+) -> Result<cairo::ImageSurface, cairo::Error> {
     let dest = cairo::ImageSurface::create(cairo::Format::ARgb32, w, h)?;
     let cr = cairo::Context::new(&dest);
     cr.set_source_surface(&source, f64::from(-x), f64::from(-y));
diff --git a/tests/src/utils.rs b/tests/src/utils.rs
index 4795055f..fea62327 100644
--- a/tests/src/utils.rs
+++ b/tests/src/utils.rs
@@ -17,7 +17,7 @@ use librsvg::{
 
 pub fn load_svg(input: &'static [u8]) -> Result<SvgHandle, LoadingError> {
     let bytes = glib::Bytes::from_static(input);
-    let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
+    let stream = gio::MemoryInputStream::from_bytes(&bytes);
 
     Loader::new().read_stream(&stream, None::<&gio::File>, None::<&gio::Cancellable>)
 }


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