From a21bc11fe11651f6d211489ebfc8435cef877194 Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Tue, 13 Mar 2018 07:46:14 -0600 Subject: [PATCH] Fix text scaling with non-integer scale factors when PLASMA_USE_QT_SCALING=1 is set Summary: When `PLASMA_USE_QT_SCALING=1` is set, Plasma uses native Qt scaling. This works fine for integer scale factors, and fixes a lot of bugs (see [[https://bugs.kde.org/show_bug.cgi?id=356446|Bug 356446]]) but it introduces a new one: with non-integer scale factors, text becomes blurry and pixellated because of a bug in `Text.NativeRendering`: https://bugreports.qt.io/browse/QTBUG-67007 QQC2-desktop-style forces the use of `Text.QtRendering` rendering for non-integer scale factors, successfully working around the problem. But PlasmaComponents QML objects don't implement the same workaround, so we see the issue in Plasma. This patch fixes that, and gets us one step closer to being able to use Qt scaling in Plasmashell. There is no effect when `PLASMA_USE_QT_SCALING=1` is not being used. FIXED-IN 5.13 BUG: 391691 BUG: 384031 CCBUG: 386216 CCBUG: 391695 CCBUG: 391694 CCBUG: 385547 CCBUG: 391692 CCBUG: 356446 Test Plan: Before: `PLASMA_USE_QT_SCALING=1` set, 1.2 scale factor: Plasma text looks awful: {F5749797} After: `PLASMA_USE_QT_SCALING=1` set, 1.2 scale factor: Plasma text looks amazing! {F5749798} Note that we still get sub-pixel anti-aliasing and good kerning. There appear to be no layout regressions. Without both `PLASMA_USE_QT_SCALING=1` and a non-integer scale factor set, there is no visual change compared to the status quo. Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: mart, broulik, #frameworks Tags: #frameworks Differential Revision: https://phabricator.kde.org/D11244 --- examples/applets/testtheme/contents/ui/FontGizmo.qml | 6 ++++-- src/declarativeimports/plasmacomponents/qml/Label.qml | 6 +++++- .../plasmacomponents/qml/private/DualStateButton.qml | 6 +++++- src/declarativeimports/plasmacomponents3/ComboBox.qml | 4 ++++ src/declarativeimports/plasmacomponents3/Label.qml | 6 +++++- src/declarativeimports/plasmacomponents3/TextArea.qml | 6 +++++- src/declarativeimports/plasmacomponents3/TextField.qml | 6 +++++- src/declarativeimports/plasmastyle/ComboBoxStyle.qml | 5 +++++ src/declarativeimports/plasmastyle/SpinBoxStyle.qml | 5 ++++- src/declarativeimports/plasmastyle/TextAreaStyle.qml | 5 ++++- src/declarativeimports/plasmastyle/TextFieldStyle.qml | 5 ++++- 11 files changed, 50 insertions(+), 10 deletions(-) diff --git a/examples/applets/testtheme/contents/ui/FontGizmo.qml b/examples/applets/testtheme/contents/ui/FontGizmo.qml index 79e9affb2..e0e7976d2 100644 --- a/examples/applets/testtheme/contents/ui/FontGizmo.qml +++ b/examples/applets/testtheme/contents/ui/FontGizmo.qml @@ -17,7 +17,7 @@ */ import QtQuick 2.1 - +import QtQuick.Window 2.2 import QtQuick.Controls 1.0 import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate @@ -28,7 +28,9 @@ import org.kde.plasma.core 2.0 as PlasmaCore Text { - renderType: QtQuickControlsPrivate.Settings.isMobile ? Text.QtRendering : Text.NativeRendering + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: QtQuickControlsPrivate.Settings.isMobile || Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering font.pointSize: 22 //font.family: theme.defaultFont.family diff --git a/src/declarativeimports/plasmacomponents/qml/Label.qml b/src/declarativeimports/plasmacomponents/qml/Label.qml index 65ac2d651..6e6e1a9a7 100644 --- a/src/declarativeimports/plasmacomponents/qml/Label.qml +++ b/src/declarativeimports/plasmacomponents/qml/Label.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.1 +import QtQuick.Window 2.2 import QtQuick.Controls 1.0 import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import org.kde.plasma.core 2.0 as PlasmaCore @@ -41,7 +42,10 @@ Text { verticalAlignment: lineCount > 1 ? Text.AlignTop : Text.AlignVCenter activeFocusOnTab: false - renderType: QtQuickControlsPrivate.Settings.isMobile ? Text.QtRendering : Text.NativeRendering + + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: QtQuickControlsPrivate.Settings.isMobile || Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering font.capitalization: theme.defaultFont.capitalization font.family: theme.defaultFont.family diff --git a/src/declarativeimports/plasmacomponents/qml/private/DualStateButton.qml b/src/declarativeimports/plasmacomponents/qml/private/DualStateButton.qml index 7830e601d..7ac05718b 100644 --- a/src/declarativeimports/plasmacomponents/qml/private/DualStateButton.qml +++ b/src/declarativeimports/plasmacomponents/qml/private/DualStateButton.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.1 +import QtQuick.Window 2.2 import QtQuick.Controls 1.0 import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import org.kde.plasma.core 2.0 as PlasmaCore @@ -95,7 +96,10 @@ Item { id: label text: dualButton.text - renderType: QtQuickControlsPrivate.Settings.isMobile ? Text.QtRendering : Text.NativeRendering + + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: QtQuickControlsPrivate.Settings.isMobile || Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering anchors { top: parent.top bottom: parent.bottom diff --git a/src/declarativeimports/plasmacomponents3/ComboBox.qml b/src/declarativeimports/plasmacomponents3/ComboBox.qml index b0a843023..a320f3687 100644 --- a/src/declarativeimports/plasmacomponents3/ComboBox.qml +++ b/src/declarativeimports/plasmacomponents3/ComboBox.qml @@ -39,6 +39,10 @@ T.ComboBox { rightPadding: surfaceNormal.margins.right bottomPadding: surfaceNormal.margins.bottom + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering + delegate: ItemDelegate { width: control.popup.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData diff --git a/src/declarativeimports/plasmacomponents3/Label.qml b/src/declarativeimports/plasmacomponents3/Label.qml index 630918083..0368f31a1 100644 --- a/src/declarativeimports/plasmacomponents3/Label.qml +++ b/src/declarativeimports/plasmacomponents3/Label.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.1 +import QtQuick.Window 2.2 import QtQuick.Templates @QQC2_VERSION@ as T import org.kde.plasma.core 2.0 as PlasmaCore @@ -27,7 +28,10 @@ T.Label { verticalAlignment: lineCount > 1 ? Text.AlignTop : Text.AlignVCenter activeFocusOnTab: false - renderType: Text.NativeRendering + + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering //font data is the system one by default //TODO: from theme singleton? diff --git a/src/declarativeimports/plasmacomponents3/TextArea.qml b/src/declarativeimports/plasmacomponents3/TextArea.qml index 861d02203..8d5f969bb 100644 --- a/src/declarativeimports/plasmacomponents3/TextArea.qml +++ b/src/declarativeimports/plasmacomponents3/TextArea.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.6 +import QtQuick.Window 2.2 import QtQuick.Controls @QQC2_VERSION@ import QtQuick.Templates @QQC2_VERSION@ as T import org.kde.plasma.core 2.0 as PlasmaCore @@ -41,7 +42,10 @@ T.TextArea { opacity: control.enabled ? 1 : 0.6 wrapMode: Text.WordWrap verticalAlignment: TextEdit.AlignTop - renderType: Text.NativeRendering + + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering Label { id: placeholder diff --git a/src/declarativeimports/plasmacomponents3/TextField.qml b/src/declarativeimports/plasmacomponents3/TextField.qml index b75cb0622..6d833d9f8 100644 --- a/src/declarativeimports/plasmacomponents3/TextField.qml +++ b/src/declarativeimports/plasmacomponents3/TextField.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.6 +import QtQuick.Window 2.2 import QtQuick.Controls @QQC2_VERSION@ import QtQuick.Templates @QQC2_VERSION@ as T import org.kde.plasma.core 2.0 as PlasmaCore @@ -39,7 +40,10 @@ T.TextField { selectedTextColor: theme.highlightedTextColor verticalAlignment: TextInput.AlignVCenter opacity: control.enabled ? 1 : 0.6 - renderType: Text.NativeRendering + + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering Label { id: placeholder diff --git a/src/declarativeimports/plasmastyle/ComboBoxStyle.qml b/src/declarativeimports/plasmastyle/ComboBoxStyle.qml index 779cf4b8e..0d284a422 100644 --- a/src/declarativeimports/plasmastyle/ComboBoxStyle.qml +++ b/src/declarativeimports/plasmastyle/ComboBoxStyle.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.0 +import QtQuick.Window 2.2 import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import org.kde.plasma.core 2.0 as PlasmaCore @@ -28,6 +29,10 @@ import "private" as Private QtQuickControlStyle.ComboBoxStyle { drowDownButtonWidth: units.iconSizes.small + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering + label: PlasmaComponents.Label { text: control.currentText elide: Text.ElideRight diff --git a/src/declarativeimports/plasmastyle/SpinBoxStyle.qml b/src/declarativeimports/plasmastyle/SpinBoxStyle.qml index 8f00720a2..92e77454a 100644 --- a/src/declarativeimports/plasmastyle/SpinBoxStyle.qml +++ b/src/declarativeimports/plasmastyle/SpinBoxStyle.qml @@ -19,6 +19,7 @@ */ import QtQuick 2.0 +import QtQuick.Window 2.2 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate @@ -40,7 +41,9 @@ QtQuickControlStyle.SpinBoxStyle { selectedTextColor: theme.viewBackgroundColor - renderType: QtQuickControlsPrivate.Settings.isMobile ? Text.QtRendering : Text.NativeRendering + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: QtQuickControlsPrivate.Settings.isMobile || Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering PlasmaCore.Svg { id: arrowSvg diff --git a/src/declarativeimports/plasmastyle/TextAreaStyle.qml b/src/declarativeimports/plasmastyle/TextAreaStyle.qml index 3b4cb917f..4ea7eba03 100644 --- a/src/declarativeimports/plasmastyle/TextAreaStyle.qml +++ b/src/declarativeimports/plasmastyle/TextAreaStyle.qml @@ -19,6 +19,7 @@ import QtQuick 2.1 +import QtQuick.Window 2.2 import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import QtQuick.Controls 1.1 @@ -41,7 +42,9 @@ QtQuickControlStyle.TextAreaStyle { selectionColor: control.backgroundVisible ? theme.viewFocusColor : PlasmaCore.ColorScope.highlightColor selectedTextColor: control.backgroundVisible ? theme.viewHighlightedTextColor : PlasmaCore.ColorScope.highlightedTextColor - renderType: QtQuickControlsPrivate.Settings.isMobile ? Text.QtRendering : Text.NativeRendering + // Work around Qt bug where NativeRendering breaks for non-integer scale factors + // https://bugreports.qt.io/browse/QTBUG-67007 + renderType: QtQuickControlsPrivate.Settings.isMobile || Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering frame: PlasmaCore.FrameSvgItem { id: base diff --git a/src/declarativeimports/plasmastyle/TextFieldStyle.qml b/src/declarativeimports/plasmastyle/TextFieldStyle.qml index 3c2499e13..836bcc613 100644 --- a/src/declarativeimports/plasmastyle/TextFieldStyle.qml +++ b/src/declarativeimports/plasmastyle/TextFieldStyle.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.0 +import QtQuick.Window 2.2 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate @@ -40,8 +41,10 @@ QtQuickControlStyle.TextFieldStyle { * more blurred with different rendring types. * Using Qt rendering, the dots will look more aligned and equally spaced. * Also if we are on mobile, make sure we use QtRendering + * Finally, use QtRendering if we're using a non-integer scale factor to work around + * https://bugreports.qt.io/browse/QTBUG-67007 */ - renderType: !QtQuickControlsPrivate.Settings.isMobile && control.echoMode == TextInput.Normal ? Text.NativeRendering : Text.QtRendering + renderType: !QtQuickControlsPrivate.Settings.isMobile && control.echoMode == TextInput.Normal && Screen.devicePixelRatio % 1 == 0 ? Text.NativeRendering : Text.QtRendering background: Item { //QQC button heights are max(backgroundHeight, label + margins).