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.
This commit is contained in:
Sam Atkins 2025-07-17 15:04:25 +01:00 committed by Alexander Kalenik
commit 6b53454b68
Notes: github-actions[bot] 2025-07-17 18:00:44 +00:00
9 changed files with 322 additions and 272 deletions

View file

@ -26,7 +26,7 @@ Optional<Vector<Transform>> AttributeParser::parse_transform(StringView input)
return parser.parse_transform();
}
Vector<PathInstruction> AttributeParser::parse_path_data(StringView input)
Path AttributeParser::parse_path_data(StringView input)
{
AttributeParser parser { input };
parser.parse_whitespace();
@ -37,9 +37,9 @@ Vector<PathInstruction> AttributeParser::parse_path_data(StringView input)
}
if (!parser.m_instructions.is_empty() && parser.m_instructions[0].type != PathInstructionType::Move) {
// Invalid. "A path data segment (if there is one) must begin with a "moveto" command."
return {};
return Path { {} };
}
return parser.m_instructions;
return Path { parser.m_instructions };
}
Optional<float> AttributeParser::parse_coordinate(StringView input)