More fixes

This commit is contained in:
jpirnay
2026-05-15 00:02:16 +02:00
parent 3dfcdd002f
commit 25e1a64eb8
7 changed files with 82 additions and 3 deletions
+30
View File
@@ -179,6 +179,36 @@ static uint8_t targetPtSizeFromEnum(uint8_t fontSizeEnum) {
return FONT_SIZE_TO_PT[fontSizeEnum];
}
void SdCardFontSystem::ensureLoaded(GfxRenderer& renderer, const char* wantedFamily, uint8_t fontSizeEnum) {
const std::string& currentFamily = manager_.currentFamilyName();
const uint8_t targetPt = targetPtSizeFromEnum(fontSizeEnum);
if (!wantedFamily || wantedFamily[0] == '\0') {
if (!currentFamily.empty()) manager_.unloadAll(renderer);
return;
}
bool familyMatches = (currentFamily == wantedFamily);
if (familyMatches) {
const auto* family = registry_.findFamily(wantedFamily);
if (!family) {
manager_.unloadAll(renderer);
return;
}
const auto* best = family->pickClosestSize(targetPt);
if (best && best->pointSize == manager_.currentPointSize()) return;
}
if (!currentFamily.empty()) manager_.unloadAll(renderer);
const auto* family = registry_.findFamily(wantedFamily);
if (family) {
if (!manager_.loadFamily(*family, renderer, targetPt)) {
LOG_ERR("SDFS", "Failed to load SD font family: %s", wantedFamily);
}
}
}
int SdCardFontSystem::resolveFontId(const char* familyName, uint8_t fontSizeEnum) const {
// The manager loads exactly one size for the active SD family. Resolve only
// if the requested family matches the loaded family and the requested size