Skip to content

Commit

Permalink
Incorrect Rendering of Dashed Underline in WebKit
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268448

Reviewed by Alan Baradlay.

This commit updates the rendering logic for dashed lines. Previously, dashes intersecting with the specified boundaries were completely omitted. Now, the rendering process trims these dashes at the intersection points instead of entirely removing them. This enhancement ensures a more accurate and visually consistent representation of dashed lines, especially in scenarios where partial dashes are expected to be visible at the edges.

* Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContextCG::drawLinesForText):

Canonical link: https://commits.webkit.org/276585@main
  • Loading branch information
ptu14 authored and Ahmad Saleem committed Mar 23, 2024
1 parent bf47c37 commit f4bc380
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,10 +1396,30 @@ void GraphicsContextCG::drawLinesForText(const FloatPoint& point, float thicknes
if (!dashWidth)
dashBounds.append(CGRectMake(bounds.x() + left, bounds.y(), width, bounds.height()));
else {
auto startParticle = static_cast<int>(std::ceil(left / (2 * dashWidth)));
auto endParticle = static_cast<int>((left + width) / (2 * dashWidth));
for (auto j = startParticle; j < endParticle; ++j)
dashBounds.append(CGRectMake(bounds.x() + j * 2 * dashWidth, bounds.y(), dashWidth, bounds.height()));
auto doubleWidth = 2 * dashWidth;
auto quotient = static_cast<int>(left / doubleWidth);
auto startOffset = left - quotient * doubleWidth;
auto effectiveLeft = left + startOffset;
auto startParticle = static_cast<int>(std::floor(effectiveLeft / doubleWidth));
auto endParticle = static_cast<int>(std::ceil((left + width) / doubleWidth));

for (auto j = startParticle; j < endParticle; ++j) {
auto actualDashWidth = dashWidth;
auto dashStart = bounds.x() + j * doubleWidth;

if (j == startParticle && startOffset > 0 && startOffset < dashWidth) {
actualDashWidth -= startOffset;
dashStart += startOffset;
}

if (j == endParticle - 1) {
auto remainingWidth = left + width - (j * doubleWidth);
if (remainingWidth < dashWidth)
actualDashWidth = remainingWidth;
}

dashBounds.append(CGRectMake(dashStart, bounds.y(), actualDashWidth, bounds.height()));
}
}
}

Expand Down

0 comments on commit f4bc380

Please sign in to comment.