From cc42d90eb4fd148656941e9a6395169b5aa4cf73 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 23 May 2022 14:55:37 +0200 Subject: Enable text layout drawing on coordinates outside QFIXED_MAX In an earlier commit, painting on such coordinates was rejected, since it would overflow the internal calculations using QFixed. Instead, avoid the overflow by translating the painter to avoid the huge coordinate values. Also reduce the max value somewhat, so that pos stays well away from QFIXED_MAX, to avoid overflows in the other QFixed variables that have values offset from pos. Fixes: QTBUG-103745 Pick-to: 6.3 6.2 Change-Id: Iebdec32bed57fe8e65551c7d278da9fd6c041b37 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextlayout.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 92af43d526..eb71b46526 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2468,7 +2468,7 @@ void QTextLine::draw(QPainter *painter, const QPointF &position) const draw_internal(painter, position, nullptr); } -void QTextLine::draw_internal(QPainter *p, const QPointF &pos, +void QTextLine::draw_internal(QPainter *p, const QPointF &origPos, const QTextLayout::FormatRange *selection) const { #ifndef QT_NO_RAWFONT @@ -2486,7 +2486,7 @@ void QTextLine::draw_internal(QPainter *p, const QPointF &pos, && selection->start + selection->length > line.from) { const qreal lineHeight = line.height().toReal(); - QRectF r(pos.x() + line.x.toReal(), pos.y() + line.y.toReal(), + QRectF r(origPos.x() + line.x.toReal(), origPos.y() + line.y.toReal(), lineHeight / 2, QFontMetrics(eng->font()).horizontalAdvance(u' ')); setPenAndDrawBackground(p, QPen(), selection->format, r); p->setPen(pen); @@ -2494,9 +2494,13 @@ void QTextLine::draw_internal(QPainter *p, const QPointF &pos, return; } - static QRectF maxFixedRect(QPointF(-QFIXED_MAX, -QFIXED_MAX), QPointF(QFIXED_MAX, QFIXED_MAX)); - if (!maxFixedRect.contains(pos)) - return; + static QRectF maxFixedRect(-QFIXED_MAX / 2, -QFIXED_MAX / 2, QFIXED_MAX, QFIXED_MAX); + const bool xlateToFixedRange = !maxFixedRect.contains(origPos); + QPointF pos; + if (Q_LIKELY(!xlateToFixedRange)) + pos = origPos; + else + p->translate(origPos); QTextLineItemIterator iterator(eng, index, pos, selection); QFixed lineBase = line.base(); @@ -2689,6 +2693,9 @@ void QTextLine::draw_internal(QPainter *p, const QPointF &pos, } eng->drawDecorations(p); + if (xlateToFixedRange) + p->translate(-origPos); + if (eng->hasFormats()) p->setPen(pen); } -- cgit v1.2.3