Commit graph

13 commits

Author SHA1 Message Date
Callum Law
3c4076597e LibWeb: Avoid Vector allocation in parse_coordinate{_pair_}_sequence
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.
2026-06-08 12:39:39 +01:00
Callum Law
5fbb8d82e7 LibWeb: Move SVG::parse_elliptical_arc_argument inline
`SVG::parse_elliptical_arc` was the only user and moving it inline
allows us to avoid a `Vector` allocation.
2026-06-08 12:39:39 +01:00
Callum Law
b33b9a6747 LibWeb: Parse SVG coordinate pair as Gfx::FloatPoint
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.
2026-06-08 12:39:39 +01:00
Callum Law
1026991820 LibWeb: Specialize SVG::PathInstruction structs
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.
2026-06-08 12:39:39 +01:00
Callum Law
743922b868 LibWeb: Avoid copying instructions in AttributeParser::parse_path_data
We throw away the parser immediately afterwards so we can just `move()`
instead of copying
2026-06-08 12:39:39 +01:00
François Guerraz
c984ce2429 LibWeb/SVG: Fix crash parsing a coordinate sequence that ends mid-token
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.
2026-06-04 13:36:16 +01:00
Luke Wilde
a89b02e5c3 LibWeb/SVG: Implement SVGAnimatedInteger
This is basically the same as SVGAnimatedNumber, but stores an i32
instead.
2026-02-11 09:39:39 +01:00
Jelle Raaijmakers
832e953c67 LibWeb: Use is_ascii_digit() in SVG attribute parsing 2025-11-20 23:15:24 +01:00
Jelle Raaijmakers
db321cb74f LibWeb: Add SVGComponentTransferFunctionElement
This will be the base for <feFuncR>, <feFuncG>, <feFuncB> and <feFuncA>.
2025-11-09 01:22:48 +01:00
Erik Kurzinger
21ff66c6cb LibWeb/SVG: Parse comma-separated SVG viewBox
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.
2025-08-30 15:49:11 +02:00
Sam Atkins
6b53454b68 LibWeb/SVG: Move path data into Path.{h,cpp}
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.
2025-07-17 13:59:23 -04:00
Timothy Flynn
62d9a84b8d AK+Everywhere: Replace custom number parsers with fast_float
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.
2025-07-03 09:51:56 -04:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Renamed from Userland/Libraries/LibWeb/SVG/AttributeParser.cpp (Browse further)