Repository: microsoft/terminal
File: src/renderer/dx/CustomTextRenderer.cpp (C++)

Code before:
    const DWRITE_GLYPH_RUN* glyphRun,
    const DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription,
    IUnknown* clientDrawingEffect)
{
    // Color glyph rendering sourced from https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DWriteColorGlyph

#pragma warning(suppress : 26429) // Symbol 'drawingContext' is never tested for nullness, it can be marked as not_null (f.23).
    auto drawingContext = static_cast<DrawingContext*>(clientDrawingContext);

    // Since we've delegated the drawing of the background of the text into this function, the origin passed in isn't actually the baseline.
    // It's the top left corner. Save that off first.
    const auto origin = D2D1::Point2F(baselineOriginX, baselineOriginY);

    // Then make a copy for the baseline origin (which is part way down the left side of the text, not the top or bottom).
    // We'll use this baseline Origin for drawing the actual text.
    const D2D1_POINT_2F baselineOrigin{ origin.x, origin.y + drawingContext->spacing.baseline };

    ::Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2dContext;
    RETURN_IF_FAILED(drawingContext->renderTarget->QueryInterface(d2dContext.GetAddressOf()));

    // Determine clip rectangle
    D2D1_RECT_F clipRect;
    clipRect.top = origin.y + drawingContext->topClipOffset;
    clipRect.bottom = origin.y + drawingContext->cellSize.height - drawingContext->bottomClipOffset;
    clipRect.left = 0;
    clipRect.right = drawingContext->targetSize.width;

    // If we already have a clip rectangle, check if it different than the previous one.
    if (_clipRect.has_value())
    {
        const auto storedVal = _clipRect.value();
        // If it is different, pop off the old one and push the new one on.
        if (storedVal.top != clipRect.top || storedVal.bottom != clipRect.bottom ||
            storedVal.left != clipRect.left || storedVal.right != clipRect.right)
        {
            d2dContext->PopAxisAlignedClip();

            // Clip all drawing in this glyph run to where we expect.
            // We need the AntialiasMode here to be Aliased to ensure
            //  that background boxes line up with each other and don't leave behind
            //  stray colors.
            // See GH#3626 for more details.
            d2dContext->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_ALIASED);
            _clipRect = clipRect;
        }
    }
    // If we have no clip rectangle, it's easy. Push it on and go.
    else
    {
        // See above for aliased flag explanation.
        d2dContext->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_ALIASED);

Review comment (suggestion):
👀 

This seems... interesting. Any chance this breaks something by not clipping on the right side anymore? My attempted fix was (I believe) 

```c++
clipRect.left = origin.x;
```

on the line above, but I don't know which is better

Code after:
    const DWRITE_GLYPH_RUN* glyphRun,
    const DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription,
    IUnknown* clientDrawingEffect)
{
    // Color glyph rendering sourced from https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DWriteColorGlyph

#pragma warning(suppress : 26429) // Symbol 'drawingContext' is never tested for nullness, it can be marked as not_null (f.23).
    auto drawingContext = static_cast<DrawingContext*>(clientDrawingContext);

    // Since we've delegated the drawing of the background of the text into this function, the origin passed in isn't actually the baseline.
    // It's the top left corner. Save that off first.
    const auto origin = D2D1::Point2F(baselineOriginX, baselineOriginY);

    // Then make a copy for the baseline origin (which is part way down the left side of the text, not the top or bottom).
    // We'll use this baseline Origin for drawing the actual text.
    const D2D1_POINT_2F baselineOrigin{ origin.x, origin.y + drawingContext->spacing.baseline };

    ::Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2dContext;
    RETURN_IF_FAILED(drawingContext->renderTarget->QueryInterface(d2dContext.GetAddressOf()));

    // Determine clip rectangle
    D2D1_RECT_F clipRect;
    clipRect.top = origin.y + drawingContext->topClipOffset;
    clipRect.bottom = origin.y + drawingContext->cellSize.height - drawingContext->bottomClipOffset;
    clipRect.left = 0;
    clipRect.right = FLT_MAX;

    // If we already have a clip rectangle, check if it different than the previous one.
    if (_clipRect.has_value())
    {
        const auto storedVal = _clipRect.value();
        // If it is different, pop off the old one and push the new one on.
        if (storedVal.top != clipRect.top || storedVal.bottom != clipRect.bottom ||
            storedVal.left != clipRect.left || storedVal.right != clipRect.right)
        {
            d2dContext->PopAxisAlignedClip();

            // Clip all drawing in this glyph run to where we expect.
            // We need the AntialiasMode here to be Aliased to ensure
            //  that background boxes line up with each other and don't leave behind
            //  stray colors.
            // See GH#3626 for more details.
            d2dContext->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_ALIASED);
            _clipRect = clipRect;
        }
    }
    // If we have no clip rectangle, it's easy. Push it on and go.
    else
    {
        // See above for aliased flag explanation.
        d2dContext->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_ALIASED);