diff options
author | MacDue <macdue@dueutil.tech> | 2023-05-19 20:35:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-20 08:52:19 +0200 |
commit | 00cda96e2db3d10c300d7fde5a6bc1fa1e2fabc6 (patch) | |
tree | 3bdfc2583d5eb414d0f4596233256be5bd22ca7a /Userland/Libraries/LibWeb/Painting | |
parent | 120e5b6b6f95328877d8bfbdda5b1a2f429df47f (diff) | |
download | serenity-00cda96e2db3d10c300d7fde5a6bc1fa1e2fabc6.zip |
LibWeb: Implement SVG opacity properties
This implements the stop-opacity, fill-opacity, and stroke-opacity
properties (in CSS). This replaces the existing more ad-hoc
fill-opacity attribute handling.
Diffstat (limited to 'Userland/Libraries/LibWeb/Painting')
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp | 16 |
2 files changed, 15 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp index fa1fefc59c..09ac1270a5 100644 --- a/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp @@ -101,19 +101,22 @@ void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const .transform = paint_transform }; + // FIXME: Apply fill opacity to paint styles? + auto fill_opacity = geometry_element.fill_opacity().value_or(svg_context.fill_opacity()); if (auto paint_style = geometry_element.fill_paint_style(paint_context); paint_style.has_value()) { painter.fill_path( closed_path(), *paint_style, Gfx::Painter::WindingRule::EvenOdd); - } else if (auto fill_color = geometry_element.fill_color().value_or(svg_context.fill_color()); fill_color.alpha() > 0) { + } else if (auto fill_color = geometry_element.fill_color().value_or(svg_context.fill_color()).with_opacity(fill_opacity); fill_color.alpha() > 0) { painter.fill_path( closed_path(), fill_color, Gfx::Painter::WindingRule::EvenOdd); } - if (auto stroke_color = geometry_element.stroke_color().value_or(svg_context.stroke_color()); stroke_color.alpha() > 0) { + auto stroke_opacity = geometry_element.stroke_opacity().value_or(svg_context.stroke_opacity()); + if (auto stroke_color = geometry_element.stroke_color().value_or(svg_context.stroke_color()).with_opacity(stroke_opacity); stroke_color.alpha() > 0) { painter.stroke_path( path, stroke_color, diff --git a/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp index cceaeb3cab..43a790e6cc 100644 --- a/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp @@ -32,12 +32,16 @@ void SVGGraphicsPaintable::before_children_paint(PaintContext& context, PaintPha auto& graphics_element = layout_box().dom_node(); - if (graphics_element.fill_color().has_value()) - context.svg_context().set_fill_color(graphics_element.fill_color().value()); - if (graphics_element.stroke_color().has_value()) - context.svg_context().set_stroke_color(graphics_element.stroke_color().value()); - if (graphics_element.stroke_width().has_value()) - context.svg_context().set_stroke_width(graphics_element.stroke_width().value()); + if (auto fill_color = graphics_element.fill_color(); fill_color.has_value()) + context.svg_context().set_fill_color(*fill_color); + if (auto stroke_color = graphics_element.stroke_color(); stroke_color.has_value()) + context.svg_context().set_stroke_color(*stroke_color); + if (auto stroke_width = graphics_element.stroke_width(); stroke_width.has_value()) + context.svg_context().set_stroke_width(*stroke_width); + if (auto fill_opacity = graphics_element.fill_opacity(); fill_opacity.has_value()) + context.svg_context().set_fill_opacity(*fill_opacity); + if (auto stroke_opacity = graphics_element.stroke_opacity(); stroke_opacity.has_value()) + context.svg_context().set_stroke_opacity(*stroke_opacity); } } |