From d5fb916bf078e969d6d2085a3a2d68b9652481bc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 16 Apr 2020 21:12:14 +0200 Subject: [PATCH] LibWeb: Implement CanvasRenderingContext2D::stroke_rect() with lines Stroking rects by drawing individual lines gives us line width support without having to extend the Painter::draw_rect() code. :^) --- Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp index e0a9320780..44a5a6cb6f 100644 --- a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp @@ -79,7 +79,17 @@ void CanvasRenderingContext2D::stroke_rect(float x, float y, float width, float return; auto rect = m_transform.map(Gfx::FloatRect(x, y, width, height)); - painter->draw_rect(enclosing_int_rect(rect), m_stroke_style); + + auto top_left = m_transform.map(Gfx::FloatPoint(x, y)).to_int_point(); + auto top_right = m_transform.map(Gfx::FloatPoint(x + width - 1, y)).to_int_point(); + auto bottom_left = m_transform.map(Gfx::FloatPoint(x, y + height - 1)).to_int_point(); + auto bottom_right = m_transform.map(Gfx::FloatPoint(x + width - 1, y + height - 1)).to_int_point(); + + painter->draw_line(top_left, top_right, m_stroke_style, m_line_width); + painter->draw_line(top_right, bottom_right, m_stroke_style, m_line_width); + painter->draw_line(bottom_right, bottom_left, m_stroke_style, m_line_width); + painter->draw_line(bottom_left, top_left, m_stroke_style, m_line_width); + did_draw(rect); }