[librsvg: 8/11] Allow DrawingCtx.set_gradient to report failure
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 8/11] Allow DrawingCtx.set_gradient to report failure
- Date: Tue, 1 Dec 2020 18:24:44 +0000 (UTC)
commit 1ed437bfd2855a70408db77ff8b5aaa4a9aec8b4
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 1 10:59:53 2020 -0600
Allow DrawingCtx.set_gradient to report failure
Right now it seems like it can't fail, but in reality Cairo could OOM
or something and leave the cr in an error state. We'll catch this in
the future.
Also, this makes set_gradient similar to set_pattern.
src/drawing_ctx.rs | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 31195957..81a9f9e1 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -933,7 +933,11 @@ impl DrawingCtx {
Ok(child_surface)
}
- fn set_gradient(self: &mut DrawingCtx, gradient: &UserSpaceGradient, opacity: UnitInterval) {
+ fn set_gradient(
+ self: &mut DrawingCtx,
+ gradient: &UserSpaceGradient,
+ opacity: UnitInterval,
+ ) -> Result<bool, RenderingError> {
let g = match gradient.variant {
GradientVariant::Linear { x1, y1, x2, y2 } => {
cairo::Gradient::clone(&cairo::LinearGradient::new(x1, y1, x2, y2))
@@ -968,6 +972,8 @@ impl DrawingCtx {
let cr = self.cr.clone();
cr.set_source(&g);
+
+ Ok(true)
}
fn set_pattern(
@@ -1141,8 +1147,15 @@ impl DrawingCtx {
match paint_source {
PaintSource::Gradient(g, c) => {
+ let had_gradient;
+
if let Some(gradient) = g.to_user_space(bbox, self, values) {
- self.set_gradient(&gradient, opacity);
+ had_gradient = self.set_gradient(&gradient, opacity)?;
+ } else {
+ had_gradient = false;
+ }
+
+ if had_gradient {
Ok(true)
} else if let Some(c) = c {
self.set_color(c, opacity, current_color)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]