summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2022-05-23 14:55:37 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2022-05-24 20:20:01 +0200
commitcc42d90eb4fd148656941e9a6395169b5aa4cf73 (patch)
tree2a3937c1ffc0d5cbc07cb283a673961584e78bb7 /src
parent718d680579508284f7617a4e7db24d140438478d (diff)
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 <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qtextlayout.cpp17
1 files 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);
}