mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +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:
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user