1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 16:35:06 +00:00
serenity/Userland/Libraries/LibWeb/SVG/SVGPolygonElement.cpp
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

56 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/AttributeParser.h>
#include <LibWeb/SVG/SVGPolygonElement.h>
namespace Web::SVG {
SVGPolygonElement::SVGPolygonElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: SVGGeometryElement(document, qualified_name)
{
set_prototype(&Bindings::cached_web_prototype(realm(), "SVGPolygonElement"));
}
void SVGPolygonElement::parse_attribute(FlyString const& name, DeprecatedString const& value)
{
SVGGeometryElement::parse_attribute(name, value);
if (name == SVG::AttributeNames::points) {
m_points = AttributeParser::parse_points(value);
m_path.clear();
}
}
Gfx::Path& SVGPolygonElement::get_path()
{
if (m_path.has_value())
return m_path.value();
Gfx::Path path;
if (m_points.is_empty()) {
m_path = move(path);
return m_path.value();
}
// 1. perform an absolute moveto operation to the first coordinate pair in the list of points
path.move_to(m_points.first());
// 2. for each subsequent coordinate pair, perform an absolute lineto operation to that coordinate pair.
for (size_t point_index = 1; point_index < m_points.size(); ++point_index)
path.line_to(m_points[point_index]);
// 3. perform a closepath command
path.close();
m_path = move(path);
return m_path.value();
}
}