Merge pull request #220 from jpirnay/feat-txt-font
feat: Add a default font for .txt / .md files
This commit is contained in:
@@ -387,3 +387,11 @@ int CrossPointSettings::getReaderFontId() const {
|
||||
}
|
||||
return getBuiltinReaderFontId(fontFamily, fontSize);
|
||||
}
|
||||
|
||||
int CrossPointSettings::getTxtReaderFontId() const {
|
||||
if (txtSdFontFamilyName[0] != '\0') {
|
||||
int id = resolveSdCardFontId(txtSdFontFamilyName, txtFontSize);
|
||||
if (id != 0) return id;
|
||||
}
|
||||
return getBuiltinReaderFontId(txtFontFamily, txtFontSize);
|
||||
}
|
||||
|
||||
@@ -228,11 +228,15 @@ class CrossPointSettings {
|
||||
uint8_t frontButtonConfirm = FRONT_HW_CONFIRM;
|
||||
uint8_t frontButtonLeft = FRONT_HW_LEFT;
|
||||
uint8_t frontButtonRight = FRONT_HW_RIGHT;
|
||||
// Reader font settings
|
||||
// Reader font settings (EPUB)
|
||||
uint8_t fontFamily = BOOKERLY;
|
||||
// SD card font family name (empty = use built-in fontFamily)
|
||||
char sdFontFamilyName[32] = "";
|
||||
uint8_t fontSize = MEDIUM;
|
||||
// Reader font settings (TXT / MD) — defaults to EPUB settings when not explicitly set
|
||||
uint8_t txtFontFamily = NOTOSANS;
|
||||
char txtSdFontFamilyName[32] = "";
|
||||
uint8_t txtFontSize = MEDIUM;
|
||||
uint8_t lineSpacing = NORMAL;
|
||||
uint8_t paragraphAlignment = JUSTIFIED;
|
||||
// Auto-sleep timeout setting (default 10 minutes)
|
||||
@@ -358,6 +362,7 @@ class CrossPointSettings {
|
||||
|
||||
static constexpr uint16_t getPowerButtonDuration() { return 400; }
|
||||
int getReaderFontId() const;
|
||||
int getTxtReaderFontId() const;
|
||||
// Pure built-in lookup (size enum + family enum -> font ID). Independent of
|
||||
// SD-card font selection. Used by the per-book fontFamilyOverride path so
|
||||
// an override forces back to a known built-in even when an SD font is the
|
||||
|
||||
@@ -213,6 +213,11 @@ bool JsonSettingsIO::saveSettings(const CrossPointSettings& s, const char* path)
|
||||
if (s.sdFontFamilyName[0] != '\0') {
|
||||
doc["sdFontFamilyName"] = s.sdFontFamilyName;
|
||||
}
|
||||
// TXT/MD font family also uses DynamicEnumCtx (no valuePtr); save manually.
|
||||
doc["txtFontFamily"] = s.txtFontFamily;
|
||||
if (s.txtSdFontFamilyName[0] != '\0') {
|
||||
doc["txtSdFontFamilyName"] = s.txtSdFontFamilyName;
|
||||
}
|
||||
doc["moveFinishedBooksToCompleted"] = s.moveFinishedBooksToCompleted;
|
||||
doc["removeFinishedBooksFromRecents"] = s.removeFinishedBooksFromRecents;
|
||||
|
||||
@@ -329,6 +334,12 @@ bool JsonSettingsIO::loadSettings(CrossPointSettings& s, const char* json, bool*
|
||||
const char* sfn = doc["sdFontFamilyName"] | "";
|
||||
strncpy(s.sdFontFamilyName, sfn, sizeof(s.sdFontFamilyName) - 1);
|
||||
s.sdFontFamilyName[sizeof(s.sdFontFamilyName) - 1] = '\0';
|
||||
// TXT/MD font family is dynamic too; load manually.
|
||||
s.txtFontFamily = clamp(doc["txtFontFamily"] | (uint8_t)CrossPointSettings::NOTOSANS,
|
||||
CrossPointSettings::BUILTIN_FONT_COUNT, CrossPointSettings::NOTOSANS);
|
||||
const char* txtSfn = doc["txtSdFontFamilyName"] | "";
|
||||
strncpy(s.txtSdFontFamilyName, txtSfn, sizeof(s.txtSdFontFamilyName) - 1);
|
||||
s.txtSdFontFamilyName[sizeof(s.txtSdFontFamilyName) - 1] = '\0';
|
||||
s.moveFinishedBooksToCompleted = doc["moveFinishedBooksToCompleted"] | (uint8_t)0;
|
||||
s.removeFinishedBooksFromRecents = doc["removeFinishedBooksFromRecents"] | (uint8_t)0;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -26,6 +31,10 @@ int resolveSdCardFontId(const char* familyName, uint8_t fontSizeEnum);
|
||||
uint8_t fontFamilyDynamicGetter(const void* ctx);
|
||||
void fontFamilyDynamicSetter(void* ctx, uint8_t value);
|
||||
|
||||
// Same as above but for the TXT/MD reader font family setting.
|
||||
uint8_t txtFontFamilyDynamicGetter(const void* ctx);
|
||||
void txtFontFamilyDynamicSetter(void* ctx, uint8_t value);
|
||||
|
||||
// Returns the total number of font-family options currently available
|
||||
// (BUILTIN_FONT_COUNT + number of discovered SD families). Used by the
|
||||
// settings UI / web layer to enrich enumLabels and to bound cycling.
|
||||
|
||||
@@ -54,6 +54,33 @@ void fontFamilyDynamicSetter(void* /*ctx*/, uint8_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t txtFontFamilyDynamicGetter(const void* /*ctx*/) {
|
||||
if (SETTINGS.txtSdFontFamilyName[0] != '\0') {
|
||||
const auto& families = sdFontSystem.registry().getFamilies();
|
||||
for (size_t i = 0; i < families.size(); i++) {
|
||||
if (families[i].name == SETTINGS.txtSdFontFamilyName) {
|
||||
return static_cast<uint8_t>(CrossPointSettings::BUILTIN_FONT_COUNT + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return SETTINGS.txtFontFamily < CrossPointSettings::BUILTIN_FONT_COUNT ? SETTINGS.txtFontFamily
|
||||
: CrossPointSettings::NOTOSANS;
|
||||
}
|
||||
|
||||
void txtFontFamilyDynamicSetter(void* /*ctx*/, uint8_t value) {
|
||||
if (value < CrossPointSettings::BUILTIN_FONT_COUNT) {
|
||||
SETTINGS.txtFontFamily = value;
|
||||
SETTINGS.txtSdFontFamilyName[0] = '\0';
|
||||
return;
|
||||
}
|
||||
const auto& families = sdFontSystem.registry().getFamilies();
|
||||
uint8_t sdIdx = value - CrossPointSettings::BUILTIN_FONT_COUNT;
|
||||
if (sdIdx < families.size()) {
|
||||
strncpy(SETTINGS.txtSdFontFamilyName, families[sdIdx].name.c_str(), sizeof(SETTINGS.txtSdFontFamilyName) - 1);
|
||||
SETTINGS.txtSdFontFamilyName[sizeof(SETTINGS.txtSdFontFamilyName) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t fontFamilyOptionCount() {
|
||||
return static_cast<uint8_t>(CrossPointSettings::BUILTIN_FONT_COUNT + sdFontSystem.registry().getFamilies().size());
|
||||
}
|
||||
@@ -152,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;
|
||||
|
||||
+18
-5
@@ -92,24 +92,37 @@ inline const std::vector<SettingInfo> list = {
|
||||
SettingInfo::Enum(StrId::STR_ORIENTATION, &CrossPointSettings::orientation,
|
||||
{StrId::STR_PORTRAIT, StrId::STR_LANDSCAPE_CW, StrId::STR_INVERTED, StrId::STR_LANDSCAPE_CCW},
|
||||
"orientation", StrId::STR_CAT_READER),
|
||||
// Font — DynamicEnum so SD card font families can be appended at the consumer
|
||||
// EPUB font submenu — family first, then size/AA/darkness.
|
||||
// DynamicEnum so SD card font families can be appended at the consumer
|
||||
// side (SettingsActivity / CrossPointWebServer enrich enumLabels before
|
||||
// iterating). The built-in StrIds are kept as a fallback for code paths that
|
||||
// don't enrich enumLabels.
|
||||
SettingInfo::DynamicEnum(StrId::STR_FONT_FAMILY, {StrId::STR_BOOKERLY, StrId::STR_NOTO_SANS},
|
||||
fontFamilyDynamicGetter, fontFamilyDynamicSetter, "fontFamily", StrId::STR_CAT_READER)
|
||||
.withSubcategory(StrId::STR_MENU_READER_FONT),
|
||||
.withSubcategory(StrId::STR_MENU_READER_FONT)
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT)
|
||||
.withSelectorActivity(),
|
||||
SettingInfo::Enum(StrId::STR_FONT_SIZE, &CrossPointSettings::fontSize,
|
||||
{StrId::STR_SMALL, StrId::STR_MEDIUM, StrId::STR_LARGE, StrId::STR_X_LARGE, StrId::STR_TINY},
|
||||
"fontSize", StrId::STR_CAT_READER)
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT_SETTINGS),
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT),
|
||||
SettingInfo::Toggle(StrId::STR_TEXT_AA, &CrossPointSettings::textAntiAliasing, "textAntiAliasing",
|
||||
StrId::STR_CAT_READER)
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT_SETTINGS),
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT),
|
||||
SettingInfo::Enum(StrId::STR_TEXT_DARKNESS, &CrossPointSettings::textDarkness,
|
||||
{StrId::STR_NORMAL, StrId::STR_DARK, StrId::STR_EXTRA_DARK, StrId::STR_MAX_DARK}, "textDarkness",
|
||||
StrId::STR_CAT_READER)
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT_SETTINGS),
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT),
|
||||
// TXT/MD font submenu — same dynamic structure as EPUB, includes SD card fonts.
|
||||
SettingInfo::DynamicEnum(StrId::STR_TXT_FONT_FAMILY, {StrId::STR_BOOKERLY, StrId::STR_NOTO_SANS},
|
||||
txtFontFamilyDynamicGetter, txtFontFamilyDynamicSetter, "txtFontFamily",
|
||||
StrId::STR_CAT_READER)
|
||||
.withSubmenu(StrId::STR_MENU_TXT_FONT)
|
||||
.withSelectorActivity(),
|
||||
SettingInfo::Enum(StrId::STR_TXT_FONT_SIZE, &CrossPointSettings::txtFontSize,
|
||||
{StrId::STR_SMALL, StrId::STR_MEDIUM, StrId::STR_LARGE, StrId::STR_X_LARGE, StrId::STR_TINY},
|
||||
"txtFontSize", StrId::STR_CAT_READER)
|
||||
.withSubmenu(StrId::STR_MENU_TXT_FONT),
|
||||
|
||||
// Formatting settings
|
||||
SettingInfo::Enum(
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -494,7 +494,7 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
} else if (FsHelpers::checkFileExtension(bookPath, ".txt")) {
|
||||
} else if (FsHelpers::hasTxtExtension(bookPath) || FsHelpers::hasMarkdownExtension(bookPath)) {
|
||||
Txt txt(bookPath, "/.crosspoint");
|
||||
if (txt.load()) {
|
||||
info.title = txt.getTitle();
|
||||
@@ -834,7 +834,7 @@ void SleepActivity::renderOverlaySleepScreen() const {
|
||||
|
||||
if (FsHelpers::checkFileExtension(path, ".xtc") || FsHelpers::checkFileExtension(path, ".xtch")) {
|
||||
rendered = XtcReaderActivity::drawCurrentPageToBuffer(path, renderer);
|
||||
} else if (FsHelpers::checkFileExtension(path, ".txt")) {
|
||||
} else if (FsHelpers::hasTxtExtension(path) || FsHelpers::hasMarkdownExtension(path)) {
|
||||
rendered = TxtReaderActivity::drawCurrentPageToBuffer(path, renderer);
|
||||
} else if (FsHelpers::checkFileExtension(path, ".epub")) {
|
||||
rendered = EpubReaderActivity::drawCurrentPageToBuffer(path, renderer);
|
||||
|
||||
@@ -325,7 +325,7 @@ void MdReaderActivity::initializeReader() {
|
||||
return;
|
||||
}
|
||||
|
||||
cachedFontId = SETTINGS.getReaderFontId();
|
||||
cachedFontId = SETTINGS.getTxtReaderFontId();
|
||||
cachedScreenMargin = SETTINGS.screenMargin;
|
||||
cachedParagraphAlignment = SETTINGS.paragraphAlignment;
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ void TxtReaderActivity::initializeReader() {
|
||||
}
|
||||
|
||||
// Store current settings for cache validation
|
||||
cachedFontId = SETTINGS.getReaderFontId();
|
||||
cachedFontId = SETTINGS.getTxtReaderFontId();
|
||||
cachedScreenMargin = SETTINGS.screenMargin;
|
||||
cachedParagraphAlignment = SETTINGS.paragraphAlignment;
|
||||
|
||||
@@ -710,7 +710,7 @@ bool TxtReaderActivity::drawCurrentPageToBuffer(const std::string& filePath, Gfx
|
||||
}
|
||||
|
||||
// Compute layout values that match what initializeReader() produces
|
||||
const int fontId = SETTINGS.getReaderFontId();
|
||||
const int fontId = SETTINGS.getTxtReaderFontId();
|
||||
const uint8_t screenMargin = SETTINGS.screenMargin;
|
||||
const uint8_t paragraphAlignment = SETTINGS.paragraphAlignment;
|
||||
|
||||
|
||||
@@ -6,28 +6,12 @@
|
||||
#include "MappedInputManager.h"
|
||||
#include "SdCardFontGlobals.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
namespace {
|
||||
|
||||
uint8_t currentFontIndex() {
|
||||
if (SETTINGS.sdFontFamilyName[0] != '\0') {
|
||||
const auto& families = sdFontSystem.registry().getFamilies();
|
||||
for (int i = 0; i < static_cast<int>(families.size()); i++) {
|
||||
if (families[i].name == SETTINGS.sdFontFamilyName) {
|
||||
return static_cast<uint8_t>(CrossPointSettings::BUILTIN_FONT_COUNT + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return SETTINGS.fontFamily < CrossPointSettings::BUILTIN_FONT_COUNT ? SETTINGS.fontFamily : 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void FontSelectionActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
fontCount = fontFamilyOptionCount();
|
||||
selectedIndex = currentFontIndex();
|
||||
selectedIndex =
|
||||
static_cast<int>(target == Target::TXT ? txtFontFamilyDynamicGetter(nullptr) : fontFamilyDynamicGetter(nullptr));
|
||||
if (selectedIndex >= fontCount) selectedIndex = 0;
|
||||
requestUpdate();
|
||||
}
|
||||
@@ -50,7 +34,11 @@ void FontSelectionActivity::loop() {
|
||||
}
|
||||
|
||||
void FontSelectionActivity::handleSelection() {
|
||||
fontFamilyDynamicSetter(nullptr, static_cast<uint8_t>(selectedIndex));
|
||||
if (target == Target::TXT) {
|
||||
txtFontFamilyDynamicSetter(nullptr, static_cast<uint8_t>(selectedIndex));
|
||||
} else {
|
||||
fontFamilyDynamicSetter(nullptr, static_cast<uint8_t>(selectedIndex));
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -60,13 +48,15 @@ void FontSelectionActivity::render(RenderLock&&) {
|
||||
const auto& metrics = UITheme::getInstance().getMetrics();
|
||||
const Rect contentRect = UITheme::getContentRect(renderer, true, false);
|
||||
|
||||
const StrId headerStr = target == Target::TXT ? StrId::STR_TXT_FONT_FAMILY : StrId::STR_FONT_FAMILY;
|
||||
GUI.drawHeader(renderer, Rect{contentRect.x, metrics.topPadding, contentRect.width, metrics.headerHeight},
|
||||
tr(STR_FONT_FAMILY));
|
||||
I18N.get(headerStr));
|
||||
|
||||
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
|
||||
const int contentHeight = contentRect.height - contentTop - metrics.verticalSpacing;
|
||||
|
||||
const uint8_t activeIndex = currentFontIndex();
|
||||
const uint8_t activeIndex = static_cast<uint8_t>(target == Target::TXT ? txtFontFamilyDynamicGetter(nullptr)
|
||||
: fontFamilyDynamicGetter(nullptr));
|
||||
GUI.drawList(
|
||||
renderer, Rect{contentRect.x, contentTop, contentRect.width, contentHeight}, fontCount, selectedIndex,
|
||||
[](int index) { return fontFamilyOptionLabel(static_cast<uint8_t>(index)); }, nullptr, nullptr,
|
||||
|
||||
@@ -11,8 +11,10 @@ class MappedInputManager;
|
||||
/// Replaces in-place enum cycling for the Reader Font Family setting.
|
||||
class FontSelectionActivity final : public Activity {
|
||||
public:
|
||||
explicit FontSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
|
||||
: Activity("FontSelect", renderer, mappedInput) {}
|
||||
enum class Target { EPUB, TXT };
|
||||
|
||||
explicit FontSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, Target target = Target::EPUB)
|
||||
: Activity("FontSelect", renderer, mappedInput), target(target) {}
|
||||
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
@@ -25,4 +27,5 @@ class FontSelectionActivity final : public Activity {
|
||||
ButtonNavigator buttonNavigator;
|
||||
int selectedIndex = 0;
|
||||
uint8_t fontCount = 0;
|
||||
Target target;
|
||||
};
|
||||
|
||||
@@ -221,9 +221,18 @@ struct SettingInfo {
|
||||
}
|
||||
|
||||
bool isSeparator = false;
|
||||
bool usesSelectorActivity = false; // Confirm opens a full-screen selector instead of inline cycling
|
||||
StrId subcategory = StrId::STR_NONE_OPT; // Triggers a separator row on first use and on change
|
||||
StrId submenu = StrId::STR_NONE_OPT; // Routes item into a submenu; hidden from main list
|
||||
|
||||
// Marks this entry as requiring a full-screen selector activity on Confirm
|
||||
// (instead of inline value cycling). The SettingsActivity / SettingsSubmenuActivity
|
||||
// intercept entries with this flag before toggleValue() is called.
|
||||
SettingInfo& withSelectorActivity() {
|
||||
usesSelectorActivity = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Inserts a separator row in the parent tab when this item's subcategory first appears or changes.
|
||||
SettingInfo& withSubcategory(StrId sub) {
|
||||
subcategory = sub;
|
||||
|
||||
@@ -81,10 +81,11 @@ void SettingsActivity::onEnter() {
|
||||
setting.nameId == StrId::STR_TIMEZONE)) {
|
||||
continue;
|
||||
}
|
||||
// Enrich the font-family entry with SD card families discovered at boot.
|
||||
// Enrich font-family entries with SD card families discovered at boot.
|
||||
// The list itself is a namespace-static; we only mutate our local copy here.
|
||||
SettingInfo enriched = setting;
|
||||
if (setting.key && std::strcmp(setting.key, "fontFamily") == 0) {
|
||||
if (setting.key &&
|
||||
(std::strcmp(setting.key, "fontFamily") == 0 || std::strcmp(setting.key, "txtFontFamily") == 0)) {
|
||||
const uint8_t n = fontFamilyOptionCount();
|
||||
enriched.enumLabels.clear();
|
||||
enriched.enumLabels.reserve(n);
|
||||
@@ -96,8 +97,8 @@ void SettingsActivity::onEnter() {
|
||||
continue;
|
||||
}
|
||||
const bool isReaderFontEntry =
|
||||
enriched.category == StrId::STR_CAT_READER && (enriched.subcategory == StrId::STR_MENU_READER_FONT ||
|
||||
enriched.submenu == StrId::STR_MENU_READER_FONT_SETTINGS);
|
||||
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();
|
||||
@@ -277,8 +278,10 @@ void SettingsActivity::toggleCurrentSetting() {
|
||||
const auto& setting = (*currentSettings)[selectedSetting];
|
||||
if (setting.isSeparator) return;
|
||||
|
||||
if (setting.type == SettingType::ENUM && setting.nameId == StrId::STR_FONT_FAMILY) {
|
||||
startActivityForResult(std::make_unique<FontSelectionActivity>(renderer, mappedInput),
|
||||
if (setting.usesSelectorActivity) {
|
||||
const auto target = (setting.valueGetter == txtFontFamilyDynamicGetter) ? FontSelectionActivity::Target::TXT
|
||||
: FontSelectionActivity::Target::EPUB;
|
||||
startActivityForResult(std::make_unique<FontSelectionActivity>(renderer, mappedInput, target),
|
||||
[this](const ActivityResult&) {
|
||||
SETTINGS.saveToFile();
|
||||
needsHalfRefresh = true;
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include <I18n.h>
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "FontSelectionActivity.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "SdCardFontGlobals.h"
|
||||
#include "SettingActionDispatch.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
@@ -48,6 +50,26 @@ std::string SettingsSubmenuActivity::getItemValueString(int index) const {
|
||||
return MenuListActivity::getItemValueString(index);
|
||||
}
|
||||
|
||||
void SettingsSubmenuActivity::toggleCurrentItem() {
|
||||
if (selectedIndex < 0 || selectedIndex >= static_cast<int>(menuItems.size())) return;
|
||||
const auto& setting = menuItems[selectedIndex];
|
||||
if (setting.isSeparator) return;
|
||||
|
||||
if (setting.usesSelectorActivity) {
|
||||
const auto target = (setting.valueGetter == txtFontFamilyDynamicGetter) ? FontSelectionActivity::Target::TXT
|
||||
: FontSelectionActivity::Target::EPUB;
|
||||
startActivityForResult(std::make_unique<FontSelectionActivity>(renderer, mappedInput, target),
|
||||
[this](const ActivityResult&) {
|
||||
SETTINGS.saveToFile();
|
||||
needsHalfRefresh = true;
|
||||
requestUpdate();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
MenuListActivity::toggleCurrentItem();
|
||||
}
|
||||
|
||||
void SettingsSubmenuActivity::onSettingToggled(int /*index*/) { SETTINGS.saveToFile(); }
|
||||
|
||||
void SettingsSubmenuActivity::render(RenderLock&&) {
|
||||
|
||||
@@ -16,6 +16,7 @@ class SettingsSubmenuActivity final : public MenuListActivity {
|
||||
|
||||
// MenuListActivity overrides
|
||||
void onEnter() override;
|
||||
void toggleCurrentItem() override;
|
||||
void onActionSelected(int index) override;
|
||||
void onSettingToggled(int index) override;
|
||||
std::string getItemValueString(int index) const override;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <Epub.h>
|
||||
#include <FontCacheManager.h>
|
||||
#include <FontDecompressor.h>
|
||||
#include <FsHelpers.h>
|
||||
#include <GfxRenderer.h>
|
||||
#include <HalClock.h>
|
||||
#include <HalDisplay.h>
|
||||
@@ -191,6 +192,21 @@ void setupDisplayAndFonts() {
|
||||
// activity-side callers out of SdCardFontSystem internals.
|
||||
void ensureSdFontLoaded() { sdFontSystem.ensureLoaded(renderer); }
|
||||
|
||||
void ensureSdFontLoadedForPath(const char* path) {
|
||||
if (!path) {
|
||||
ensureSdFontLoaded();
|
||||
return;
|
||||
}
|
||||
const std::string_view filePath(path);
|
||||
const bool isTxtMd = static_cast<bool (*)(std::string_view)>(FsHelpers::hasTxtExtension)(filePath) ||
|
||||
static_cast<bool (*)(std::string_view)>(FsHelpers::hasMarkdownExtension)(filePath);
|
||||
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;
|
||||
|
||||
@@ -1257,10 +1257,10 @@ void CrossPointWebServer::handleGetSettings() const {
|
||||
for (const auto& sBase : settings) {
|
||||
if (!sBase.key) continue; // Skip ACTION-only entries
|
||||
|
||||
// Enrich the font-family entry with current SD card families.
|
||||
// Enrich font-family entries with current SD card families.
|
||||
SettingInfo sLocal;
|
||||
const SettingInfo* sPtr = &sBase;
|
||||
if (std::strcmp(sBase.key, "fontFamily") == 0) {
|
||||
if (sBase.key && (std::strcmp(sBase.key, "fontFamily") == 0 || std::strcmp(sBase.key, "txtFontFamily") == 0)) {
|
||||
sLocal = sBase;
|
||||
const uint8_t n = fontFamilyOptionCount();
|
||||
sLocal.enumLabels.clear();
|
||||
@@ -1380,9 +1380,11 @@ void CrossPointWebServer::handlePostSettings() {
|
||||
}
|
||||
case SettingType::ENUM: {
|
||||
const int val = doc[s.key].as<int>();
|
||||
// For fontFamily the enumLabels in the static list are empty by design
|
||||
// For font-family keys the enumLabels in the static list are empty by design
|
||||
// (built lazily by handleGetSettings); use the dynamic option count instead.
|
||||
const int count = (std::strcmp(s.key, "fontFamily") == 0)
|
||||
const bool isFontFamilyKey =
|
||||
s.key && (std::strcmp(s.key, "fontFamily") == 0 || std::strcmp(s.key, "txtFontFamily") == 0);
|
||||
const int count = isFontFamilyKey
|
||||
? static_cast<int>(fontFamilyOptionCount())
|
||||
: static_cast<int>(s.enumLabels.empty() ? s.enumValues.size() : s.enumLabels.size());
|
||||
if (val >= 0 && val < count) {
|
||||
|
||||
Reference in New Issue
Block a user