diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-09-16 16:51:45 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-16 22:30:33 +0200 |
commit | 6c992e5dce1ccfa7903d5a41e10e645dcf166612 (patch) | |
tree | 68d9d46bf86ace58e9ef701a246c0f2c6e8b7b9e /Userland/Libraries/LibGfx/Painter.cpp | |
parent | 3964b81d2b5458c0c4fb102929d3aae61f86feed (diff) | |
download | serenity-6c992e5dce1ccfa7903d5a41e10e645dcf166612.zip |
LibGfx: Don't try to paint 0px-wide lines
In some cases, we were infinite-looping when asked to paint something
with a thickness of '0', so now every Painter method that takes a
thickness, does a check for a thickness <= 0 and bails early. After all,
you can't draw something that's 0px wide. :^)
Diffstat (limited to 'Userland/Libraries/LibGfx/Painter.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index ba692ec7d6..719b52277b 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -486,6 +486,9 @@ void Painter::draw_ellipse_intersecting(const IntRect& rect, Color color, int th { VERIFY(scale() == 1); // FIXME: Add scaling support. + if (thickness <= 0) + return; + constexpr int number_samples = 100; // FIXME: dynamically work out the number of samples based upon the rect size double increment = M_PI / number_samples; @@ -590,6 +593,9 @@ void Painter::draw_rect_with_thickness(const IntRect& rect, Color color, int thi { VERIFY(scale() == 1); // FIXME: Add scaling support. + if (thickness <= 0) + return; + IntPoint p1 = rect.location(); IntPoint p2 = { rect.location().x() + rect.width(), rect.location().y() }; IntPoint p3 = { rect.location().x() + rect.width(), rect.location().y() + rect.height() }; @@ -1634,6 +1640,9 @@ void Painter::draw_physical_pixel(const IntPoint& physical_position, Color color // (including scaling thickness). VERIFY(draw_op() == DrawOp::Copy); + if (thickness <= 0) + return; + if (thickness == 1) { // Implies scale() == 1. auto& pixel = m_target->scanline(physical_position.y())[physical_position.x()]; return set_physical_pixel_with_draw_op(pixel, Color::from_rgba(pixel).blend(color)); @@ -1646,6 +1655,9 @@ void Painter::draw_physical_pixel(const IntPoint& physical_position, Color color void Painter::draw_line(IntPoint const& a_p1, IntPoint const& a_p2, Color color, int thickness, LineStyle style, Color alternate_color) { + if (thickness <= 0) + return; + if (color.alpha() == 0) return; @@ -1837,6 +1849,9 @@ void Painter::draw_quadratic_bezier_curve(const IntPoint& control_point, const I { VERIFY(scale() == 1); // FIXME: Add scaling support. + if (thickness <= 0) + return; + for_each_line_segment_on_bezier_curve(FloatPoint(control_point), FloatPoint(p1), FloatPoint(p2), [&](const FloatPoint& fp1, const FloatPoint& fp2) { draw_line(IntPoint(fp1.x(), fp1.y()), IntPoint(fp2.x(), fp2.y()), color, thickness, style); }); @@ -1902,6 +1917,9 @@ void Painter::draw_elliptical_arc(const IntPoint& p1, const IntPoint& p2, const { VERIFY(scale() == 1); // FIXME: Add scaling support. + if (thickness <= 0) + return; + for_each_line_segment_on_elliptical_arc(FloatPoint(p1), FloatPoint(p2), FloatPoint(center), radii, x_axis_rotation, theta_1, theta_delta, [&](const FloatPoint& fp1, const FloatPoint& fp2) { draw_line(IntPoint(fp1.x(), fp1.y()), IntPoint(fp2.x(), fp2.y()), color, thickness, style); }); @@ -1933,6 +1951,9 @@ void Painter::stroke_path(const Path& path, Color color, int thickness) { VERIFY(scale() == 1); // FIXME: Add scaling support. + if (thickness <= 0) + return; + FloatPoint cursor; for (auto& segment : path.segments()) { |