mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:28:11 +00:00
LibWeb: Add for CSS fill/stroke/stroke-color
properties for SVG
In the spec, `fill` and `stroke` are supposed to be a shorthands for various properties. But since the spec is still a working draft, and neither Firefox or Chrome support the `fill-color` or `stroke-color` properties, we'll stick with `fill` and `stroke` as simple colors for now. Also, note that SVG expects things in "user units", and we are assuming that 1px = 1 user unit for now.
This commit is contained in:
parent
2c8c56684b
commit
3964b81d2b
5 changed files with 75 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -13,7 +14,7 @@ SVGGraphicsElement::SVGGraphicsElement(DOM::Document& document, QualifiedName qu
|
|||
{
|
||||
}
|
||||
|
||||
void SVGGraphicsElement::parse_attribute(const FlyString& name, const String& value)
|
||||
void SVGGraphicsElement::parse_attribute(FlyString const& name, String const& value)
|
||||
{
|
||||
SVGElement::parse_attribute(name, value);
|
||||
|
||||
|
@ -28,4 +29,39 @@ void SVGGraphicsElement::parse_attribute(const FlyString& name, const String& va
|
|||
}
|
||||
}
|
||||
|
||||
Optional<Gfx::Color> SVGGraphicsElement::fill_color() const
|
||||
{
|
||||
if (m_fill_color.has_value())
|
||||
return m_fill_color;
|
||||
if (!layout_node())
|
||||
return {};
|
||||
// FIXME: In the working-draft spec, `fill` is intended to be a shorthand, with `fill-color`
|
||||
// being what we actually want to use. But that's not final or widely supported yet.
|
||||
return layout_node()->computed_values().fill();
|
||||
}
|
||||
|
||||
Optional<Gfx::Color> SVGGraphicsElement::stroke_color() const
|
||||
{
|
||||
if (m_stroke_color.has_value())
|
||||
return m_stroke_color;
|
||||
if (!layout_node())
|
||||
return {};
|
||||
// FIXME: In the working-draft spec, `stroke` is intended to be a shorthand, with `stroke-color`
|
||||
// being what we actually want to use. But that's not final or widely supported yet.
|
||||
return layout_node()->computed_values().stroke();
|
||||
}
|
||||
|
||||
Optional<float> SVGGraphicsElement::stroke_width() const
|
||||
{
|
||||
if (m_stroke_width.has_value())
|
||||
return m_stroke_width;
|
||||
if (!layout_node())
|
||||
return {};
|
||||
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
|
||||
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
|
||||
if (auto width = layout_node()->computed_values().stroke_width(); width.has_value())
|
||||
return width->to_px(*layout_node());
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue