[librsvg: 15/31] PaintServer.resolve() is infallible now




commit b52c695df835518daba7f1c40900811f8defa961
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jun 2 18:16:05 2021 -0500

    PaintServer.resolve() is infallible now

 src/drawing_ctx.rs  | 12 ++++++------
 src/paint_server.rs | 28 +++++++++++-----------------
 2 files changed, 17 insertions(+), 23 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 73b87887..c24f0f80 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -735,7 +735,7 @@ impl DrawingCtx {
                         values
                             .stroke()
                             .0
-                            .resolve(acquired_nodes, values.stroke_opacity().0, current_color)?
+                            .resolve(acquired_nodes, values.stroke_opacity().0, current_color)
                             .to_user_space(&bbox, &temporary_draw_ctx, values),
                     );
 
@@ -743,7 +743,7 @@ impl DrawingCtx {
                         values
                             .fill()
                             .0
-                            .resolve(acquired_nodes, values.fill_opacity().0, current_color)?
+                            .resolve(acquired_nodes, values.fill_opacity().0, current_color)
                             .to_user_space(&bbox, &temporary_draw_ctx, values),
                     );
 
@@ -1152,7 +1152,7 @@ impl DrawingCtx {
         let paint_source = values
             .stroke()
             .0
-            .resolve(acquired_nodes, values.stroke_opacity().0, values.color().0)?
+            .resolve(acquired_nodes, values.stroke_opacity().0, values.color().0)
             .to_user_space(bbox, self, values);
 
         self.set_paint_source(&paint_source, acquired_nodes)
@@ -1175,7 +1175,7 @@ impl DrawingCtx {
         let paint_source = values
             .fill()
             .0
-            .resolve(acquired_nodes, values.fill_opacity().0, values.color().0)?
+            .resolve(acquired_nodes, values.fill_opacity().0, values.color().0)
             .to_user_space(bbox, self, values);
 
         self.set_paint_source(&paint_source, acquired_nodes)
@@ -1401,7 +1401,7 @@ impl DrawingCtx {
         let paint_source = values
             .fill()
             .0
-            .resolve(acquired_nodes, values.fill_opacity().0, values.color().0)?
+            .resolve(acquired_nodes, values.fill_opacity().0, values.color().0)
             .to_user_space(&bbox, saved_cr.draw_ctx, values);
 
         saved_cr
@@ -1421,7 +1421,7 @@ impl DrawingCtx {
         let paint_source = values
             .stroke()
             .0
-            .resolve(acquired_nodes, values.stroke_opacity().0, values.color().0)?
+            .resolve(acquired_nodes, values.stroke_opacity().0, values.color().0)
             .to_user_space(&bbox, saved_cr.draw_ctx, values);
 
         saved_cr
diff --git a/src/paint_server.rs b/src/paint_server.rs
index 286ff450..8ac01795 100644
--- a/src/paint_server.rs
+++ b/src/paint_server.rs
@@ -6,7 +6,7 @@ use crate::bbox::BoundingBox;
 use crate::document::{AcquiredNodes, NodeId};
 use crate::drawing_ctx::DrawingCtx;
 use crate::element::Element;
-use crate::error::{AcquireError, NodeIdError, ParseError, RenderingError, ValueErrorKind};
+use crate::error::{AcquireError, NodeIdError, ParseError, ValueErrorKind};
 use crate::gradient::{ResolvedGradient, UserSpaceGradient};
 use crate::node::NodeBorrow;
 use crate::parsers::Parse;
@@ -108,7 +108,7 @@ impl PaintServer {
         acquired_nodes: &mut AcquiredNodes<'_>,
         opacity: UnitInterval,
         current_color: cssparser::RGBA,
-    ) -> Result<PaintSource, RenderingError> {
+    ) -> PaintSource {
         match self {
             PaintServer::Iri {
                 ref iri,
@@ -147,7 +147,7 @@ impl PaintServer {
                         _ => Err(AcquireError::InvalidLinkType(iri.as_ref().clone())),
                     }
                 })
-                .or_else(|err| match (err, alternate) {
+                .unwrap_or_else(|_| match alternate {
                     // The following cases catch AcquireError::CircularReference and
                     // AcquireError::MaxReferencesExceeded.
                     //
@@ -160,36 +160,30 @@ impl PaintServer {
                     // Exceeding the maximum number of references will get caught again
                     // later in the drawing code, so it should be fine to translate this
                     // condition to that for an invalid paint server.
-                    (_, Some(color)) => {
+                    Some(color) => {
                         rsvg_log!(
                             "could not resolve paint server \"{}\", using alternate color",
                             iri
                         );
 
-                        Ok(PaintSource::SolidColor(resolve_color(
-                            color,
-                            opacity,
-                            current_color,
-                        )))
+                        PaintSource::SolidColor(resolve_color(color, opacity, current_color))
                     }
 
-                    (_, _) => {
+                    None => {
                         rsvg_log!(
                             "could not resolve paint server \"{}\", no alternate color specified",
                             iri
                         );
 
-                        Ok(PaintSource::None)
+                        PaintSource::None
                     }
                 }),
 
-            PaintServer::SolidColor(color) => Ok(PaintSource::SolidColor(resolve_color(
-                color,
-                opacity,
-                current_color,
-            ))),
+            PaintServer::SolidColor(color) => {
+                PaintSource::SolidColor(resolve_color(color, opacity, current_color))
+            }
 
-            PaintServer::None => Ok(PaintSource::None),
+            PaintServer::None => PaintSource::None,
         }
     }
 }


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