[librsvg: 39/90] PathBuilder::to_cairo() - Check the cr.status after completing the path
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 39/90] PathBuilder::to_cairo() - Check the cr.status after completing the path
- Date: Tue, 26 Mar 2019 19:15:20 +0000 (UTC)
commit 3ae3bb1cb3dbc19038017d20e17562692238ee2e
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Mar 14 13:42:44 2019 -0600
PathBuilder::to_cairo() - Check the cr.status after completing the path
Any of the individual path commands may cause the cr to enter an
error state, for example, if they come with coordinates outside of Cairo's supported range.
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.
(In the worst case, Cairo will throw out-of-memory with a super-long
path, but this is the correct place to catch that.)
rsvg_internals/src/path_builder.rs | 18 +++++++++++++++++-
rsvg_internals/src/shapes.rs | 2 +-
2 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/path_builder.rs b/rsvg_internals/src/path_builder.rs
index 077f3e8f..db133bfc 100644
--- a/rsvg_internals/src/path_builder.rs
+++ b/rsvg_internals/src/path_builder.rs
@@ -355,10 +355,26 @@ impl PathBuilder {
&self.path_commands
}
- pub fn to_cairo(&self, cr: &cairo::Context) {
+ pub fn to_cairo(&self, cr: &cairo::Context) -> Result<(), cairo::Status> {
for s in &self.path_commands {
s.to_cairo(cr);
}
+
+ // We check the cr's status right after feeding it a new path for a few reasons:
+ //
+ // * Any of the individual path commands may cause the cr to enter an error state,
+ // for example, if they come with coordinates outside of Cairo's supported range.
+ //
+ // * 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)
+ }
}
}
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index a9ca0a8d..f7a9fd1d 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -27,7 +27,7 @@ fn render_path_builder(
draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
let cr = dc.get_cairo_context();
- builder.to_cairo(&cr);
+ builder.to_cairo(&cr)?;
if clipping {
cr.set_fill_rule(cairo::FillRule::from(values.clip_rule));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]