diff --git a/platformthemeplugin/qdeepintheme.cpp b/platformthemeplugin/qdeepintheme.cpp index 7af14492..b3862509 100644 --- a/platformthemeplugin/qdeepintheme.cpp +++ b/platformthemeplugin/qdeepintheme.cpp @@ -656,6 +656,14 @@ const QPalette *QDeepinTheme::palette(QPlatformTheme::Palette type) const return &palette; } +static QFont *createUnresolveFont(const QString &family, qreal pointSize) +{ + auto font = new QFont(family); + font->setPointSizeF(pointSize); + setResolveMask(*font, QFont::NoPropertiesResolved); + return font; +} + const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const { if (!qApp->desktopSettingsAware()) @@ -667,12 +675,16 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const QByteArray font_name = theme->fontName(); qreal font_size = 0; + static QScopedPointer sysFont; if (font_name.isEmpty()) { font_name = theme->gtkFontName(); int font_size_index = font_name.lastIndexOf(' '); - if (font_size_index <= 0) - break; + if (font_size_index <= 0) { + const QFont *defaultFont = QGenericUnixTheme::font(type); + sysFont.reset(createUnresolveFont(defaultFont->family(), defaultFont->pointSizeF())); + return sysFont.data(); + } font_size = font_name.mid(font_size_index + 1).toDouble(); font_name = font_name.left(font_size_index); @@ -684,13 +696,8 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const font_size = 10.5; } - static QScopedPointer sysFont; - // We need to re-contruct a new QFont each time, inorder to refresh font dpi - sysFont.reset(new QFont(QString())); - sysFont->setFamily(font_name); - sysFont->setPointSizeF(font_size); - setResolveMask(*sysFont, QFont::NoPropertiesResolved); + sysFont.reset(createUnresolveFont(font_name, font_size)); return sysFont.data(); } @@ -700,8 +707,11 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const if (DPlatformTheme *theme = appTheme()) { QByteArray font_name = theme->monoFontName(); + static QScopedPointer fixedFont; if (font_name.isEmpty()) { - break; + const QFont *defaultFont = QGenericUnixTheme::font(type); + fixedFont.reset(createUnresolveFont(defaultFont->family(), defaultFont->pointSizeF())); + return fixedFont.data(); } qreal font_size = theme->fontPointSize(); @@ -710,13 +720,8 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const font_size = 10.5; } - static QScopedPointer fixedFont; - // We need to re-contruct a new QFont each time, inorder to refresh font dpi - fixedFont.reset(new QFont(QString())); - fixedFont->setFamily(font_name); - fixedFont->setPointSizeF(font_size); - setResolveMask(*fixedFont, QFont::NoPropertiesResolved); + fixedFont.reset(createUnresolveFont(font_name, font_size)); return fixedFont.data(); }