1
use cssparser::Color;
2

            
3
use crate::document::AcquiredNodes;
4
use crate::drawing_ctx::DrawingCtx;
5
use crate::element::ElementTrait;
6
use crate::node::{CascadedValues, Node};
7
use crate::paint_server::resolve_color;
8
use crate::rect::IRect;
9
use crate::rsvg_log;
10
use crate::session::Session;
11
use crate::xml::Attributes;
12

            
13
use super::bounds::BoundsBuilder;
14
use super::context::{FilterContext, FilterOutput};
15
use super::{
16
    FilterEffect, FilterError, FilterResolveError, Primitive, PrimitiveParams, ResolvedPrimitive,
17
};
18

            
19
/// The `feFlood` filter primitive.
20
62
#[derive(Default)]
21
pub struct FeFlood {
22
31
    base: Primitive,
23
}
24

            
25
/// Resolved `feFlood` primitive for rendering.
26
pub struct Flood {
27
    pub color: Color,
28
}
29

            
30
impl ElementTrait for FeFlood {
31
31
    fn set_attributes(&mut self, attrs: &Attributes, session: &Session) {
32
31
        self.base.parse_no_inputs(attrs, session);
33
31
    }
34
}
35

            
36
impl Flood {
37
34
    pub fn render(
38
        &self,
39
        bounds_builder: BoundsBuilder,
40
        ctx: &FilterContext,
41
        _acquired_nodes: &mut AcquiredNodes<'_>,
42
        draw_ctx: &mut DrawingCtx,
43
    ) -> Result<FilterOutput, FilterError> {
44
34
        let bounds: IRect = bounds_builder.compute(ctx).clipped.into();
45
34
        rsvg_log!(draw_ctx.session(), "(feFlood bounds={:?}", bounds);
46

            
47
34
        let surface = ctx.source_graphic().flood(bounds, self.color)?;
48

            
49
34
        Ok(FilterOutput { surface, bounds })
50
34
    }
51
}
52

            
53
impl FilterEffect for FeFlood {
54
32
    fn resolve(
55
        &self,
56
        _acquired_nodes: &mut AcquiredNodes<'_>,
57
        node: &Node,
58
    ) -> Result<Vec<ResolvedPrimitive>, FilterResolveError> {
59
32
        let cascaded = CascadedValues::new_from_node(node);
60
32
        let values = cascaded.get();
61

            
62
64
        Ok(vec![ResolvedPrimitive {
63
32
            primitive: self.base.clone(),
64
32
            params: PrimitiveParams::Flood(Flood {
65
32
                color: resolve_color(
66
32
                    &values.flood_color().0,
67
32
                    values.flood_opacity().0,
68
32
                    &values.color().0,
69
                ),
70
            }),
71
        }])
72
32
    }
73
}