On Thu, 10 Feb 2022 11:36:38 GMT, Jay Bhaskar <d...@openjdk.java.net> wrote:

> Issue: The end point of  line in drawLinesForText , add thickness to the 
> endPoint.y(). In this case origin which is start point and the end point 
> would not be same, and line would be drawn not straight.
> Solution: Do not add thickness to the y position of end point of line.
> Start Point(x,y) ----------End Point(x + width, 0)

void GraphicsContextCG::drawLinesForText(const FloatPoint& point, float 
thickness, const DashArray& widths, bool printing, bool doubleLines, 
StrokeStyle strokeStyle)
{
    if (!widths.size())
        return;

    Color localStrokeColor(strokeColor());

    FloatRect bounds = 
computeLineBoundsAndAntialiasingModeForText(FloatRect(point, 
FloatSize(widths.last(), thickness)), printing, localStrokeColor);
    if (bounds.isEmpty())

----------------------------------
computeLineBoundsAndAntialiasingModeForText this will return rect after 
considering thickness.

The TextDecorationPainter::paintTextDecoration..
                    FloatRect underlineBoundingBox = 
m_context.computeUnderlineBoundsForText(rect, m_isPrinting);
                    DashArray intersections = 
m_font.dashesForIntersectionsWithRect(textRun, textOrigin, 
underlineBoundingBox);
                    DashArray boundaries = 
translateIntersectionPointsToSkipInkBoundaries(intersections, 
underlineBoundingBox.height(), rect.width());
                    ASSERT(!(boundaries.size() % 2));
                    // We don't use underlineBoundingBox here because 
drawLinesForText() will run computeUnderlineBoundsForText() internally.
                    m_context.drawLinesForText(rect.location(), rect.height(), 
boundaries, m_isPrinting, style == TextDecorationStyle::Double, strokeStyle);

This is already calculating underlineBoundingBox and generates boundaries. 
 m_context.drawLinesForText(rect.location(), rect.height(), boundaries, 
m_isPrinting, style == TextDecorationStyle::Double, strokeStyle); 
 
rect.height() is passed as thickness.

So, void GraphicsContextJava::drawLinesForText(const FloatPoint& origin, float 
thickness, const DashArray& widths, bool, bool, StrokeStyle stroke) {

    if (paintingDisabled())
        return;

    for (const auto& width : widths) {
        // This is a workaround for http://bugs.webkit.org/show_bug.cgi?id=15659
        StrokeStyle savedStrokeStyle = strokeStyle();
        setStrokeStyle(stroke);

        // do not add thickness to y position of end point , as line should be 
straight to the origin
        FloatPoint endPoint = origin + FloatPoint(width, 0);
        drawLine(
            IntPoint(origin.x(), origin.y()),
            IntPoint(endPoint.x(), endPoint.y()));

        setStrokeStyle(savedStrokeStyle);
    }
}
To calculate end point , we should not add thickess to the end point. Let it 
draw with default thickness.

-------------

PR: https://git.openjdk.java.net/jfx/pull/731

Reply via email to