mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-23 17:58:59 +00:00
LibGfx: Output an SVG compatible string from Path::to_byte_string()
This is much more useful than the previous format, as you can now just paste the path into a site like https://svg-path-visualizer.netlify.app/ to debug issues.
This commit is contained in:
parent
0d7107e1d3
commit
d7e2894e57
Notes:
sideshowbarker
2024-07-17 05:19:06 +09:00
Author: https://github.com/MacDue
Commit: d7e2894e57
Pull-request: https://github.com/SerenityOS/serenity/pull/23638
Reviewed-by: https://github.com/trflynn89
2 changed files with 12 additions and 21 deletions
|
@ -291,40 +291,30 @@ void Path::close_all_subpaths()
|
||||||
|
|
||||||
ByteString Path::to_byte_string() const
|
ByteString Path::to_byte_string() const
|
||||||
{
|
{
|
||||||
|
// Dumps this path as an SVG compatible string.
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append("Path { "sv);
|
if (is_empty() || m_commands.first() != PathSegment::MoveTo)
|
||||||
|
builder.append("M 0,0"sv);
|
||||||
for (auto segment : *this) {
|
for (auto segment : *this) {
|
||||||
|
if (!builder.is_empty())
|
||||||
|
builder.append(' ');
|
||||||
switch (segment.command()) {
|
switch (segment.command()) {
|
||||||
case PathSegment::MoveTo:
|
case PathSegment::MoveTo:
|
||||||
builder.append("MoveTo"sv);
|
builder.append('M');
|
||||||
break;
|
break;
|
||||||
case PathSegment::LineTo:
|
case PathSegment::LineTo:
|
||||||
builder.append("LineTo"sv);
|
builder.append('L');
|
||||||
break;
|
break;
|
||||||
case PathSegment::QuadraticBezierCurveTo:
|
case PathSegment::QuadraticBezierCurveTo:
|
||||||
builder.append("QuadraticBezierCurveTo"sv);
|
builder.append('Q');
|
||||||
break;
|
break;
|
||||||
case PathSegment::CubicBezierCurveTo:
|
case PathSegment::CubicBezierCurveTo:
|
||||||
builder.append("CubicBezierCurveTo"sv);
|
builder.append('C');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
builder.appendff("({}", segment.point());
|
for (auto point : segment.points())
|
||||||
|
builder.appendff(" {},{}", point.x(), point.y());
|
||||||
switch (segment.command()) {
|
|
||||||
case PathSegment::QuadraticBezierCurveTo:
|
|
||||||
builder.appendff(", {}"sv, segment.through());
|
|
||||||
break;
|
|
||||||
case PathSegment::CubicBezierCurveTo:
|
|
||||||
builder.appendff(", {}"sv, segment.through_0());
|
|
||||||
builder.appendff(", {}"sv, segment.through_1());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(") "sv);
|
|
||||||
}
|
|
||||||
builder.append('}');
|
|
||||||
return builder.to_byte_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
VERIFY(m_command == Command::CubicBezierCurveTo);
|
VERIFY(m_command == Command::CubicBezierCurveTo);
|
||||||
return m_points[1];
|
return m_points[1];
|
||||||
}
|
}
|
||||||
|
ALWAYS_INLINE ReadonlySpan<FloatPoint> points() const { return m_points; }
|
||||||
|
|
||||||
static constexpr int points_per_command(Command command)
|
static constexpr int points_per_command(Command command)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue