Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: treeland font init failed #251

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions platformthemeplugin/qdeepintheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -667,12 +675,16 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const
QByteArray font_name = theme->fontName();
qreal font_size = 0;

static QScopedPointer<QFont> 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);
Expand All @@ -684,13 +696,8 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const
font_size = 10.5;
}

static QScopedPointer<QFont> 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();
}
Expand All @@ -700,8 +707,11 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const
if (DPlatformTheme *theme = appTheme()) {
QByteArray font_name = theme->monoFontName();

static QScopedPointer<QFont> 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();
Expand All @@ -710,13 +720,8 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const
font_size = 10.5;
}

static QScopedPointer<QFont> 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();
}
Expand Down
Loading