1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 03:47:34 +00:00

LibWeb: Remove SVGContext

The SVGContext is a leftover from when SVG properties were more ad-hoc.
All properties are now (for better or worse) treated as CSS properties
(or handled elsewhere). This makes the SVGContext's fill/stroke
inheritance handling unnecessary.
This commit is contained in:
MacDue 2023-07-01 21:24:04 +01:00 committed by Jelle Raaijmakers
parent 23a7ccf607
commit 7d26383426
11 changed files with 18 additions and 150 deletions

View file

@ -1,61 +0,0 @@
/*
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibGfx/Color.h>
#include <LibGfx/Rect.h>
#include <LibWeb/SVG/AttributeParser.h>
namespace Web {
class SVGContext {
public:
SVGContext(CSSPixelRect svg_element_bounds)
: m_svg_element_bounds(svg_element_bounds)
{
m_states.append(State());
}
SVG::FillRule fill_rule() const { return state().fill_rule; }
Gfx::Color fill_color() const { return state().fill_color; }
Gfx::Color stroke_color() const { return state().stroke_color; }
float stroke_width() const { return state().stroke_width; }
float fill_opacity() const { return state().fill_opacity; }
float stroke_opacity() const { return state().stroke_opacity; }
void set_fill_rule(SVG::FillRule fill_rule) { state().fill_rule = fill_rule; }
void set_fill_color(Gfx::Color color) { state().fill_color = color; }
void set_stroke_color(Gfx::Color color) { state().stroke_color = color; }
void set_stroke_width(float width) { state().stroke_width = width; }
void set_fill_opacity(float opacity) { state().fill_opacity = opacity; }
void set_stroke_opacity(float opacity) { state().stroke_opacity = opacity; }
CSSPixelPoint svg_element_position() const { return m_svg_element_bounds.top_left(); }
CSSPixelSize svg_element_size() const { return m_svg_element_bounds.size(); }
void save() { m_states.append(m_states.last()); }
void restore() { m_states.take_last(); }
private:
struct State {
SVG::FillRule fill_rule { SVG::FillRule::Nonzero };
Gfx::Color fill_color { Gfx::Color::Transparent };
Gfx::Color stroke_color { Gfx::Color::Transparent };
float stroke_width { 1.0f };
float fill_opacity { 1.0f };
float stroke_opacity { 1.0f };
};
State const& state() const { return m_states.last(); }
State& state() { return m_states.last(); }
CSSPixelRect m_svg_element_bounds;
Vector<State> m_states;
};
}

View file

@ -108,7 +108,6 @@ Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> trans
Gfx::AffineTransform SVGGraphicsElement::get_transform() const
{
// FIXME: It would be nice to do this using the SVGContext, however, then layout/hit testing knows nothing about the transform.
Gfx::AffineTransform transform = m_transform;
for (auto* svg_ancestor = shadow_including_first_ancestor_of_type<SVGGraphicsElement>(); svg_ancestor; svg_ancestor = svg_ancestor->shadow_including_first_ancestor_of_type<SVGGraphicsElement>()) {
transform = Gfx::AffineTransform { svg_ancestor->m_transform }.multiply(transform);