[GTK Config] Write Font without style name
Needs ReviewPublic

Authored by gikari on Thu, Feb 13, 7:19 PM.

Details

Reviewers
ervin
bport
meven
Group Reviewers
Plasma
Summary

It has been reported, that on localized systems
the font style was written in local language.
Therefore config line was incorrectly read by
GTK and therefore applications displayed bad
font. To avoid that this commit is introduced.

This is not an ideal solution, because the selected
font style in font dialog will be ignored by GTK applications.
However, there is a workaround for that: you need to select a
font with the style in its family name. For example: "Inter"
with style "Medium" will be "Inter Medium". But some styles
do not have these "clones", e.g. Regular, Bold and Italic.

At least ignored style with very easy workaround is better, than
no ability to correctly apply a font at all with a very tedious
workaround aka "manually editing a lot of GTK config files and options".

BUG: 333146
FIXED-IN: 5.18.1

Test Plan
  1. Apply fonts with style and see, that it is not propagated to GTK configs.
  2. Apply fonts with the same styles in their family name to see, that they are working correctly.

Diff Detail

Repository
R99 KDE Gtk Configuration Tool
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 22445
Build 22463: arc lint + arc unit
gikari created this revision.Thu, Feb 13, 7:19 PM
Restricted Application added a project: Plasma. · View Herald TranscriptThu, Feb 13, 7:19 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
gikari requested review of this revision.Thu, Feb 13, 7:19 PM
gikari edited the summary of this revision. (Show Details)Thu, Feb 13, 7:20 PM

I don't understand the problem in-depth, but isn't it possible to write non-localized style name instead?

I don't understand the problem in-depth, but isn't it possible to write non-localized style name instead?

Indeed.

Is the problem that the style name is already localized by the time we get it from the Fonts KCM?

cfeck added a subscriber: cfeck.Thu, Feb 13, 9:41 PM

So... is this all related to bug https://bugs.kde.org/show_bug.cgi?id=378523 ?
:/

Is the problem that the style name is already localized by the time we get it from the Fonts KCM?

Yes. It's already displayed localized, so that I cannot do anything with it.

Is the problem that the style name is already localized by the time we get it from the Fonts KCM?

Yes. It's already displayed localized, so that I cannot do anything with it.

So maybe that's something we can fix in the Fonts KCM? Or Is it caused by the Qt bug ultimately causing https://bugs.kde.org/show_bug.cgi?id=378523?

gikari added a comment.EditedThu, Feb 13, 10:06 PM

So maybe that's something we can fix in the Fonts KCM? Or Is it caused by the Qt bug ultimately causing https://bugs.kde.org/show_bug.cgi?id=378523?

Probably a Qt bug, because Fonts KCM uses QtQuick.Dialogs.FontDialog, and there is already the localized style displayed at some fonts.

*groan*

I guess we need to fix it Qt then. I don't know much about fonts but maybe it could display the localized string in the UI but write an un-localized version to the config file? Would that work? And then maybe we can somehow finally fix https://bugs.kde.org/show_bug.cgi?id=378523.

Take this code:

static QString styleStringHelper(int weight, QFont::Style style)
{
    QString result;
    if (weight > QFont::Normal) {
        if (weight >= QFont::Black)
            result = QCoreApplication::translate("QFontDatabase", "Black");
        else if (weight >= QFont::ExtraBold)
            result = QCoreApplication::translate("QFontDatabase", "Extra Bold");
        else if (weight >= QFont::Bold)
            result = QCoreApplication::translate("QFontDatabase", "Bold");
        else if (weight >= QFont::DemiBold)
            result = QCoreApplication::translate("QFontDatabase", "Demi Bold");
        else if (weight >= QFont::Medium)
            result = QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight");
    } else {
        if (weight <= QFont::Thin)
            result = QCoreApplication::translate("QFontDatabase", "Thin");
        else if (weight <= QFont::ExtraLight)
            result = QCoreApplication::translate("QFontDatabase", "Extra Light");
        else if (weight <= QFont::Light)
            result = QCoreApplication::translate("QFontDatabase", "Light");
    }

    if (style == QFont::StyleItalic)
        result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Italic");
    else if (style == QFont::StyleOblique)
        result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Oblique");

    if (result.isEmpty())
        result = QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight");

    return result.simplified();
}

Drop the QCoreApplication::translate("QFontDatabase", " stuff, and it should work fine.

Take this code

How about other styles, such as Condensed, Book etc?