Skip to content

Fix skewed borders and text-decoration thickness #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions Source/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -105,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.
Expand Down Expand Up @@ -396,19 +408,34 @@ void GraphicsContextHaiku::drawFocusRing(const Vector<FloatRect>& 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&,
Expand Down