QPainter: Skip drawing text if target rect is invalid

If drawText() is passed an empty/invalid target rectangle, we would
still go though the motions of laying out and painting the
text. Output would normally be empty, as expected, since the clipping
would take of it. But for paint devices with limited clipping support,
like QSvgGenerator in 1.2 Tiny mode, the text would wrongly show up.

Add a shortcut to skip painting text in this case.

Fixes: QTBUG-127114
Change-Id: Ia7de3e7d2493218fc2a0f6cb0e815285ddceeb1d
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit c7df8dda8b60b4e4e7b1859f462d65cef5d8c85b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eirik Aavitsland 2024-07-12 10:16:05 +02:00 committed by Qt Cherry-pick Bot
parent 68b07f90f9
commit 051764ddf4

View File

@ -7102,6 +7102,13 @@ void qt_format_text(const QFont &fnt, const QRectF &_r,
Q_ASSERT( !((tf & ~Qt::TextDontPrint)!=0 && option!=nullptr) ); // we either have an option or flags
if (_r.isEmpty()) {
if (!brect)
return;
else
tf |= Qt::TextDontPrint;
}
if (option) {
tf |= option->alignment();
if (option->wrapMode() != QTextOption::NoWrap)