[librsvg: 3/8] c_api.rs: Check the incoming cairo context here to emit a g_warning()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/8] c_api.rs: Check the incoming cairo context here to emit a g_warning()
- Date: Mon, 26 Aug 2019 12:52:47 +0000 (UTC)
commit c2811e084be3adcd606e8ebcf161d1f6bae7f1eb
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Aug 26 12:15:42 2019 +0300
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.
rsvg_internals/src/c_api.rs | 23 +++++++++++++++++++++++
rsvg_internals/src/handle.rs | 6 ------
2 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/rsvg_internals/src/c_api.rs b/rsvg_internals/src/c_api.rs
index f8d2477c..5d1c3f7a 100644
--- a/rsvg_internals/src/c_api.rs
+++ b/rsvg_internals/src/c_api.rs
@@ -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::*;
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 270b266e..73b227db 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -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))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]