From c7df8dda8b60b4e4e7b1859f462d65cef5d8c85b 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 Pick-to: 6.8 Change-Id: Ia7de3e7d2493218fc2a0f6cb0e815285ddceeb1d Reviewed-by: Eskil Abrahamsen Blomfeldt --- 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 830f91face7..d19a4de04c8 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7104,6 +7104,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)