Build the font family setting dynamically. When registry is non-null, SD card fonts are appended after the built-in fonts. Otherwise only built-in fonts are listed.
| 17 | // Build the font family setting dynamically. When registry is non-null, SD card fonts |
| 18 | // are appended after the built-in fonts. Otherwise only built-in fonts are listed. |
| 19 | inline SettingInfo buildFontFamilySetting(const SdCardFontRegistry* registry) { |
| 20 | // Built-in font labels (StrId) |
| 21 | std::vector<StrId> enumValues = {StrId::STR_NOTO_SERIF, StrId::STR_NOTO_SANS}; |
| 22 | // Runtime string labels for SD card fonts |
| 23 | std::vector<std::string> enumStringValues; |
| 24 | |
| 25 | // Reserve: first CrossPointSettings::BUILTIN_FONT_COUNT entries use StrId, rest use strings |
| 26 | if (registry) { |
| 27 | const auto& families = registry->getFamilies(); |
| 28 | enumStringValues.reserve(families.size()); |
| 29 | std::transform(families.begin(), families.end(), std::back_inserter(enumStringValues), |
| 30 | [](const SdCardFontFamilyInfo& f) { return f.name; }); |
| 31 | } |
| 32 | |
| 33 | // Capture the SD font count for the lambdas |
| 34 | const int sdFontCount = static_cast<int>(enumStringValues.size()); |
| 35 | |
| 36 | // Total option count = built-in + SD card families |
| 37 | // For the combined enumStringValues: we need all entries as strings (built-in names + SD names) |
| 38 | // The render code checks enumStringValues first, then enumValues. So we build enumStringValues |
| 39 | // with all options when SD fonts are present. |
| 40 | std::vector<std::string> allStringValues; |
| 41 | if (sdFontCount > 0) { |
| 42 | allStringValues.push_back(I18N.get(StrId::STR_NOTO_SERIF)); |
| 43 | allStringValues.push_back(I18N.get(StrId::STR_NOTO_SANS)); |
| 44 | allStringValues.insert(allStringValues.end(), enumStringValues.begin(), enumStringValues.end()); |
| 45 | } |
| 46 | |
| 47 | SettingInfo s; |
| 48 | s.nameId = StrId::STR_FONT_FAMILY; |
| 49 | s.type = SettingType::ENUM; |
| 50 | s.enumValues = std::move(enumValues); |
| 51 | s.enumStringValues = std::move(allStringValues); |
| 52 | s.key = "fontFamily"; |
| 53 | s.category = StrId::STR_CAT_READER; |
| 54 | |
| 55 | // Capture registry families by copy for the lambdas |
| 56 | std::vector<std::string> sdFamilyNames; |
| 57 | if (registry) { |
| 58 | const auto& families = registry->getFamilies(); |
| 59 | sdFamilyNames.reserve(families.size()); |
| 60 | std::transform(families.begin(), families.end(), std::back_inserter(sdFamilyNames), |
| 61 | [](const SdCardFontFamilyInfo& f) { return f.name; }); |
| 62 | } |
| 63 | |
| 64 | s.valueGetter = [sdFamilyNames]() -> uint8_t { |
| 65 | // If an SD card font is selected, find its index |
| 66 | if (SETTINGS.sdFontFamilyName[0] != '\0') { |
| 67 | for (int i = 0; i < static_cast<int>(sdFamilyNames.size()); i++) { |
| 68 | if (sdFamilyNames[i] == SETTINGS.sdFontFamilyName) { |
| 69 | return static_cast<uint8_t>(CrossPointSettings::BUILTIN_FONT_COUNT + i); |
| 70 | } |
| 71 | } |
| 72 | // SD font name not found in registry — fall through to built-in |
| 73 | } |
| 74 | return SETTINGS.fontFamily < CrossPointSettings::BUILTIN_FONT_COUNT ? SETTINGS.fontFamily : 0; |
| 75 | }; |
| 76 |