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
This commit is contained in:
Nathaniel Graham 2018-03-13 07:46:14 -06:00
parent 5163e3e9ff
commit a21bc11fe1
11 changed files with 50 additions and 10 deletions

View File

@ -17,7 +17,7 @@
*/ */
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Window 2.2
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
@ -28,7 +28,9 @@ import org.kde.plasma.core 2.0 as PlasmaCore
Text { 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.pointSize: 22
//font.family: theme.defaultFont.family //font.family: theme.defaultFont.family

View File

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Window 2.2
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
@ -41,7 +42,10 @@ Text {
verticalAlignment: lineCount > 1 ? Text.AlignTop : Text.AlignVCenter verticalAlignment: lineCount > 1 ? Text.AlignTop : Text.AlignVCenter
activeFocusOnTab: false 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.capitalization: theme.defaultFont.capitalization
font.family: theme.defaultFont.family font.family: theme.defaultFont.family

View File

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Window 2.2
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
@ -95,7 +96,10 @@ Item {
id: label id: label
text: dualButton.text 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 { anchors {
top: parent.top top: parent.top
bottom: parent.bottom bottom: parent.bottom

View File

@ -39,6 +39,10 @@ T.ComboBox {
rightPadding: surfaceNormal.margins.right rightPadding: surfaceNormal.margins.right
bottomPadding: surfaceNormal.margins.bottom 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 { delegate: ItemDelegate {
width: control.popup.width width: control.popup.width
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData

View File

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Window 2.2
import QtQuick.Templates @QQC2_VERSION@ as T import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
@ -27,7 +28,10 @@ T.Label {
verticalAlignment: lineCount > 1 ? Text.AlignTop : Text.AlignVCenter verticalAlignment: lineCount > 1 ? Text.AlignTop : Text.AlignVCenter
activeFocusOnTab: false 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 //font data is the system one by default
//TODO: from theme singleton? //TODO: from theme singleton?

View File

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.6 import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls @QQC2_VERSION@ import QtQuick.Controls @QQC2_VERSION@
import QtQuick.Templates @QQC2_VERSION@ as T import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
@ -41,7 +42,10 @@ T.TextArea {
opacity: control.enabled ? 1 : 0.6 opacity: control.enabled ? 1 : 0.6
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
verticalAlignment: TextEdit.AlignTop 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 { Label {
id: placeholder id: placeholder

View File

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.6 import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls @QQC2_VERSION@ import QtQuick.Controls @QQC2_VERSION@
import QtQuick.Templates @QQC2_VERSION@ as T import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
@ -39,7 +40,10 @@ T.TextField {
selectedTextColor: theme.highlightedTextColor selectedTextColor: theme.highlightedTextColor
verticalAlignment: TextInput.AlignVCenter verticalAlignment: TextInput.AlignVCenter
opacity: control.enabled ? 1 : 0.6 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 { Label {
id: placeholder id: placeholder

View File

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
@ -28,6 +29,10 @@ import "private" as Private
QtQuickControlStyle.ComboBoxStyle { QtQuickControlStyle.ComboBoxStyle {
drowDownButtonWidth: units.iconSizes.small 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 { label: PlasmaComponents.Label {
text: control.currentText text: control.currentText
elide: Text.ElideRight elide: Text.ElideRight

View File

@ -19,6 +19,7 @@
*/ */
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
@ -40,7 +41,9 @@ QtQuickControlStyle.SpinBoxStyle {
selectedTextColor: theme.viewBackgroundColor 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 { PlasmaCore.Svg {
id: arrowSvg id: arrowSvg

View File

@ -19,6 +19,7 @@
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
import QtQuick.Controls 1.1 import QtQuick.Controls 1.1
@ -41,7 +42,9 @@ QtQuickControlStyle.TextAreaStyle {
selectionColor: control.backgroundVisible ? theme.viewFocusColor : PlasmaCore.ColorScope.highlightColor selectionColor: control.backgroundVisible ? theme.viewFocusColor : PlasmaCore.ColorScope.highlightColor
selectedTextColor: control.backgroundVisible ? theme.viewHighlightedTextColor : PlasmaCore.ColorScope.highlightedTextColor 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 { frame: PlasmaCore.FrameSvgItem {
id: base id: base

View File

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
@ -40,8 +41,10 @@ QtQuickControlStyle.TextFieldStyle {
* more blurred with different rendring types. * more blurred with different rendring types.
* Using Qt rendering, the dots will look more aligned and equally spaced. * Using Qt rendering, the dots will look more aligned and equally spaced.
* Also if we are on mobile, make sure we use QtRendering * 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 { background: Item {
//QQC button heights are max(backgroundHeight, label + margins). //QQC button heights are max(backgroundHeight, label + margins).