[Fonts] Resolve CardText sizes against the shipped theme

Seeding themes/<name>/fonts.toml made getAvailableThemes() resolve the user dir, which shadowed the shipped theme.cfg and stylesheet: styleName came back empty and QSS was cleared. Fall back to the shipped theme dir for theme.cfg and QSS when the user dir exists, and resolve CardText sizes through FontConfig's 6..72 range so a migrated 80..100 renders at the size the editor shows. Insert CardTextMaxSize inside [Fonts] when another section follows.
This commit is contained in:
Lukas Brübach 2026-11-07 19:02:51 +01:00
parent e87cd80c9b
commit 47bb103a87
9 changed files with 415 additions and 79 deletions

View file

@ -1160,6 +1160,54 @@ TEST_F(SettingsMigrationTest, AppearanceMaxFontSize_MergesWithOtherRoles)
EXPECT_TRUE(content.contains("20"));
}
TEST_F(SettingsMigrationTest, AppearanceMaxFontSize_InsertsIntoFontsSectionNotAfterIt)
{
// A hand-edited fonts.toml may keep [Fonts] first and another section after
// it. Appending the seeded key at EOF would land it in that trailing
// section, where the font parser never reads it.
const QString themesPath = tempDir.path() + "/themes";
ASSERT_TRUE(QDir().mkpath(themesPath + "/MyTheme"));
{
QFile f(themesPath + "/MyTheme/fonts.toml");
ASSERT_TRUE(f.open(QIODevice::WriteOnly | QIODevice::Text));
QTextStream out(&f);
out << "[Fonts]\n"
"# keep this comment\n"
"InterfaceDefault = \"Inter, 10\"\n"
"\n"
"[Other]\n"
"Keep = \"me\"\n";
}
{
QSettings paths(settingsPath + "paths.ini", QSettings::IniFormat);
paths.setValue("paths/themes", themesPath);
paths.sync();
}
{
QSettings appearance(settingsPath + "appearance.ini", QSettings::IniFormat);
appearance.setValue("appearance/maxFontSize", 18);
appearance.sync();
}
ASSERT_TRUE(SettingsMigration::migrateAppearanceMaxFontSizeToTheme(settingsPath));
QFile f(themesPath + "/MyTheme/fonts.toml");
ASSERT_TRUE(f.open(QIODevice::ReadOnly | QIODevice::Text));
const QString content = QString::fromUtf8(f.readAll());
ASSERT_TRUE(content.contains("CardTextMaxSize"));
EXPECT_TRUE(content.contains("18"));
// The new key belongs to [Fonts], not to the section that follows it ...
const int keyPos = content.indexOf("CardTextMaxSize");
const int otherSectionPos = content.indexOf("[Other]");
ASSERT_GE(keyPos, 0);
ASSERT_GE(otherSectionPos, 0);
EXPECT_LT(keyPos, otherSectionPos);
// ... and the file keeps its own comment, ordering and trailing section.
EXPECT_TRUE(content.contains("# keep this comment"));
EXPECT_TRUE(content.contains("InterfaceDefault = \"Inter, 10\""));
EXPECT_TRUE(content.endsWith("[Other]\nKeep = \"me\"\n"));
}
TEST_F(SettingsMigrationTest, AppearanceMaxFontSize_AbsentKeyDoesNothing)
{
ASSERT_FALSE(SettingsMigration::migrateAppearanceMaxFontSizeToTheme(settingsPath));