File kcm-fix-105797-fontconfig.patch of Package kdebase4-workspace

diff --git a/kcontrol/fonts/fonts.cpp b/kcontrol/fonts/fonts.cpp
index 67eccd4..5da6722 100644
--- a/kcontrol/fonts/fonts.cpp
+++ b/kcontrol/fonts/fonts.cpp
@@ -131,7 +131,7 @@ static const char * const aa_vbgr_xpm[]={
 "aaaaaaaaaaaa",
 "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>(); )
@@ -258,23 +258,23 @@ 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()));
 
   QString hintingText(i18n("Hinting is a process used to enhance the quality of fonts at small sizes."));
@@ -285,7 +285,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()));
@@ -311,20 +310,10 @@ 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;
 
@@ -332,9 +321,8 @@ bool FontAASettings::load()
   {
     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);
@@ -344,29 +332,33 @@ 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());
   else
     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());
@@ -374,12 +366,17 @@ 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)
@@ -395,8 +392,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();
 }
 
@@ -419,11 +416,11 @@ 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)
@@ -458,7 +455,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 ) {
@@ -469,7 +465,6 @@ void FontAASettings::enableWidgets()
       FT_Done_FreeType(ftLibrary);
     }
   }
-  useSubPixel->setEnabled(ft_has_subpixel);
   subPixelType->setEnabled(ft_has_subpixel);
 #endif
 }
@@ -787,8 +782,21 @@ void KFonts::save()
   // TODO: With AASystem the changes already made by this module should be reverted somehow.
 #if defined(HAVE_FONTCONFIG) && defined (Q_WS_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) {
     KMessageBox::information(this,
diff --git a/kcontrol/fonts/fonts.h b/kcontrol/fonts/fonts.h
index e98d060..95d70e0 100644
--- a/kcontrol/fonts/fonts.h
+++ b/kcontrol/fonts/fonts.h
@@ -57,13 +57,14 @@ public:
 #if defined(HAVE_FONTCONFIG) && defined (Q_WS_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
@@ -76,11 +77,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/kcontrol/fonts/kxftconfig.cpp b/kcontrol/fonts/kxftconfig.cpp
index 410bf01..d5cd3a8 100644
--- a/kcontrol/fonts/kxftconfig.cpp
+++ b/kcontrol/fonts/kxftconfig.cpp
@@ -209,8 +209,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;
 }
 
 static KXftConfig::Hint::Style strToStyle(const char *str)
@@ -230,7 +232,6 @@ KXftConfig::KXftConfig()
           , m_file(getConfigFile())
 {
     kDebug(1208) << "Using fontconfig file:" << m_file;
-    m_antiAliasing = aliasingEnabled();
     reset();
 }
 
@@ -248,6 +249,7 @@ bool KXftConfig::reset()
     m_excludeRange.reset();
     m_excludePixelRange.reset();
     m_subPixel.reset();
+    m_antiAliasing.reset();
 
     QFile f(m_file);
 
@@ -282,7 +284,6 @@ 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))   
@@ -291,7 +292,6 @@ bool KXftConfig::reset()
             m_excludeRange.from=(int)pixel2Point(m_excludePixelRange.from);
             m_excludeRange.to=(int)pixel2Point(m_excludePixelRange.to);
             m_madeChanges=true;
-            apply();
         }
     }
 
@@ -314,7 +314,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)
@@ -467,6 +467,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:
@@ -503,10 +505,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:
@@ -521,10 +523,12 @@ const char * KXftConfig::toStr(Hint::Style s)
     switch(s)
     {
         default:
-        case Hint::Medium:
-            return "hintmedium";
+        case Hint::NotSet:
+            return "";
         case Hint::None:
             return "hintnone";
+        case Hint::Medium:
+            return "hintmedium";
         case Hint::Slight:
             return "hintslight";
         case Hint::Full:
@@ -577,7 +581,7 @@ void KXftConfig::readContents()
                                                        "assign")).isNull())
                                 {
                                     m_antiAliasing.node=n;
-                                    m_antiAliasing.set=str.toLower()!="false";
+                                    m_antiAliasing.state = str.toLower() != "false" ? AntiAliasing::Enabled : AntiAliasing::Disabled;
                                 }
                             }
                         }
@@ -665,35 +669,51 @@ 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);
-    m_subPixel.node=matchNode;
+    {
+        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;
+    }
 }
 
 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
     {
@@ -793,37 +813,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)
+    if (state != m_antiAliasing.state)
     {
-        m_antiAliasing.set = set;
+        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);
-    m_doc.documentElement().appendChild(matchNode);
-    m_antiAliasing.node=matchNode;
+        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;
+    }
 }
 
 // KXftConfig only parses one config file, user's .fonts.conf usually.
diff --git a/kcontrol/fonts/kxftconfig.h b/kcontrol/fonts/kxftconfig.h
index 0df6164..9cba20b 100644
--- a/kcontrol/fonts/kxftconfig.h
+++ b/kcontrol/fonts/kxftconfig.h
@@ -50,6 +50,7 @@ class KXftConfig
     {
         enum Type
         {
+            NotSet,
             None,
             Rgb,
             Bgr,
@@ -58,9 +59,9 @@ class KXftConfig
         };
 
         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; }
+        void reset() { Item::reset(); type=NotSet; }
 
         Type type;
     };
@@ -107,12 +108,20 @@ class KXftConfig
 
     struct AntiAliasing : public Item
     {
-        AntiAliasing(bool s, QDomNode &n) : Item(n), set(s) {}
-        AntiAliasing(bool s=true)         : set(s)          {}
+        enum State
+        {
+            NotSet,
+            Enabled,
+            Disabled
+        };
 
-        void reset() { Item::reset(); set=true; }
+        AntiAliasing(State s, QDomNode &n) : Item(n), state(s) {}
+        AntiAliasing(State s = NotSet) : state(s) {}
+        AntiAliasing(bool aaEnabled) : state(aaEnabled ? Enabled : Disabled) {}
 
-        bool set;
+        void reset() { Item::reset(); state = NotSet; }
+
+        enum State state;
     };
 
     public:
@@ -129,13 +138,14 @@ class KXftConfig
     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; }
     static QString description(SubPixel::Type t);
     static const char * toStr(SubPixel::Type t);
     static QString description(Hint::Style s);
     static const char * toStr(Hint::Style s);
+    bool        aliasingEnabled();
 
     private:
 
@@ -146,7 +156,6 @@ class KXftConfig
     void        setHinting(bool set);
     void        applyHinting();
     void        applyExcludeRange(bool pixel);
-    bool        aliasingEnabled();
 
     private:
 
openSUSE Build Service is sponsored by