mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-08 04:50:08 +03: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: https://github.com/SerenityOS/serenity/commit/d7e2894e57 Pull-request: https://github.com/SerenityOS/serenity/pull/23638 Reviewed-by: https://github.com/trflynn89
@ -291,40 +291,30 @@ void Path::close_all_subpaths()
|
||||
|
||||
ByteString Path::to_byte_string() const
|
||||
{
|
||||
// Dumps this path as an SVG compatible string.
|
||||
StringBuilder builder;
|
||||
builder.append("Path { "sv);
|
||||
if (is_empty() || m_commands.first() != PathSegment::MoveTo)
|
||||
builder.append("M 0,0"sv);
|
||||
for (auto segment : *this) {
|
||||
if (!builder.is_empty())
|
||||
builder.append(' ');
|
||||
switch (segment.command()) {
|
||||
case PathSegment::MoveTo:
|
||||
builder.append("MoveTo"sv);
|
||||
builder.append('M');
|
||||
break;
|
||||
case PathSegment::LineTo:
|
||||
builder.append("LineTo"sv);
|
||||
builder.append('L');
|
||||
break;
|
||||
case PathSegment::QuadraticBezierCurveTo:
|
||||
builder.append("QuadraticBezierCurveTo"sv);
|
||||
builder.append('Q');
|
||||
break;
|
||||
case PathSegment::CubicBezierCurveTo:
|
||||
builder.append("CubicBezierCurveTo"sv);
|
||||
builder.append('C');
|
||||
break;
|
||||
}
|
||||
builder.appendff("({}", segment.point());
|
||||
|
||||
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);
|
||||
for (auto point : segment.points())
|
||||
builder.appendff(" {},{}", point.x(), point.y());
|
||||
}
|
||||
builder.append('}');
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
VERIFY(m_command == Command::CubicBezierCurveTo);
|
||||
return m_points[1];
|
||||
}
|
||||
ALWAYS_INLINE ReadonlySpan<FloatPoint> points() const { return m_points; }
|
||||
|
||||
static constexpr int points_per_command(Command command)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user