mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
LibGfx: Add method for copying a Path with a transform applied
The Web's CanvasRenderingContext2D needs a way to draw a path with a transform applied to it, without modifying the original path, so here it is. :^)
This commit is contained in:
parent
2ec52bbbd5
commit
389f1ee6f5
2 changed files with 46 additions and 0 deletions
|
@ -332,4 +332,48 @@ void Path::segmentize_path()
|
||||||
m_bounding_box = Gfx::FloatRect { min_x, min_y, max_x - min_x, max_y - min_y };
|
m_bounding_box = Gfx::FloatRect { min_x, min_y, max_x - min_x, max_y - min_y };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path Path::copy_transformed(Gfx::AffineTransform const& transform) const
|
||||||
|
{
|
||||||
|
Path result;
|
||||||
|
|
||||||
|
for (auto const& segment : m_segments) {
|
||||||
|
switch (segment.type()) {
|
||||||
|
case Segment::Type::MoveTo:
|
||||||
|
result.move_to(transform.map(segment.point()));
|
||||||
|
break;
|
||||||
|
case Segment::Type::LineTo: {
|
||||||
|
result.line_to(transform.map(segment.point()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Segment::Type::QuadraticBezierCurveTo: {
|
||||||
|
auto const& quadratic_segment = static_cast<QuadraticBezierCurveSegment const&>(segment);
|
||||||
|
result.quadratic_bezier_curve_to(transform.map(quadratic_segment.through()), transform.map(segment.point()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Segment::Type::CubicBezierCurveTo: {
|
||||||
|
auto const& cubic_segment = static_cast<CubicBezierCurveSegment const&>(segment);
|
||||||
|
result.cubic_bezier_curve_to(transform.map(cubic_segment.through_0()), transform.map(cubic_segment.through_1()), transform.map(segment.point()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Segment::Type::EllipticalArcTo: {
|
||||||
|
auto const& arc_segment = static_cast<EllipticalArcSegment const&>(segment);
|
||||||
|
result.elliptical_arc_to(
|
||||||
|
transform.map(segment.point()),
|
||||||
|
transform.map(arc_segment.center()),
|
||||||
|
transform.map(arc_segment.radii()),
|
||||||
|
arc_segment.x_axis_rotation(),
|
||||||
|
arc_segment.theta_1(),
|
||||||
|
arc_segment.theta_delta(),
|
||||||
|
arc_segment.large_arc(),
|
||||||
|
arc_segment.sweep());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Segment::Type::Invalid:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,6 +243,8 @@ public:
|
||||||
return m_bounding_box.value();
|
return m_bounding_box.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path copy_transformed(AffineTransform const&) const;
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue