mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03: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
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/389f1ee6f5 Pull-request: https://github.com/SerenityOS/serenity/pull/14839
@ -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 };
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Path copy_transformed(AffineTransform const&) const;
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user