c_api.rs: Check the incoming cairo context here to emit a g_warning()

We want to emit a g_warning only from the C API code, not from the
internals Rust code.

The internals Rust code needs to check the Cairo context as well, in
case it is called form the librsvg_crate, but not emit a g_warning in
that case.
parent c8540b91
......@@ -685,6 +685,8 @@ impl CHandle {
cr: &cairo::Context,
id: Option<&str>,
) -> Result<(), RenderingError> {
check_cairo_context(cr)?;
let handle = self.get_handle_ref()?;
let size_callback = self.size_callback.borrow();
handle.render_cairo_sub(
......@@ -707,6 +709,8 @@ impl CHandle {
cr: &cairo::Context,
viewport: &cairo::Rectangle,
) -> Result<(), RenderingError> {
check_cairo_context(cr)?;
let handle = self.get_handle_ref()?;
handle.render_document(cr, viewport, self.dpi.get(), self.is_testing.get())
}
......@@ -726,6 +730,8 @@ impl CHandle {
id: Option<&str>,
viewport: &cairo::Rectangle,
) -> Result<(), RenderingError> {
check_cairo_context(cr)?;
let handle = self.get_handle_ref()?;
handle.render_layer(cr, id, viewport, self.dpi.get(), self.is_testing.get())
}
......@@ -744,6 +750,8 @@ impl CHandle {
id: Option<&str>,
element_viewport: &cairo::Rectangle,
) -> Result<(), RenderingError> {
check_cairo_context(cr)?;
let handle = self.get_handle_ref()?;
handle.render_element(cr, id, element_viewport, self.dpi.get(), self.is_testing.get())
}
......@@ -1450,6 +1458,21 @@ impl PathOrUrl {
}
}
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))
}
}
#[cfg(test)]
mod tests {
use super::*;
......
......@@ -511,12 +511,6 @@ fn check_cairo_context(cr: &cairo::Context) -> Result<(), RenderingError> {
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))
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment