diff --git a/kcms/fonts/fonts.h b/kcms/fonts/fonts.h --- a/kcms/fonts/fonts.h +++ b/kcms/fonts/fonts.h @@ -97,6 +97,7 @@ #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) private: + bool m_excludeOriginal; int m_excludeTo; int m_excludeToOriginal; int m_excludeFrom; diff --git a/kcms/fonts/fonts.cpp b/kcms/fonts/fonts.cpp --- a/kcms/fonts/fonts.cpp +++ b/kcms/fonts/fonts.cpp @@ -137,6 +137,7 @@ m_excludeTo = 15; setExclude(false); } + m_excludeOriginal = m_exclude; m_excludeFromOriginal = m_excludeFrom; m_excludeToOriginal = m_excludeTo; excludeToChanged(); @@ -421,7 +422,8 @@ bool FontAASettings::needsSave() const { - return m_excludeTo != m_excludeToOriginal + return m_exclude != m_excludeOriginal + || m_excludeTo != m_excludeToOriginal || m_excludeFrom != m_excludeFromOriginal || m_antiAliasing != m_antiAliasingOriginal || m_dpi != m_dpiOriginal @@ -450,6 +452,8 @@ connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); + connect(m_fontAASettings, &FontAASettings::excludeChanged, this, updateState); + connect(m_fontAASettings, &FontAASettings::excludeFromChanged, this, updateState); connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); diff --git a/kcms/fonts/kxftconfig.h b/kcms/fonts/kxftconfig.h --- a/kcms/fonts/kxftconfig.h +++ b/kcms/fonts/kxftconfig.h @@ -27,6 +27,7 @@ #include #include +#include class KXftConfig { @@ -168,15 +169,19 @@ private: + bool parseConfigFile(const QString& filename); void readContents(); void applySubPixelType(); void applyHintStyle(); void applyAntiAliasing(); void setHinting(bool set); void applyHinting(); void applyExcludeRange(bool pixel); + QString getConfigFile(); private: + + QStringList m_globalFiles; SubPixel m_subPixel; Exclude m_excludeRange, diff --git a/kcms/fonts/kxftconfig.cpp b/kcms/fonts/kxftconfig.cpp --- a/kcms/fonts/kxftconfig.cpp +++ b/kcms/fonts/kxftconfig.cpp @@ -117,49 +117,6 @@ return !item.isNull() && 0 == KDE_lstat(QFile::encodeName(item), &info) ? info.st_mtime : 0; } -// -// Obtain location of config file to use. -QString getConfigFile() -{ - FcStrList *list = FcConfigGetConfigFiles(FcConfigGetCurrent()); - QStringList files; - FcChar8 *file; - QString home(dirSyntax(QDir::homePath())); - - while ((file = FcStrListNext(list))) { - QString f((const char *)file); - - if (fExists(f) && 0 == f.indexOf(home)) { - files.append(f); - } - } - FcStrListDone(list); - - // - // Go through list of files, looking for the preferred one... - if (files.count()) { - QStringList::const_iterator it(files.begin()), - end(files.end()); - - for (; it != end; ++it) - if (-1 != (*it).indexOf(QRegExp("/\\.?fonts\\.conf$"))) { - return *it; - } - return files.front(); // Just return the 1st one... - } else { // Hmmm... no known files? - if (FcGetVersion() >= 21000) { - QString targetPath(KGlobal::dirs()->localxdgconfdir() + "fontconfig"); - QDir target(targetPath); - if (!target.exists()) { - target.mkpath(targetPath); - } - return targetPath + "/fonts.conf"; - } else { - return home + "/.fonts.conf"; - } - } -} - static QString getEntry(QDomElement element, const char *type, unsigned int numAttributes, ...) { if (numAttributes == element.attributes().length()) { @@ -238,6 +195,53 @@ { } +// +// Obtain location of config file to use. +QString KXftConfig::getConfigFile() +{ + FcStrList *list = FcConfigGetConfigFiles(FcConfigGetCurrent()); + QStringList localFiles; + FcChar8 *file; + QString home(dirSyntax(QDir::homePath())); + + m_globalFiles.clear(); + + while ((file = FcStrListNext(list))) { + QString f((const char *)file); + + if (fExists(f) && 0 == f.indexOf(home)) { + localFiles.append(f); + } else { + m_globalFiles.append(f); + } + } + FcStrListDone(list); + + // + // Go through list of localFiles, looking for the preferred one... + if (localFiles.count()) { + QStringList::const_iterator it(localFiles.begin()), + end(localFiles.end()); + + for (; it != end; ++it) + if (-1 != (*it).indexOf(QRegExp("/\\.?fonts\\.conf$"))) { + return *it; + } + return localFiles.front(); // Just return the 1st one... + } else { // Hmmm... no known localFiles? + if (FcGetVersion() >= 21000) { + QString targetPath(KGlobal::dirs()->localxdgconfdir() + "fontconfig"); + QDir target(targetPath); + if (!target.exists()) { + target.mkpath(targetPath); + } + return targetPath + "/fonts.conf"; + } else { + return home + "/.fonts.conf"; + } + } +} + bool KXftConfig::reset() { bool ok = false; @@ -250,45 +254,12 @@ m_subPixel.reset(); m_antiAliasing.reset(); - QFile f(m_file); - - if (f.open(QIODevice::ReadOnly)) { - m_time = getTimeStamp(m_file); - ok = true; - m_doc.clear(); - - if (m_doc.setContent(&f)) { - readContents(); - } - f.close(); - } else { - ok = !fExists(m_file) && dWritable(getDir(m_file)); - } - - if (m_doc.documentElement().isNull()) { - m_doc.appendChild(m_doc.createElement("fontconfig")); - } - - if (ok) { - // - // Check exclude range values - i.e. size and pixel size... - // If "size" range is set, ensure "pixelsize" matches... - if (!equal(0, m_excludeRange.from) || !equal(0, m_excludeRange.to)) { - double pFrom = (double)point2Pixel(m_excludeRange.from), - pTo = (double)point2Pixel(m_excludeRange.to); - - if (!equal(pFrom, m_excludePixelRange.from) || !equal(pTo, m_excludePixelRange.to)) { - m_excludePixelRange.from = pFrom; - m_excludePixelRange.to = pTo; - m_madeChanges = true; - } - } 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; - } + QStringList::const_iterator it(m_globalFiles.begin()), + end(m_globalFiles.end()); + for (; it != end; ++it) { + ok |= parseConfigFile(*it); } + ok |= parseConfigFile(m_file); return ok; } @@ -518,48 +489,129 @@ } } +bool KXftConfig::parseConfigFile(const QString& filename) +{ + bool ok = false; + + QFile f(filename); + + if (f.open(QIODevice::ReadOnly)) { + m_time = getTimeStamp(filename); + ok = true; + m_doc.clear(); + + if (m_doc.setContent(&f)) { + qDebug() << f; + readContents(); + } + f.close(); + } else { + ok = !fExists(filename) && dWritable(getDir(filename)); + } + + if (m_doc.documentElement().isNull()) { + m_doc.appendChild(m_doc.createElement("fontconfig")); + } + + if (ok) { + // + // Check exclude range values - i.e. size and pixel size... + // If "size" range is set, ensure "pixelsize" matches... + if (!equal(0, m_excludeRange.from) || !equal(0, m_excludeRange.to)) { + double pFrom = (double)point2Pixel(m_excludeRange.from), + pTo = (double)point2Pixel(m_excludeRange.to); + + if (!equal(pFrom, m_excludePixelRange.from) || !equal(pTo, m_excludePixelRange.to)) { + m_excludePixelRange.from = pFrom; + m_excludePixelRange.to = pTo; + m_madeChanges = true; + } + } 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; + } + } + + return ok; +} + void KXftConfig::readContents() { QDomNode n = m_doc.documentElement().firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); - + if (!e.isNull()) { if ("match" == e.tagName()) { QString str; + + int childNodesCount = e.childNodes().count(); + QDomNode en = e.firstChild(); + while (!en.isNull()) { + if (en.isComment()) { + childNodesCount--; + } + en = en.nextSibling(); + } - switch (e.childNodes().count()) { + switch (childNodesCount) { case 1: - if ("font" == e.attribute("target")) { - QDomElement ene = e.firstChild().toElement(); - - if (!ene.isNull() && "edit" == ene.tagName()) { - if (!(str = getEntry(ene, "const", 2, "name", "rgba", "mode", - "assign")).isNull()) { - m_subPixel.node = n; - m_subPixel.type = strToType(str.toLatin1()); - } else if (!(str = getEntry(ene, "const", 2, "name", "hintstyle", "mode", - "assign")).isNull()) { - m_hint.node = n; - m_hint.style = strToStyle(str.toLatin1()); - } else if (!(str = getEntry(ene, "bool", 2, "name", "hinting", "mode", - "assign")).isNull()) { - m_hinting.node = n; - m_hinting.set = str.toLower() != "false"; - } else if (!(str = getEntry(ene, "bool", 2, "name", "antialias", "mode", - "assign")).isNull()) { - m_antiAliasing.node = n; - m_antiAliasing.state = str.toLower() != "false" ? - AntiAliasing::Enabled : AntiAliasing::Disabled; + if ("font" == e.attribute("target") || "pattern" == e.attribute("target")) { + QDomNode en = e.firstChild(); + while (!en.isNull()) { + QDomElement ene = en.toElement(); + + while (ene.isComment()) { + ene = ene.nextSiblingElement(); } + qDebug() << ene.nodeName(); + + if (!ene.isNull() && "edit" == ene.tagName()) { + if (!(str = getEntry(ene, "const", 2, "name", "rgba", "mode", + "assign")).isNull() + || (m_subPixel.type == SubPixel::NotSet && !(str = getEntry(ene, "const", 2, "name", "rgba", "mode", + "append")).isNull())) { + qDebug() << "setting subpixel"; + m_subPixel.node = n; + m_subPixel.type = strToType(str.toLatin1()); + } else if (!(str = getEntry(ene, "const", 2, "name", "hintstyle", "mode", + "assign")).isNull() + || (m_hint.style == Hint::NotSet && !(str = getEntry(ene, "const", 2, "name", "hintstyle", "mode", + "append")).isNull())) { + qDebug() << "setting hinting"; + m_hint.node = n; + m_hint.style = strToStyle(str.toLatin1()); + } else if (!(str = getEntry(ene, "bool", 2, "name", "hinting", "mode", + "assign")).isNull()) { + qDebug() << "setting hinting"; + m_hinting.node = n; + m_hinting.set = str.toLower() != "false"; + } else if (!(str = getEntry(ene, "bool", 2, "name", "antialias", "mode", + "assign")).isNull() + || (m_antiAliasing.state == AntiAliasing::NotSet && !(str = getEntry(ene, "bool", 2, "name", "antialias", "mode", + "append")).isNull())) { + qDebug() << "setting antialias"; + m_antiAliasing.node = n; + m_antiAliasing.state = str.toLower() != "false" ? + AntiAliasing::Enabled : AntiAliasing::Disabled; + } + } + + en = en.nextSibling(); } } break; case 3: // CPD: Is target "font" or "pattern" ???? + qDebug() << "3 childs"; if ("font" == e.attribute("target")) { bool foundFalse = false; QDomNode en = e.firstChild(); + while (en.isComment()) { + en = en.nextSibling(); + } QString family; double from = -1.0, to = -1.0, diff --git a/kcms/fonts/package/contents/ui/main.qml b/kcms/fonts/package/contents/ui/main.qml --- a/kcms/fonts/package/contents/ui/main.qml +++ b/kcms/fonts/package/contents/ui/main.qml @@ -98,26 +98,16 @@ QtControls.ButtonGroup { id: antiAliasingGroup } - QtControls.RadioButton { - Kirigami.FormData.label: i18n("Anti-Aliasing:") - text: "Vendor Default" - QtControls.ButtonGroup.group: antiAliasingGroup - onCheckedChanged: { - if(checked) { - kcm.fontAASettings.antiAliasing = 1 - } - } - checked: kcm.fontAASettings.antiAliasing == 1 - } QtControls.RadioButton { text: "Enabled" + Kirigami.FormData.label: i18n("Anti-Aliasing:") QtControls.ButtonGroup.group: antiAliasingGroup onCheckedChanged: { if(checked) { kcm.fontAASettings.antiAliasing = 0 } } - checked: kcm.fontAASettings.antiAliasing == 0 + checked: kcm.fontAASettings.antiAliasing == 0 || kcm.fontAASettings.antiAliasing == 1 } RowLayout { QtControls.RadioButton{