From 868991f2b6bf438ff81cb5fe82e14d0b3f4e41d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= Date: Fri, 25 Feb 2022 19:14:34 +0100 Subject: [PATCH 1/3] Restore pen size after drawing a stroked rect --- .../platform/graphics/haiku/GraphicsContextHaiku.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp b/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp index 42b4be465c30..e3e591a91200 100644 --- a/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp +++ b/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp @@ -72,11 +72,7 @@ void GraphicsContextHaiku::drawRect(const FloatRect& rect, float borderThickness m_view->FillRect(rect, B_SOLID_LOW); // TODO: Support gradients - if (strokeStyle() != NoStroke && borderThickness > 0.0f && strokeColor().isVisible()) - { - m_view->SetPenSize(borderThickness); - m_view->StrokeRect(rect, m_strokeStyle); - } + strokeRect(rect, borderThickness); } void GraphicsContextHaiku::drawNativeImage(NativeImage& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) From 90e7e357f41f77211cce2c04e4b5f672d79a140c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= Date: Sat, 26 Feb 2022 16:04:47 +0100 Subject: [PATCH 2/3] Set pen size for text lines Fixes part of https://dev.haiku-os.org/ticket/17611 --- .../graphics/haiku/GraphicsContextHaiku.cpp | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp b/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp index e3e591a91200..12010141a69f 100644 --- a/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp +++ b/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp @@ -392,19 +392,34 @@ void GraphicsContextHaiku::drawFocusRing(const Vector& rects, float w m_view->PopState(); } -void GraphicsContextHaiku::drawLinesForText(const FloatPoint& point, float, const DashArray& widths, bool printing, bool doubleUnderlines, WebCore::StrokeStyle) +void GraphicsContextHaiku::drawLinesForText(const FloatPoint& point, + float thickness, const DashArray& widths, bool printing, + bool doubleUnderlines, WebCore::StrokeStyle style) { - if (widths.size() <= 0) + if (widths.isEmpty() || style == NoStroke) return; + Color lineColor(strokeColor()); + FloatRect bounds = computeLineBoundsAndAntialiasingModeForText( + FloatRect(point, FloatSize(widths.last(), thickness)), + printing, lineColor); + if (bounds.isEmpty() || !strokeColor().isVisible()) + return; + + float y = bounds.center().y(); + + float oldSize = m_view->PenSize(); + m_view->SetPenSize(bounds.height()); + // TODO would be faster to use BeginLineArray/EndLineArray here - // TODO in Cairo, these are not lines, but filled rectangle? Whats the thickness? for (size_t i = 0; i < widths.size(); i += 2) { - drawLine( - FloatPoint(point.x() + widths[i], point.y()), - FloatPoint(point.x() + widths[i+1], point.y())); + m_view->StrokeLine( + BPoint(bounds.x() + widths[i], y), + BPoint(bounds.x() + widths[i+1], y)); } + + m_view->SetPenSize(oldSize); } void GraphicsContextHaiku::drawDotsForDocumentMarker(WebCore::FloatRect const&, From 78202a8cd6b26ae18ef8539470b15cf32fa1d283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= Date: Fri, 25 Feb 2022 20:42:44 +0100 Subject: [PATCH 3/3] Fix skewed styled borders The arguments for GraphicsContext::drawLine are the top left and bottom right limits of the rectangle for that line considering its thickness, not the start and end points. Fixes the other part of https://dev.haiku-os.org/ticket/17611 --- .../graphics/haiku/GraphicsContextHaiku.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp b/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp index 12010141a69f..68030eea033b 100644 --- a/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp +++ b/Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp @@ -101,11 +101,27 @@ void GraphicsContextHaiku::drawBitmap(BBitmap* image, const FloatSize& imageSize } // This is only used to draw borders. +// The line width is already accounted for, the points being not the center of +// the edges, but opposite corners of the rectangle containing the line. void GraphicsContextHaiku::drawLine(const FloatPoint& point1, const FloatPoint& point2) { if (strokeStyle() == NoStroke || !strokeColor().isVisible()) return; - m_view->StrokeLine(point1, point2, m_strokeStyle); + + BPoint start = point1; + BPoint end = point2; + // This test breaks for a vertical line as wide as long, but in that + // case there's no information to tell vertical and horizontal apart. + if (fabs(end.y - start.y - m_view->PenSize()) < 1) { + // Horizontal line + end.y = start.y = (end.y + start.y) / 2; + end.x--; + } else { + // Vertical line + end.x = start.x = (end.x + start.x) / 2; + end.y--; + } + m_view->StrokeLine(start, end, m_strokeStyle); } // This method is only used to draw the little circles used in lists.