[librsvg: 14/31] PaintServer.resolve - recover from MaxReferencesExceeded to the fallback color




commit b9fbfe0d6c99e01b631585b77c2b71a9e4b98bbf
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jun 2 17:54:05 2021 -0500

    PaintServer.resolve - recover from MaxReferencesExceeded to the fallback color
    
    The limit will be hit again in the drawing code and properly terminate
    the rendering phase early.
    
    This commit also ajusts the error tests so that they allow a "no
    error" condition, which hopefully means that the process finished
    within a reasonable amount of time as well.

 src/paint_server.rs | 28 +++++++++++++---------------
 tests/src/errors.rs | 27 +++++++++++++--------------
 2 files changed, 26 insertions(+), 29 deletions(-)
---
diff --git a/src/paint_server.rs b/src/paint_server.rs
index 09c125a2..286ff450 100644
--- a/src/paint_server.rs
+++ b/src/paint_server.rs
@@ -6,9 +6,7 @@ use crate::bbox::BoundingBox;
 use crate::document::{AcquiredNodes, NodeId};
 use crate::drawing_ctx::DrawingCtx;
 use crate::element::Element;
-use crate::error::{
-    AcquireError, ImplementationLimit, NodeIdError, ParseError, RenderingError, ValueErrorKind,
-};
+use crate::error::{AcquireError, NodeIdError, ParseError, RenderingError, ValueErrorKind};
 use crate::gradient::{ResolvedGradient, UserSpaceGradient};
 use crate::node::NodeBorrow;
 use crate::parsers::Parse;
@@ -150,18 +148,18 @@ impl PaintServer {
                     }
                 })
                 .or_else(|err| match (err, alternate) {
-                    (AcquireError::MaxReferencesExceeded, _) => {
-                        rsvg_log!("exceeded maximum number of referenced objects");
-                        Err(RenderingError::LimitExceeded(
-                            ImplementationLimit::TooManyReferencedElements,
-                        ))
-                    }
-
-                    // The following two cases catch AcquireError::CircularReference, which for
-                    // paint servers may mean that there is a pattern or gradient with a reference
-                    // cycle in its "href" attribute.  This is an invalid paint server, and per
-                    // https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint we should try to
-                    // fall back to the alternate color.
+                    // The following cases catch AcquireError::CircularReference and
+                    // AcquireError::MaxReferencesExceeded.
+                    //
+                    // Circular references mean that there is a pattern or gradient with a
+                    // reference cycle in its "href" attribute.  This is an invalid paint
+                    // server, and per
+                    // https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint we should
+                    // try to fall back to the alternate color.
+                    //
+                    // 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)) => {
                         rsvg_log!(
                             "could not resolve paint server \"{}\", using alternate color",
diff --git a/tests/src/errors.rs b/tests/src/errors.rs
index b315fe2b..93b4f9dc 100644
--- a/tests/src/errors.rs
+++ b/tests/src/errors.rs
@@ -37,20 +37,19 @@ fn rendering_instancing_limit(name: &str) {
     // Note that at least 515-patttern-billion-laughs.svg requires a viewport of this size
     // or bigger; a smaller one causes the recursive patterns to get so small that they
     // are culled out, and so the document doesn't reach the instancing limit.
-    assert!(matches!(
-        CairoRenderer::new(&handle).render_document(
-            &cr,
-            &cairo::Rectangle {
-                x: 0.0,
-                y: 0.0,
-                width: 500.0,
-                height: 500.0,
-            },
-        ),
-        Err(RenderingError::LimitExceeded(
-            ImplementationLimit::TooManyReferencedElements
-        ))
-    ));
+    match CairoRenderer::new(&handle).render_document(
+        &cr,
+        &cairo::Rectangle {
+            x: 0.0,
+            y: 0.0,
+            width: 500.0,
+            height: 500.0,
+        },
+    ) {
+        Ok(_) => (),
+        Err(RenderingError::LimitExceeded(ImplementationLimit::TooManyReferencedElements)) => (),
+        _ => panic!("unexpected error code"),
+    }
 }
 
 #[ignore]


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