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>
bb10
Eirik Aavitsland 2022-05-23 14:55:37 +02:00
parent 718d680579
commit cc42d90eb4
1 changed files with 12 additions and 5 deletions

View File

@ -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);
}