Relayout QStaticText when dpi changes

If the cached font has a different DPI than the one used in
QPainter, we need to treat this the same as if other font
properties have changed and redo the layout.

This happened when running the QStaticText test on Wayland,
because the default dpi was 100 and the QPixmap we ended up
drawing to was 96. This caused the pixel size of the font to
be calculated differently when doing drawText() (using 96 dpi)
and drawStaticText() (using the cached 100 dpi).

Pick-to: 6.4
Fixes: QTBUG-100982
Change-Id: Ie4270341bb8a64b6458eb67ba460a282c65dc26b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2022-06-29 07:53:29 +02:00
parent fef9e0e216
commit ade2df4c4b
2 changed files with 6 additions and 26 deletions

View File

@ -39,6 +39,7 @@
#include <private/qhexstring_p.h>
#include <private/qguiapplication_p.h>
#include <private/qrawfont_p.h>
#include <private/qfont_p.h>
QT_BEGIN_NAMESPACE
@ -5448,7 +5449,9 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText
QStaticTextPrivate *staticText_d =
const_cast<QStaticTextPrivate *>(QStaticTextPrivate::get(&staticText));
if (font() != staticText_d->font) {
QFontPrivate *fp = QFontPrivate::get(font());
QFontPrivate *stfp = QFontPrivate::get(staticText_d->font);
if (font() != staticText_d->font || fp == nullptr || stfp == nullptr || fp->dpi != stfp->dpi) {
staticText_d->font = font();
staticText_d->needsRelayout = true;
}

View File

@ -82,11 +82,6 @@ private:
Q_DECLARE_METATYPE(QImage::Format);
static bool isPlatformWayland()
{
return QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive);
}
void tst_QStaticText::constructionAndDestruction()
{
QStaticText text("My text");
@ -148,8 +143,6 @@ void tst_QStaticText::drawToPoint()
}
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}
@ -190,8 +183,6 @@ void tst_QStaticText::drawToRect()
#endif
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}
@ -246,13 +237,11 @@ void tst_QStaticText::compareToDrawText()
#if defined(DEBUG_SAVE_IMAGE)
imageDrawText.save("compareToDrawText_imageDrawText.png");
imageDrawStaticText.save("compareToDrawText_imageDrawStaticPlainText.png");
imageDrawStaticText.save("compareToDrawText_imageDrawStaticRichText.png");
imageDrawStaticPlainText.save("compareToDrawText_imageDrawStaticPlainText.png");
imageDrawStaticRichText.save("compareToDrawText_imageDrawStaticRichText.png");
#endif
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
if (isPlatformWayland() && font == QFont())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticPlainText, imageDrawText);
QCOMPARE(imageDrawStaticRichText, imageDrawText);
}
@ -360,8 +349,6 @@ void tst_QStaticText::setFont()
#endif
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}
@ -385,8 +372,6 @@ void tst_QStaticText::setTextWidth()
}
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}
@ -414,8 +399,6 @@ void tst_QStaticText::translatedPainter()
}
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}
@ -456,8 +439,6 @@ void tst_QStaticText::rotatedPainter()
if (!supportsTransformations())
QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}
@ -488,8 +469,6 @@ void tst_QStaticText::scaledPainter()
if (!supportsTransformations())
QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}
@ -617,8 +596,6 @@ void tst_QStaticText::transformationChanged()
if (!supportsTransformations())
QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort);
if (isPlatformWayland())
QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort);
QCOMPARE(imageDrawStaticText, imageDrawText);
}