From 051764ddf48e16440826f5d23a25aefa3aac91f7 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 12 Jul 2024 10:16:05 +0200 Subject: [PATCH] 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 (cherry picked from commit c7df8dda8b60b4e4e7b1859f462d65cef5d8c85b) Reviewed-by: Qt Cherry-pick Bot --- src/gui/painting/qpainter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index f4b9741eed8..5db34c9c3c8 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -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)