More fixes
This commit is contained in:
@@ -11,6 +11,11 @@ extern SdCardFontSystem sdFontSystem;
|
||||
// Defined in main.cpp; call before entering the reader or after settings change.
|
||||
extern void ensureSdFontLoaded();
|
||||
|
||||
// Ensure the correct SD card font family is loaded for the given book path.
|
||||
// Selects EPUB or TXT/MD settings depending on the file extension.
|
||||
// Defined in main.cpp.
|
||||
extern void ensureSdFontLoadedForPath(const char* path);
|
||||
|
||||
// Resolve the SD card font ID for the given family name and font size enum.
|
||||
// Returns 0 if no SD font with that family name and size is currently loaded.
|
||||
// Free function (not stored as a callback in CrossPointSettings) so the linker
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,6 +19,10 @@ class SdCardFontSystem {
|
||||
/// Call before entering the reader or after settings change.
|
||||
void ensureLoaded(GfxRenderer& renderer);
|
||||
|
||||
/// Ensure the correct SD font family is loaded for an explicit family + size.
|
||||
/// Used when the reader type determines which settings field to consult.
|
||||
void ensureLoaded(GfxRenderer& renderer, const char* familyName, uint8_t fontSizeEnum);
|
||||
|
||||
/// Resolve an SD card font ID from family name + fontSize enum.
|
||||
/// Returns 0 if not found. Used by CrossPointSettings::getReaderFontId().
|
||||
int resolveFontId(const char* familyName, uint8_t fontSizeEnum) const;
|
||||
|
||||
@@ -286,7 +286,7 @@ void ActivityManager::goToBrowser() {
|
||||
|
||||
void ActivityManager::goToReader(std::string path) {
|
||||
RenderLock lock;
|
||||
ensureSdFontLoaded();
|
||||
ensureSdFontLoadedForPath(path.c_str());
|
||||
replaceActivity(std::make_unique<ReaderActivity>(renderer, mappedInput, std::move(path)));
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ void ActivityManager::replaceWithReader(std::string path, ReturnHint hint) {
|
||||
returnHint = std::move(hint);
|
||||
hasReturnHint = true;
|
||||
RenderLock lock;
|
||||
ensureSdFontLoaded();
|
||||
ensureSdFontLoadedForPath(path.c_str());
|
||||
replaceActivity(std::make_unique<ReaderActivity>(renderer, mappedInput, std::move(path)));
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ void SettingsActivity::onEnter() {
|
||||
continue;
|
||||
}
|
||||
const bool isReaderFontEntry =
|
||||
enriched.category == StrId::STR_CAT_READER && enriched.submenu == StrId::STR_MENU_READER_FONT;
|
||||
enriched.category == StrId::STR_CAT_READER &&
|
||||
(enriched.submenu == StrId::STR_MENU_READER_FONT || enriched.submenu == StrId::STR_MENU_TXT_FONT);
|
||||
|
||||
if (!insertedFontDownload && sawReaderFontSection && !isReaderFontEntry) {
|
||||
insertFontDownloadBelowFontSection();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <I18n.h>
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "FontSelectionActivity.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "SettingActionDispatch.h"
|
||||
#include "components/UITheme.h"
|
||||
@@ -22,6 +23,26 @@ void SettingsSubmenuActivity::onActionSelected(int index) {
|
||||
const auto& setting = menuItems[index];
|
||||
if (setting.isSeparator) return;
|
||||
|
||||
if (setting.type == SettingType::ENUM && setting.nameId == StrId::STR_FONT_FAMILY) {
|
||||
startActivityForResult(
|
||||
std::make_unique<FontSelectionActivity>(renderer, mappedInput, FontSelectionActivity::Target::EPUB),
|
||||
[this](const ActivityResult&) {
|
||||
SETTINGS.saveToFile();
|
||||
needsHalfRefresh = true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (setting.type == SettingType::ENUM && setting.nameId == StrId::STR_TXT_FONT_FAMILY) {
|
||||
startActivityForResult(
|
||||
std::make_unique<FontSelectionActivity>(renderer, mappedInput, FontSelectionActivity::Target::TXT),
|
||||
[this](const ActivityResult&) {
|
||||
SETTINGS.saveToFile();
|
||||
needsHalfRefresh = true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (setting.type == SettingType::ACTION) {
|
||||
MenuResult menuResult;
|
||||
if (setting.action != SettingAction::None) {
|
||||
|
||||
@@ -191,6 +191,24 @@ void setupDisplayAndFonts() {
|
||||
// activity-side callers out of SdCardFontSystem internals.
|
||||
void ensureSdFontLoaded() { sdFontSystem.ensureLoaded(renderer); }
|
||||
|
||||
void ensureSdFontLoadedForPath(const char* path) {
|
||||
if (!path) {
|
||||
ensureSdFontLoaded();
|
||||
return;
|
||||
}
|
||||
const size_t len = strlen(path);
|
||||
auto endsWith = [&](const char* suffix) {
|
||||
const size_t sl = strlen(suffix);
|
||||
return len >= sl && strcasecmp(path + len - sl, suffix) == 0;
|
||||
};
|
||||
const bool isTxtMd = endsWith(".txt") || endsWith(".md");
|
||||
if (isTxtMd) {
|
||||
sdFontSystem.ensureLoaded(renderer, SETTINGS.txtSdFontFamilyName, SETTINGS.txtFontSize);
|
||||
} else {
|
||||
sdFontSystem.ensureLoaded(renderer, SETTINGS.sdFontFamilyName, SETTINGS.fontSize);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
{
|
||||
esp_ota_img_states_t otaState;
|
||||
|
||||
Reference in New Issue
Block a user