File 0007-Fix-BUG-105797-inappropriate-fontconfig-settings-are.patch of Package plasma5-desktop.openSUSE_13.2_Update
From f02df03cb87b4bb5724eec668d49126a5f52a1e7 Mon Sep 17 00:00:00 2001
From: Fuminobu TAKEYAMA <ftake@geeko.jp>
Date: Mon, 29 Sep 2014 11:22:05 +0200
Subject: [PATCH 07/15] Fix BUG#105797: inappropriate fontconfig settings are
saved when kcontrol/fonts is shown and no way to revert them
Fix kcontrol/fonts saves fontconfig settings when it is opened. Add "System default" to each config. It removes a corresponding fontconfig entry made by this module. "System default" is now default values for sub-pixel rendering and hinting.
Selecting "System default" also reverts Xft configs.
BUG: 105797
REVIEW: 119764
BUG: 105797
---
kcms/fonts/fonts.cpp | 80 ++++++++++++++++-----------------
kcms/fonts/fonts.h | 5 ++-
kcms/fonts/kxftconfig.cpp | 110 ++++++++++++++++++++++++++++------------------
kcms/fonts/kxftconfig.h | 25 +++++++----
4 files changed, 126 insertions(+), 94 deletions(-)
diff --git a/kcms/fonts/fonts.cpp b/kcms/fonts/fonts.cpp
index 1b5175e..a4c9655 100644
--- a/kcms/fonts/fonts.cpp
+++ b/kcms/fonts/fonts.cpp
@@ -150,7 +150,7 @@ static const char *const aa_vbgr_xpm[] = {
"aaaaaaaaaaaa"
};
-static const char *const *const aaPixmaps[] = { aa_rgb_xpm, aa_bgr_xpm, aa_vrgb_xpm, aa_vbgr_xpm };
+static const char *const *const aaPixmaps[] = { 0, 0, aa_rgb_xpm, aa_bgr_xpm, aa_vrgb_xpm, aa_vbgr_xpm };
/**** DLL Interface ****/
K_PLUGIN_FACTORY(FontFactory, registerPlugin<KFonts>();)
@@ -280,24 +280,24 @@ FontAASettings::FontAASettings(QWidget *parent)
" have a linear ordering of RGB sub-pixel, some have BGR.<br />"
" This feature does not work with CRT monitors.</p>");
- useSubPixel = new QCheckBox(i18n("&Use sub-pixel rendering:"), mw);
- useSubPixel->setWhatsThis(subPixelWhatsThis);
+ subPixelLabel = new QLabel(i18n("Sub-pixel rendering type: "), mw);
+ subPixelLabel->setWhatsThis(subPixelWhatsThis);
subPixelType = new QComboBox(mw);
- layout->addRow(useSubPixel, subPixelType);
+ layout->addRow(subPixelLabel, subPixelType);
subPixelType->setEditable(false);
subPixelType->setWhatsThis(subPixelWhatsThis);
- for (int t = KXftConfig::SubPixel::None + 1; t <= KXftConfig::SubPixel::Vbgr; ++t) {
- subPixelType->addItem(QPixmap(aaPixmaps[t - 1]), i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8()));
+ for (int t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t) {
+ subPixelType->addItem(QPixmap(aaPixmaps[t]), i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8()));
}
QLabel *hintingLabel = new QLabel(i18n("Hinting style: "), mw);
hintingStyle = new QComboBox(mw);
hintingStyle->setEditable(false);
layout->addRow(hintingLabel, hintingStyle);
- for (int s = KXftConfig::Hint::NotSet + 1; s <= KXftConfig::Hint::Full; ++s) {
+ for (int s = KXftConfig::Hint::NotSet; s <= KXftConfig::Hint::Full; ++s) {
hintingStyle->addItem(i18n(KXftConfig::description((KXftConfig::Hint::Style)s).toUtf8()));
}
@@ -309,7 +309,6 @@ FontAASettings::FontAASettings(QWidget *parent)
setMainWidget(mw);
connect(excludeRange, SIGNAL(toggled(bool)), SLOT(changed()));
- connect(useSubPixel, SIGNAL(toggled(bool)), SLOT(changed()));
connect(excludeFrom, SIGNAL(valueChanged(double)), SLOT(changed()));
connect(excludeTo, SIGNAL(valueChanged(double)), SLOT(changed()));
connect(subPixelType, SIGNAL(activated(QString)), SLOT(changed()));
@@ -334,27 +333,18 @@ bool FontAASettings::load()
KXftConfig::SubPixel::Type spType;
- if (!xft.getSubPixelType(spType) || KXftConfig::SubPixel::None == spType) {
- useSubPixel->setChecked(false);
- } else {
- int idx = getIndex(spType);
+ xft.getSubPixelType(spType);
+ int idx = getIndex(spType);
- if (idx > -1) {
- useSubPixel->setChecked(true);
- subPixelType->setCurrentIndex(idx);
- } else {
- useSubPixel->setChecked(false);
- }
- }
+ subPixelType->setCurrentIndex(idx);
KXftConfig::Hint::Style hStyle;
if (!xft.getHintStyle(hStyle) || KXftConfig::Hint::NotSet == hStyle) {
KConfig kglobals("kdeglobals", KConfig::NoGlobals);
- hStyle = KXftConfig::Hint::Medium;
+ hStyle = KXftConfig::Hint::NotSet;
xft.setHintStyle(hStyle);
- xft.apply(); // Save this setting
KConfigGroup(&kglobals, "General").writeEntry("XftHintStyle", KXftConfig::toStr(hStyle));
kglobals.sync();
runRdb(KRdbExportXftSettings | KRdbExportGtkTheme);
@@ -364,16 +354,16 @@ bool FontAASettings::load()
enableWidgets();
- return xft.getAntiAliasing();
+ return xft.aliasingEnabled();
}
-bool FontAASettings::save(bool useAA)
+bool FontAASettings::save(KXftConfig::AntiAliasing::State aaState)
{
KXftConfig xft;
KConfig kglobals("kdeglobals", KConfig::NoGlobals);
KConfigGroup grp(&kglobals, "General");
- xft.setAntiAliasing(useAA);
+ xft.setAntiAliasing(aaState);
if (excludeRange->isChecked()) {
xft.setExcludeRange(excludeFrom->value(), excludeTo->value());
@@ -381,13 +371,15 @@ bool FontAASettings::save(bool useAA)
xft.setExcludeRange(0, 0);
}
- KXftConfig::SubPixel::Type spType(useSubPixel->isChecked()
- ? getSubPixelType()
- : KXftConfig::SubPixel::None);
+ KXftConfig::SubPixel::Type spType(getSubPixelType());
xft.setSubPixelType(spType);
grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType));
- grp.writeEntry("XftAntialias", useAA);
+ if (KXftConfig::AntiAliasing::NotSet == aaState) {
+ grp.revertToDefault("XftAntialias");
+ } else {
+ grp.writeEntry("XftAntialias", aaState == KXftConfig::AntiAliasing::Enabled);
+ }
bool mod = false;
KXftConfig::Hint::Style hStyle(getHintStyle());
@@ -395,11 +387,14 @@ bool FontAASettings::save(bool useAA)
xft.setHintStyle(hStyle);
QString hs(KXftConfig::toStr(hStyle));
-
- if (!hs.isEmpty() && hs != grp.readEntry("XftHintStyle")) {
- grp.writeEntry("XftHintStyle", hs);
- mod = true;
+ if (hs != grp.readEntry("XftHintStyle")) {
+ if (KXftConfig::Hint::NotSet == hStyle) {
+ grp.revertToDefault("XftHintStyle");
+ } else {
+ grp.writeEntry("XftHintStyle", hs);
+ }
}
+ mod = true;
kglobals.sync();
if (!mod) {
@@ -416,8 +411,8 @@ void FontAASettings::defaults()
excludeRange->setChecked(false);
excludeFrom->setValue(8.0);
excludeTo->setValue(15.0);
- useSubPixel->setChecked(false);
- hintingStyle->setCurrentIndex(getIndex(KXftConfig::Hint::Medium));
+ subPixelType->setCurrentIndex(getIndex(KXftConfig::SubPixel::NotSet));
+ hintingStyle->setCurrentIndex(getIndex(KXftConfig::Hint::NotSet));
enableWidgets();
}
@@ -439,12 +434,12 @@ KXftConfig::SubPixel::Type FontAASettings::getSubPixelType()
{
int t;
- for (t = KXftConfig::SubPixel::None; t <= KXftConfig::SubPixel::Vbgr; ++t)
+ for (t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t)
if (subPixelType->currentText() == i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8())) {
return (KXftConfig::SubPixel::Type)t;
}
- return KXftConfig::SubPixel::None;
+ return KXftConfig::SubPixel::NotSet;
}
int FontAASettings::getIndex(KXftConfig::Hint::Style hStyle)
@@ -478,7 +473,6 @@ void FontAASettings::enableWidgets()
excludeFrom->setEnabled(excludeRange->isChecked());
excludeTo->setEnabled(excludeRange->isChecked());
excludeToLabel->setEnabled(excludeRange->isChecked());
- subPixelType->setEnabled(useSubPixel->isChecked());
#ifdef FT_LCD_FILTER_H
static int ft_has_subpixel = -1;
if (ft_has_subpixel == -1) {
@@ -489,7 +483,6 @@ void FontAASettings::enableWidgets()
FT_Done_FreeType(ftLibrary);
}
}
- useSubPixel->setEnabled(ft_has_subpixel);
subPixelType->setEnabled(ft_has_subpixel);
#endif
}
@@ -803,8 +796,15 @@ void KFonts::save()
// TODO: With AASystem the changes already made by this module should be reverted somehow.
#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11)
bool aaSave = false;
- if (cbAA->currentIndex() != AASystem) {
- aaSave = aaSettings->save(useAA == AAEnabled);
+ if (cbAA->currentIndex() == AAEnabled ) {
+ aaSave = aaSettings->save(KXftConfig::AntiAliasing::Enabled);
+ } else if (cbAA->currentIndex() == AADisabled) {
+ aaSave = aaSettings->save(KXftConfig::AntiAliasing::Disabled);
+ } else {
+ // If AASystem is selected, this removes all fontconfig settings made by
+ // this module.
+ aaSettings->defaults();
+ aaSave = aaSettings->save(KXftConfig::AntiAliasing::NotSet);
}
if (aaSave || (useAA != useAA_original) || dpi != dpi_original) {
diff --git a/kcms/fonts/fonts.h b/kcms/fonts/fonts.h
index 5b9f5d8..c5141be 100644
--- a/kcms/fonts/fonts.h
+++ b/kcms/fonts/fonts.h
@@ -82,13 +82,14 @@ public:
#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11)
FontAASettings(QWidget *parent);
- bool save(bool useAA);
+ bool save(KXftConfig::AntiAliasing::State aaState);
bool load();
void defaults();
int getIndex(KXftConfig::SubPixel::Type spType);
KXftConfig::SubPixel::Type getSubPixelType();
int getIndex(KXftConfig::Hint::Style hStyle);
KXftConfig::Hint::Style getHintStyle();
+ void setAntiAliasingState(KXftConfig::AntiAliasing::State aaState);
void enableWidgets();
int exec();
#endif
@@ -101,11 +102,11 @@ protected Q_SLOTS:
private:
QCheckBox *excludeRange;
- QCheckBox *useSubPixel;
KDoubleNumInput *excludeFrom;
KDoubleNumInput *excludeTo;
QComboBox *subPixelType;
QComboBox *hintingStyle;
+ QLabel *subPixelLabel;
QLabel *excludeToLabel;
bool changesMade;
#endif
diff --git a/kcms/fonts/kxftconfig.cpp b/kcms/fonts/kxftconfig.cpp
index 6f3465f..2cc3a1b 100644
--- a/kcms/fonts/kxftconfig.cpp
+++ b/kcms/fonts/kxftconfig.cpp
@@ -206,8 +206,10 @@ static KXftConfig::SubPixel::Type strToType(const char *str)
return KXftConfig::SubPixel::Vrgb;
} else if (0 == strcmp(str, "vbgr")) {
return KXftConfig::SubPixel::Vbgr;
- } else {
+ } else if (0 == strcmp(str, "none")) {
return KXftConfig::SubPixel::None;
+ } else {
+ return KXftConfig::SubPixel::NotSet;
}
}
@@ -229,7 +231,6 @@ KXftConfig::KXftConfig()
, m_file(getConfigFile())
{
kDebug(1208) << "Using fontconfig file:" << m_file;
- m_antiAliasing = aliasingEnabled();
reset();
}
@@ -247,6 +248,7 @@ bool KXftConfig::reset()
m_excludeRange.reset();
m_excludePixelRange.reset();
m_subPixel.reset();
+ m_antiAliasing.reset();
QFile f(m_file);
@@ -279,14 +281,12 @@ bool KXftConfig::reset()
m_excludePixelRange.from = pFrom;
m_excludePixelRange.to = pTo;
m_madeChanges = true;
- apply();
}
} else if (!equal(0, m_excludePixelRange.from) || !equal(0, m_excludePixelRange.to)) {
// "pixelsize" set, but not "size" !!!
m_excludeRange.from = (int)pixel2Point(m_excludePixelRange.from);
m_excludeRange.to = (int)pixel2Point(m_excludePixelRange.to);
m_madeChanges = true;
- apply();
}
}
@@ -307,7 +307,7 @@ bool KXftConfig::apply()
newConfig.setExcludeRange(m_excludeRange.from, m_excludeRange.to);
newConfig.setSubPixelType(m_subPixel.type);
newConfig.setHintStyle(m_hint.style);
- newConfig.setAntiAliasing(m_antiAliasing.set);
+ newConfig.setAntiAliasing(m_antiAliasing.state);
ok = newConfig.changed() ? newConfig.apply() : true;
if (ok) {
@@ -450,6 +450,8 @@ QString KXftConfig::description(SubPixel::Type t)
{
switch (t) {
default:
+ case SubPixel::NotSet:
+ return i18nc("use system subpixel setting", "System default");
case SubPixel::None:
return i18nc("no subpixel rendering", "None");
case SubPixel::Rgb:
@@ -484,10 +486,10 @@ QString KXftConfig::description(Hint::Style s)
{
switch (s) {
default:
+ case Hint::NotSet:
+ return i18nc("use system hinting settings", "System default");
case Hint::Medium:
return i18nc("medium hinting", "Medium");
- case Hint::NotSet:
- return "";
case Hint::None:
return i18nc("no hinting", "None");
case Hint::Slight:
@@ -501,6 +503,8 @@ const char *KXftConfig::toStr(Hint::Style s)
{
switch (s) {
default:
+ case Hint::NotSet:
+ return "";
case Hint::Medium:
return "hintmedium";
case Hint::None:
@@ -544,7 +548,8 @@ void KXftConfig::readContents()
} else if (!(str = getEntry(ene, "bool", 2, "name", "antialias", "mode",
"assign")).isNull()) {
m_antiAliasing.node = n;
- m_antiAliasing.set = str.toLower() != "false";
+ m_antiAliasing.state = str.toLower() != "false" ?
+ AntiAliasing::Enabled : AntiAliasing::Disabled;
}
}
}
@@ -633,34 +638,45 @@ void KXftConfig::readContents()
void KXftConfig::applySubPixelType()
{
- QDomElement matchNode = m_doc.createElement("match"),
- typeNode = m_doc.createElement("const"),
- editNode = m_doc.createElement("edit");
- QDomText typeText = m_doc.createTextNode(toStr(m_subPixel.type));
-
- matchNode.setAttribute("target", "font");
- editNode.setAttribute("mode", "assign");
- editNode.setAttribute("name", "rgba");
- editNode.appendChild(typeNode);
- typeNode.appendChild(typeText);
- matchNode.appendChild(editNode);
- if (m_subPixel.node.isNull()) {
- m_doc.documentElement().appendChild(matchNode);
+ if (SubPixel::NotSet == m_subPixel.type) {
+ if (!m_subPixel.node.isNull()) {
+ m_doc.documentElement().removeChild(m_subPixel.node);
+ m_subPixel.node.clear();
+ }
} else {
- m_doc.documentElement().replaceChild(matchNode, m_subPixel.node);
+ QDomElement matchNode = m_doc.createElement("match");
+ QDomElement typeNode = m_doc.createElement("const");
+ QDomElement editNode = m_doc.createElement("edit");
+ QDomText typeText = m_doc.createTextNode(toStr(m_subPixel.type));
+
+ matchNode.setAttribute("target", "font");
+ editNode.setAttribute("mode", "assign");
+ editNode.setAttribute("name", "rgba");
+ editNode.appendChild(typeNode);
+ typeNode.appendChild(typeText);
+ matchNode.appendChild(editNode);
+ if (m_subPixel.node.isNull()) {
+ m_doc.documentElement().appendChild(matchNode);
+ } else {
+ m_doc.documentElement().replaceChild(matchNode, m_subPixel.node);
+ }
+ m_subPixel.node = matchNode;
}
- m_subPixel.node = matchNode;
}
void KXftConfig::applyHintStyle()
{
applyHinting();
- if (Hint::NotSet == m_hint.style || m_hint.toBeRemoved) {
+ if (Hint::NotSet == m_hint.style) {
if (!m_hint.node.isNull()) {
m_doc.documentElement().removeChild(m_hint.node);
m_hint.node.clear();
}
+ if (!m_hinting.node.isNull()) {
+ m_doc.documentElement().removeChild(m_hinting.node);
+ m_hinting.node.clear();
+ }
} else {
QDomElement matchNode = m_doc.createElement("match"),
typeNode = m_doc.createElement("const"),
@@ -757,37 +773,45 @@ void KXftConfig::applyExcludeRange(bool pixel)
}
}
-bool KXftConfig::getAntiAliasing() const
+KXftConfig::AntiAliasing::State KXftConfig::getAntiAliasing() const
{
- return m_antiAliasing.set;
+ return m_antiAliasing.state;
}
-void KXftConfig::setAntiAliasing(bool set)
+void KXftConfig::setAntiAliasing(AntiAliasing::State state)
{
- if (set != m_antiAliasing.set) {
- m_antiAliasing.set = set;
+ if (state != m_antiAliasing.state) {
+ m_antiAliasing.state = state;
m_madeChanges = true;
}
}
void KXftConfig::applyAntiAliasing()
{
- QDomElement matchNode = m_doc.createElement("match"),
- typeNode = m_doc.createElement("bool"),
- editNode = m_doc.createElement("edit");
- QDomText typeText = m_doc.createTextNode(m_antiAliasing.set ? "true" : "false");
+ if (AntiAliasing::NotSet == m_antiAliasing.state) {
+ if (!m_antiAliasing.node.isNull()) {
+ m_doc.documentElement().removeChild(m_antiAliasing.node);
+ m_antiAliasing.node.clear();
+ }
+ } else {
+ QDomElement matchNode = m_doc.createElement("match");
+ QDomElement typeNode = m_doc.createElement("bool");
+ QDomElement editNode = m_doc.createElement("edit");
+ QDomText typeText = m_doc.createTextNode(m_antiAliasing.state == AntiAliasing::Enabled ?
+ "true" : "false");
- matchNode.setAttribute("target", "font");
- editNode.setAttribute("mode", "assign");
- editNode.setAttribute("name", "antialias");
- editNode.appendChild(typeNode);
- typeNode.appendChild(typeText);
- matchNode.appendChild(editNode);
- if (!m_antiAliasing.node.isNull()) {
- m_doc.documentElement().removeChild(m_antiAliasing.node);
+ matchNode.setAttribute("target", "font");
+ editNode.setAttribute("mode", "assign");
+ editNode.setAttribute("name", "antialias");
+ editNode.appendChild(typeNode);
+ typeNode.appendChild(typeText);
+ matchNode.appendChild(editNode);
+ if (!m_antiAliasing.node.isNull()) {
+ m_doc.documentElement().removeChild(m_antiAliasing.node);
+ }
+ m_doc.documentElement().appendChild(matchNode);
+ m_antiAliasing.node = matchNode;
}
- m_doc.documentElement().appendChild(matchNode);
- m_antiAliasing.node = matchNode;
}
// KXftConfig only parses one config file, user's .fonts.conf usually.
diff --git a/kcms/fonts/kxftconfig.h b/kcms/fonts/kxftconfig.h
index 9efa9f5..3d5bed0 100644
--- a/kcms/fonts/kxftconfig.h
+++ b/kcms/fonts/kxftconfig.h
@@ -54,6 +54,7 @@ public:
struct SubPixel : public Item {
enum Type {
+ NotSet,
None,
Rgb,
Bgr,
@@ -62,12 +63,12 @@ public:
};
SubPixel(Type t, QDomNode &n) : Item(n), type(t) {}
- SubPixel(Type t = None) : type(t) {}
+ SubPixel(Type t = NotSet) : type(t) {}
void reset()
{
Item::reset();
- type = None;
+ type = NotSet;
}
Type type;
@@ -122,16 +123,22 @@ public:
};
struct AntiAliasing : public Item {
- AntiAliasing(bool s, QDomNode &n) : Item(n), set(s) {}
- AntiAliasing(bool s = true) : set(s) {}
+ enum State {
+ NotSet,
+ Enabled,
+ Disabled
+ };
+
+ AntiAliasing(State s, QDomNode &n) : Item(n), state(s) {}
+ AntiAliasing(State s = NotSet) : state(s) {}
void reset()
{
Item::reset();
- set = true;
+ state = NotSet;
}
- bool set;
+ enum State state;
};
public:
@@ -148,8 +155,8 @@ public:
void setExcludeRange(double from, double to); // from:0, to:0 => turn off exclude range
bool getHintStyle(Hint::Style &style);
void setHintStyle(Hint::Style style);
- void setAntiAliasing(bool set);
- bool getAntiAliasing() const;
+ void setAntiAliasing(AntiAliasing::State state);
+ AntiAliasing::State getAntiAliasing() const;
bool changed()
{
return m_madeChanges;
@@ -158,6 +165,7 @@ public:
static const char *toStr(SubPixel::Type t);
static QString description(Hint::Style s);
static const char *toStr(Hint::Style s);
+ bool aliasingEnabled();
private:
@@ -168,7 +176,6 @@ private:
void setHinting(bool set);
void applyHinting();
void applyExcludeRange(bool pixel);
- bool aliasingEnabled();
private:
--
2.1.0