Repository: microsoft/terminal
File: src/renderer/gdi/paint.cpp (C++)

Code before:
    const auto DrawStrokedLine = [&](const auto x, const auto y, const auto w) {
        RETURN_HR_IF(E_FAIL, !MoveToEx(_hdcMemoryContext, x, y, nullptr));
        RETURN_HR_IF(E_FAIL, !LineTo(_hdcMemoryContext, x + w, y));
        return S_OK;
    };
    const auto DrawCurlyLine = [&](const auto x, const auto y, const auto cCurlyLines) {
        const auto curlyLineWidth = fontWidth;
        const auto curlyLineHalfWidth = std::lround(curlyLineWidth / 2.0f);
        const auto controlPointHeight = std::lround(3.5f * _lineMetrics.curlylinePeakHeight);

        // Each curlyLine requires 3 `POINT`s
        const auto cPoints = gsl::narrow<DWORD>(3 * cCurlyLines);
        std::vector<POINT> points;
        points.reserve(cPoints);

        const auto end = x + gsl::narrow_cast<til::CoordType>(cCurlyLines * curlyLineWidth);
        auto start = x;
        while (start < end)
        {
            points.emplace_back(start + curlyLineHalfWidth, y - controlPointHeight);
            points.emplace_back(start + curlyLineHalfWidth, y + controlPointHeight);
            points.emplace_back(start + curlyLineWidth, y);
            start += curlyLineWidth;
        }

        RETURN_HR_IF(E_FAIL, !MoveToEx(_hdcMemoryContext, x, y, nullptr));
        RETURN_HR_IF(E_FAIL, !PolyBezierTo(_hdcMemoryContext, points.data(), cPoints));
        return S_OK;
    };

    if (lines.test(GridLines::Left))
    {
        auto x = ptTarget.x;
        for (size_t i = 0; i < cchLine; i++, x += fontWidth)
        {
            RETURN_HR_IF(E_FAIL, !DrawLine(x, ptTarget.y, _lineMetrics.gridlineWidth, fontHeight));
        }
    }

    if (lines.test(GridLines::Right))
    {
        // NOTE: We have to subtract the stroke width from the cell width
        // to ensure the x coordinate remains inside the clipping rectangle.
        auto x = ptTarget.x + fontWidth - _lineMetrics.gridlineWidth;
        for (size_t i = 0; i < cchLine; i++, x += fontWidth)
        {
            RETURN_HR_IF(E_FAIL, !DrawLine(x, ptTarget.y, _lineMetrics.gridlineWidth, fontHeight));
        }
    }

    if (lines.test(GridLines::Top))

Review comment (bug):
BTW in the future we might want to consider to set the DPI of the GDI context to 96. That way we could draw with pixel-accuracy instead of this buggy rounding we currently have to endure at fractual display scalings.

Code after:
    const auto DrawStrokedLine = [&](const til::CoordType x, const til::CoordType y, const unsigned w) {
        RETURN_HR_IF(E_FAIL, !MoveToEx(_hdcMemoryContext, x, y, nullptr));
        RETURN_HR_IF(E_FAIL, !LineTo(_hdcMemoryContext, gsl::narrow_cast<int>(x + w), y));
        return S_OK;
    };
    const auto DrawCurlyLine = [&](const til::CoordType x, const til::CoordType y, const size_t cCurlyLines) {
        const auto curlyLineWidth = fontWidth;
        const auto curlyLineHalfWidth = std::lround(curlyLineWidth / 2.0f);
        const auto controlPointHeight = std::lround(3.5f * _lineMetrics.curlylinePeakHeight);

        // Each curlyLine requires 3 `POINT`s
        const auto cPoints = gsl::narrow<DWORD>(3 * cCurlyLines);
        std::vector<POINT> points;
        points.reserve(cPoints);

        auto start = x;
        for (size_t i = 0; i < cCurlyLines; i++)
        {
            points.emplace_back(start + curlyLineHalfWidth, y - controlPointHeight);
            points.emplace_back(start + curlyLineHalfWidth, y + controlPointHeight);
            points.emplace_back(start + curlyLineWidth, y);
            start += curlyLineWidth;
        }

        RETURN_HR_IF(E_FAIL, !MoveToEx(_hdcMemoryContext, x, y, nullptr));
        RETURN_HR_IF(E_FAIL, !PolyBezierTo(_hdcMemoryContext, points.data(), cPoints));
        return S_OK;
    };

    if (lines.test(GridLines::Left))
    {
        auto x = ptTarget.x;
        for (size_t i = 0; i < cchLine; i++, x += fontWidth)
        {
            RETURN_HR_IF(E_FAIL, !DrawLine(x, ptTarget.y, _lineMetrics.gridlineWidth, fontHeight));
        }
    }

    if (lines.test(GridLines::Right))
    {
        // NOTE: We have to subtract the stroke width from the cell width
        // to ensure the x coordinate remains inside the clipping rectangle.
        auto x = ptTarget.x + fontWidth - _lineMetrics.gridlineWidth;
        for (size_t i = 0; i < cchLine; i++, x += fontWidth)
        {
            RETURN_HR_IF(E_FAIL, !DrawLine(x, ptTarget.y, _lineMetrics.gridlineWidth, fontHeight));
        }
    }

    if (lines.test(GridLines::Top))
    {