Skip to content

Commit b1f0248

Browse files
committed
Font (Linux): parse unicode escaped string stored by qt5ct
Fix #1864
1 parent 77dd184 commit b1f0248

File tree

1 file changed

+36
-6
lines changed
  • src/detection/gtk_qt

1 file changed

+36
-6
lines changed

src/detection/gtk_qt/qt.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,45 @@ static void detectQtCt(char qver, FFQtResult* result)
140140
// by the same author and qt6ct understands qt5ct in qt6 applications as well.
141141
char file[] = "qtXct/qtXct.conf";
142142
file[2] = file[8] = qver;
143+
144+
FF_STRBUF_AUTO_DESTROY font = ffStrbufCreate();
145+
143146
ffParsePropFileConfigValues(file, 3, (FFpropquery[]) {
144147
{"style=", &result->widgetStyle},
145148
{"icon_theme=", &result->icons},
146-
{"general=", &result->font}
149+
{"general=", &font}
147150
});
148151

149-
if (ffStrbufStartsWithC(&result->font, '@'))
152+
if (ffStrbufStartsWithC(&font, '@'))
150153
{
151154
// See QVariant notes on https://doc.qt.io/qt-5/qsettings.html and
152155
// https://github.com/fastfetch-cli/fastfetch/issues/1053#issuecomment-2197254769
153156
// Thankfully, newer versions use the more common font encoding.
154-
ffStrbufSetNS(&result->font, 5, file);
157+
ffStrbufSetNS(&font, 5, file);
158+
}
159+
else if (qver == '5')
160+
{
161+
// #1864
162+
const char *p = font.chars;
163+
164+
while (*p)
165+
{
166+
if (p[0] == '\\' && p[1] == 'x' && isxdigit(p[2]) && isxdigit(p[3]) && isxdigit(p[4]) && isxdigit(p[5]))
167+
{
168+
uint32_t codepoint = (uint32_t)strtoul((char[]) { p[2], p[3], p[4], p[5], '\0' }, NULL, 16);
169+
ffStrbufAppendUtf32CodePoint(&result->font, codepoint);
170+
p += 6;
171+
}
172+
else
173+
{
174+
ffStrbufAppendC(&result->font, *p++);
175+
}
176+
}
177+
}
178+
else
179+
{
180+
ffStrbufDestroy(&result->font);
181+
ffStrbufInitMove(&result->font, &font);
155182
}
156183
}
157184

@@ -178,14 +205,17 @@ const FFQtResult* ffDetectQt(void)
178205
ffStrbufInit(&result.wallpaper);
179206

180207
const FFDisplayServerResult* wmde = ffConnectDisplayServer();
181-
const char *qplatformtheme = getenv("QT_QPA_PLATFORMTHEME");
182208

183209
if(ffStrbufIgnCaseEqualS(&wmde->dePrettyName, FF_DE_PRETTY_PLASMA))
184210
detectPlasma(&result);
185211
else if(ffStrbufIgnCaseEqualS(&wmde->dePrettyName, FF_DE_PRETTY_LXQT))
186212
detectLXQt(&result);
187-
else if(ffStrSet(qplatformtheme) && (ffStrEquals(qplatformtheme, "qt5ct") || ffStrEquals(qplatformtheme, "qt6ct")))
188-
detectQtCt(qplatformtheme[2], &result);
213+
else
214+
{
215+
const char *qPlatformTheme = getenv("QT_QPA_PLATFORMTHEME");
216+
if(qPlatformTheme && (ffStrEquals(qPlatformTheme, "qt5ct") || ffStrEquals(qPlatformTheme, "qt6ct")))
217+
detectQtCt(qPlatformTheme[2], &result);
218+
}
189219

190220
if(ffStrbufEqualS(&result.widgetStyle, "kvantum") || ffStrbufEqualS(&result.widgetStyle, "kvantum-dark"))
191221
{

0 commit comments

Comments
 (0)