Previously we would often return a `Vector` just for the caller to
iterate over it a single time and disregard it. We instead now skip the
`Vector` allocation and second iteration by executing a callback as we
parse each value in the sequence.
We ended up converting this to a `Gfx::FloatPoint` in all but one place
any way so this just skips some extra handling and `Vector` allocations.
Also makes `parse_coordinate_pair_{double|triplet}` return `Vectors`
store data inline to avoid a heap alloc.
Previously we had a single `PathInstruction` struct which stored it's
data in a `Vector<float>`. We now define `PathInstruction` as a
`Variant<>` of structs storing data inline (note that the remaining
`Vector` properties will be replaced with `Gfx::FloatPoint` in a future
commit) - this avoids a `Vector` allocation and avoids magic indices
when accessing data.
AttributeParser::parse_coordinate_sequence() appended the result of
parse_coordinate() to the sequence even when parsing had failed on a
non-first iteration: its error branch was missing the `break` that the
sibling parse_coordinate_pair_sequence() has. Calling release_value() on
the errored ErrorOr then trips a VERIFY and aborts the process.
A path such as `<path d="H1,,">` reaches this: after the first
coordinate the trailing comma leaves match_comma_whitespace() true, the
following parse_coordinate() fails, and the loop falls through to
release the error.
Break out of the loop on a non-first error, matching the sibling
function.
From the SVG spec
The value of the ‘viewBox’ attribute is a list of four numbers <min-x>,
<min-y>, <width> and <height>, separated by whitespace and/or a comma...
Currently try_parse_view_box will fail to parse the attribute if the
values are separated by commas.
This change replaces try_parse_view_box with a more correct
implementation. It will reside in the AttributeParser.cpp. This new
implementation correctly handles comma-separated viewBox values, and is
also more robust against invalid inputs.
Additionally, it adds a new test case to ensure viewBox values with
various syntax are parsed correctly and invalid values are rejected.
More things need this than just the `<path>` element, so let's avoid
having to include `SVGPathElement.h` in places that don't need it.
Minor changes at the same time:
- Wrap it in a Path class
- Specify underlying type for PathInstructionType
- Make a couple of free functions into methods
- Give PathInstruction an operator==
No functionality changes.
Our floating point number parser was based on the fast_float library:
https://github.com/fastfloat/fast_float
However, our implementation only supports 8-bit characters. To support
UTF-16, we will need to be able to convert char16_t-based strings to
numbers as well. This works out-of-the-box with fast_float.
We can also use fast_float for integer parsing.