diff --git a/kcms/fonts/fonts.cpp b/kcms/fonts/fonts.cpp --- a/kcms/fonts/fonts.cpp +++ b/kcms/fonts/fonts.cpp @@ -103,7 +103,27 @@ if (dbase.isSmoothlyScalable(family, style) && result.pointSize() == floor(size)) { result.setPointSizeF(size); } - return result; + + bool sameFont = font.toString() == result.toString(); + // A "Regular" font will have an empty styleName e.g. "DejaVu Sans,12,-1,5,50,0,0,0,0,0" + // so that setBold(true) can work (we deliberately clear the styleName for "Regular"-like + // font styles when saving via KConfig, see: writeEntryGui() from kconfiggroupgui.cpp). + // Here in this method we could end up with a "result" font that's using a Regular style + // and that has the styleName set, so the the original "font" param. and "result" are + // actually the same font + if (!sameFont) { + if (font.weight() == QFont::Normal && font.styleName().isEmpty() + && result.weight() == QFont::Normal + && (result.styleName() == QLatin1String("Regular") + || result.styleName() == QLatin1String("Normal") + || result.styleName() == QLatin1String("Book") + || result.styleName() == QLatin1String("Roman"))) { + result.setStyleName(QString()); + sameFont = font.toString() == result.toString(); + } + } + + return sameFont ? font : result; } /**** FontAASettings ****/ @@ -549,12 +569,35 @@ void KFonts::setNearestExistingFonts() { - m_settings->setFont(nearestExistingFont(m_settings->font())); - m_settings->setFixed(nearestExistingFont(m_settings->fixed())); - m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); - m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); - m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); - m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); + const QFont font = nearestExistingFont(m_settings->font()); + if (m_settings->font() != font) { + m_settings->setFont(font); + } + + const QFont fixed = nearestExistingFont(m_settings->fixed()); + if (m_settings->fixed() != fixed) { + m_settings->setFixed(fixed); + } + + const QFont smallest = nearestExistingFont(m_settings->smallestReadableFont()); + if (m_settings->smallestReadableFont() != smallest) { + m_settings->setSmallestReadableFont(smallest); + } + + const QFont toolBar = nearestExistingFont(m_settings->toolBarFont()); + if (m_settings->toolBarFont() != toolBar) { + m_settings->setToolBarFont(toolBar); + } + + const QFont menu = nearestExistingFont(m_settings->menuFont()); + if (m_settings->menuFont() != menu) { + m_settings->setMenuFont(menu); + } + + const QFont active = nearestExistingFont(m_settings->activeFont()); + if (m_settings->activeFont() != active) { + m_settings->setActiveFont(active); + } } void KFonts::load() @@ -571,9 +614,6 @@ // otherwise AA settings will be reset in process of loading // previews engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); - - // KCM expect save state to be false at this point (can be true because of setNearestExistingFonts - setNeedsSave(false); } void KFonts::save()