Add independent default font for text 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
|
||||
|
||||
@@ -26,6 +26,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());
|
||||
}
|
||||
|
||||
+10
-1
@@ -92,7 +92,7 @@ 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 — 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.
|
||||
@@ -103,6 +103,15 @@ inline const std::vector<SettingInfo> list = {
|
||||
{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),
|
||||
// TXT/MD font — same dynamic structure as the EPUB font entry above.
|
||||
SettingInfo::DynamicEnum(StrId::STR_TXT_FONT_FAMILY, {StrId::STR_BOOKERLY, StrId::STR_NOTO_SANS},
|
||||
txtFontFamilyDynamicGetter, txtFontFamilyDynamicSetter, "txtFontFamily",
|
||||
StrId::STR_CAT_READER)
|
||||
.withSubcategory(StrId::STR_MENU_TXT_FONT),
|
||||
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)
|
||||
.withSubcategory(StrId::STR_MENU_TXT_FONT),
|
||||
SettingInfo::Toggle(StrId::STR_TEXT_AA, &CrossPointSettings::textAntiAliasing, "textAntiAliasing",
|
||||
StrId::STR_CAT_READER)
|
||||
.withSubmenu(StrId::STR_MENU_READER_FONT_SETTINGS),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user