[librsvg/attribute-parsers-737: 20/26] FilterContext::get_raw_input() - If a filter input is not found, fall back correctly per the spec




commit 541a9b4451e9b5c5ade07566a0cae87e8e165a55
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Oct 20 18:29:45 2022 -0500

    FilterContext::get_raw_input() - If a filter input is not found, fall back correctly per the spec
    
    E.g. <feSomePrimitive in="nonexistent">
    
    We used to return FilterError::InvalidInput, which would invalidate
    the entire filter chain.  Per the spec, when a named "in" or "in2" is
    not found, we need to act as if that input were unspecified - i.e. the
    last result in the filter chain, or SourceGraphic for the first
    primitive in the chain.
    
    This fixes the mouse's hat in https://gitlab.gnome.org/GNOME/librsvg/-/issues/912

 src/filters/context.rs | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/src/filters/context.rs b/src/filters/context.rs
index 17a746f80..96babf78e 100644
--- a/src/filters/context.rs
+++ b/src/filters/context.rs
@@ -333,12 +333,25 @@ impl FilterContext {
                 .stroke_paint_image(acquired_nodes, draw_ctx)
                 .map(FilterInput::StandardInput),
 
-            Input::FilterOutput(ref name) => self
-                .previous_results
-                .get(name)
-                .cloned()
-                .map(FilterInput::PrimitiveOutput)
-                .ok_or(FilterError::InvalidInput),
+            Input::FilterOutput(ref name) => {
+                let input = match self.previous_results.get(name).cloned() {
+                    Some(filter_output) => {
+                        // Happy path: we found a previous primitive's named output, so pass it on.
+                        FilterInput::PrimitiveOutput(filter_output)
+                    }
+
+                    None => {
+                        // Fallback path: we didn't find a primitive's output by the
+                        // specified name, so fall back to using an unspecified output.
+                        // Per the spec, "References to non-existent results will be
+                        // treated as if no result was specified." -
+                        // https://drafts.fxtf.org/filter-effects/#element-attrdef-filter-primitive-in
+                        self.get_unspecified_input()
+                    }
+                };
+
+                Ok(input)
+            }
         }
     }
 


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