1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

LibWeb: Add SVG <polyline> element and test case :^)

This commit is contained in:
Sam Atkins 2022-02-11 17:28:24 +00:00 committed by Andreas Kling
parent 17912330c4
commit 116a1f485c
13 changed files with 141 additions and 1 deletions

View file

@ -64,6 +64,32 @@ Optional<float> AttributeParser::parse_positive_length(StringView input)
return result;
}
Vector<Gfx::FloatPoint> AttributeParser::parse_points(StringView input)
{
AttributeParser parser { input };
parser.parse_whitespace();
// FIXME: "If an odd number of coordinates is provided, then the element is in error, with the same user agent behavior
// as occurs with an incorrectly specified path element. In such error cases the user agent will drop the last,
// odd coordinate and otherwise render the shape."
// The parser currently doesn't notice that there is a missing coordinate, so make it notice!
auto coordinate_pair_sequence = parser.parse_coordinate_pair_sequence();
parser.parse_whitespace();
if (!parser.done())
return {};
// FIXME: This is awkward. Can we return Gfx::FloatPoints from some of these parsing methods instead of Vector<float>?
Vector<Gfx::FloatPoint> points;
points.ensure_capacity(coordinate_pair_sequence.size());
for (auto const& pair : coordinate_pair_sequence)
points.empend(pair[0], pair[1]);
return points;
}
void AttributeParser::parse_drawto()
{
if (match('M') || match('m')) {