From 793417ce75bef47dd42e16a6cf9bf081db4238a5 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 24 Nov 2021 11:58:02 +0100 Subject: [PATCH] Fix gaps between lines of selection When a font has fractional metrics, we could get visible gaps between lines in a multi-line selection, if the bottom of the rect was not aligned to the pixel grid. In Qt 5, this was primarily an issue on macOS, but since making vertical metrics consistent in f761ad3cd9ad1252f24b76ae413298dc7bed8af3, we could also get this on other platforms, causing a regression on these platforms. The fix is to align the rect to the pixel grid. [ChangeLog][Text] Fixed an issue where there would sometimes be visible gaps in selections spanning multiple lines. Pick-to: 6.2 Fixes: QTBUG-98372 Change-Id: I03cb1465602b6d78c60a0c764d920f7f092418a8 Reviewed-by: Konstantin Ritt Reviewed-by: Volker Hilsheimer Reviewed-by: Qt CI Bot --- src/gui/text/qtextlayout.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 03eaa9c7264..dfcbf6a7868 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1108,6 +1108,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QList QRectF lineRect(tl.naturalTextRect()); lineRect.translate(position); lineRect.adjust(0, 0, d->leadingSpaceWidth(sl).toReal(), 0); + lineRect.setBottom(qCeil(lineRect.bottom())); bool isLastLineInBlock = (line == d->lines.size()-1); int sl_length = sl.length + (isLastLineInBlock? 1 : 0); // the infamous newline @@ -1129,6 +1130,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QList QRectF fullLineRect(tl.rect()); fullLineRect.translate(position); fullLineRect.setRight(QFIXED_MAX); + fullLineRect.setBottom(qCeil(fullLineRect.bottom())); const bool rightToLeft = d->isRightToLeft();