1
1
/*
2
2
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
3
- * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
3
+ * Copyright (c) 2021-2022 , Sam Atkins <atkinssj@serenityos.org>
4
4
*
5
5
* SPDX-License-Identifier: BSD-2-Clause
6
6
*/
7
7
8
+ #include < LibWeb/CSS/Parser/Parser.h>
8
9
#include < LibWeb/SVG/SVGGraphicsElement.h>
9
10
10
11
namespace Web ::SVG {
@@ -14,25 +15,27 @@ SVGGraphicsElement::SVGGraphicsElement(DOM::Document& document, QualifiedName qu
14
15
{
15
16
}
16
17
17
- void SVGGraphicsElement::parse_attribute (FlyString const & name, String const & value)
18
+ void SVGGraphicsElement::apply_presentational_hints (CSS::StyleProperties& style) const
18
19
{
19
- SVGElement::parse_attribute (name, value);
20
-
21
- if (name == " fill" ) {
22
- m_fill_color = Gfx::Color::from_string (value).value_or (Color::Transparent);
23
- } else if (name == " stroke" ) {
24
- m_stroke_color = Gfx::Color::from_string (value).value_or (Color::Transparent);
25
- } else if (name == " stroke-width" ) {
26
- auto result = value.to_int ();
27
- if (result.has_value ())
28
- m_stroke_width = result.value ();
29
- }
20
+ CSS::ParsingContext parsing_context { document () };
21
+ for_each_attribute ([&](auto & name, auto & value) {
22
+ if (name.equals_ignoring_case (" fill" )) {
23
+ // FIXME: The `fill` attribute and CSS `fill` property are not the same! But our support is limited enough that they are equivalent for now.
24
+ if (auto fill_value = parse_css_value (parsing_context, value, CSS::PropertyID::Fill))
25
+ style.set_property (CSS::PropertyID::Fill, fill_value.release_nonnull ());
26
+ } else if (name.equals_ignoring_case (" stroke" )) {
27
+ // FIXME: The `stroke` attribute and CSS `stroke` property are not the same! But our support is limited enough that they are equivalent for now.
28
+ if (auto stroke_value = parse_css_value (parsing_context, value, CSS::PropertyID::Stroke))
29
+ style.set_property (CSS::PropertyID::Stroke, stroke_value.release_nonnull ());
30
+ } else if (name.equals_ignoring_case (" stroke-width" )) {
31
+ if (auto stroke_width_value = parse_css_value (parsing_context, value, CSS::PropertyID::StrokeWidth))
32
+ style.set_property (CSS::PropertyID::StrokeWidth, stroke_width_value.release_nonnull ());
33
+ }
34
+ });
30
35
}
31
36
32
37
Optional<Gfx::Color> SVGGraphicsElement::fill_color () const
33
38
{
34
- if (m_fill_color.has_value ())
35
- return m_fill_color;
36
39
if (!layout_node ())
37
40
return {};
38
41
// FIXME: In the working-draft spec, `fill` is intended to be a shorthand, with `fill-color`
@@ -42,8 +45,6 @@ Optional<Gfx::Color> SVGGraphicsElement::fill_color() const
42
45
43
46
Optional<Gfx::Color> SVGGraphicsElement::stroke_color () const
44
47
{
45
- if (m_stroke_color.has_value ())
46
- return m_stroke_color;
47
48
if (!layout_node ())
48
49
return {};
49
50
// FIXME: In the working-draft spec, `stroke` is intended to be a shorthand, with `stroke-color`
@@ -53,8 +54,6 @@ Optional<Gfx::Color> SVGGraphicsElement::stroke_color() const
53
54
54
55
Optional<float > SVGGraphicsElement::stroke_width () const
55
56
{
56
- if (m_stroke_width.has_value ())
57
- return m_stroke_width;
58
57
if (!layout_node ())
59
58
return {};
60
59
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
0 commit comments