From e82957f5e6fc72e446239e2ee5139b93d3ceac85 Mon Sep 17 00:00:00 2001
From: David Edmundson <kde@davidedmundson.co.uk>
Date: Fri, 22 Nov 2024 21:57:01 +0000
Subject: [PATCH] Use Qt text rendering when high DPI scaling

It is known that native rendering performs badly with scaling and an
existing workaround is in place.

The current check does not work on Wayland that has per-window rather
than per-screen scaling. Given Qt changes hinting preferences when any
scaling is used anyway, we may as well commit to using the non-native
rendering throughout.

For QtQuick the Qt renderer is more performant, handles transformations
better and avoids this issue. Given the results look basically
identical, we can simplify the existing code.

BUG: 479891
---
 .../plasmadesktoptheme.cpp                      | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/kirigami-plasmadesktop-integration/plasmadesktoptheme.cpp b/kirigami-plasmadesktop-integration/plasmadesktoptheme.cpp
index 51a3241f..fac0831f 100644
--- a/kirigami-plasmadesktop-integration/plasmadesktoptheme.cpp
+++ b/kirigami-plasmadesktop-integration/plasmadesktoptheme.cpp
@@ -50,14 +50,15 @@ public:
         connect(qGuiApp, &QGuiApplication::fontDatabaseChanged, this, &StyleSingleton::notifyWatchersConfigurationChange);
         qGuiApp->installEventFilter(this);
 
-        // Use NativeTextRendering as the default text rendering type when the scale factor is an integer.
-        // NativeTextRendering is still distorted sometimes with fractional scale factors,
-        // despite https://bugreports.qt.io/browse/QTBUG-67007 being closed.
-        qreal devicePixelRatio = qGuiApp->devicePixelRatio();
-        QQuickWindow::TextRenderType defaultTextRenderType =
-            int(devicePixelRatio) == devicePixelRatio ? QQuickWindow::NativeTextRendering : QQuickWindow::QtTextRendering;
-        QQuickWindow::setTextRenderType(defaultTextRenderType);
-
+        // NativeTextRendering is still distorted sometimes with fractional scale factors
+        // Given Qt disables all hinting with native rendering when any scaling is used anyway
+        // we can use Qt's rendering throughout
+        // QTBUG-126577
+        if (qApp->devicePixelRatio() == 1.0) {
+            QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
+        } else {
+            QQuickWindow::setTextRenderType(QQuickWindow::QtTextRendering);
+        }
         smallFont = loadSmallFont();
     }
 
-- 
GitLab

