Add a complete SD card font subsystem that enables users to install and use custom fonts beyond the three built-in families. This combines the back-end firmware support (#1327) with the font configuration, build pipeline, CI distribution, and user-facing management UI (#1392). Core font system: - Custom .cpfont binary format (v4) with multi-style support (regular, bold, italic, bold-italic) packed into a single file per size - On-demand glyph loading from SD card with two-pass prewarm rendering to bulk-read glyphs per page, achieving near-flash performance for Latin text (~697ms vs ~681ms) and viable CJK rendering (~32% slower) - Persistent advance cache for layout measurement without SD I/O - Overflow ring buffer for glyph cache misses during rendering - Memory-conscious design: only advance tables kept in RAM; glyph bitmaps, kern tables, and ligatures loaded on demand from SD Font management: - On-device WiFi download from GitHub Releases with manifest-based discovery, install/update detection, and progress UI - Web interface font upload, listing, and deletion via /fonts page - Manual SD card copy to /fonts/ or /.fonts/ directories - Font selection integrated into Settings > Reader > Font Family Build pipeline: - Declarative YAML config (sd-fonts.yaml) as single source of truth for the 17-family font library (serif, sans, mono, accessibility) - Python converter (fontconvert_sdcard.py) for TTF/OTF to .cpfont with FreeType rasterization, class-based kerning, and ligature extraction - Parallel build orchestrator with variable font instance extraction - CI workflow publishing versioned + stable releases to a dedicated crosspoint-fonts repository with auto-incrementing revision tags - Centralized version constants (cpfont_version.py) shared across build tooling and CI, with firmware headers as manual sync points Additional fixes: - CJK characters no longer get hyphens inserted at line breaks - Advance table eliminates 30+ second stalls during CJK section indexing for paragraphs with >512 unique codepoints Closes #930 Co-authored-by: Zach Nelson <zach@zdnelson.com> Co-authored-by: Justin <itsthisjustin@users.noreply.github.com> Co-authored-by: jpirnay <jens@pirnay.com> Co-authored-by: mcrosson <kemonine@kemonine.info>
59 lines
2.4 KiB
C++
59 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
struct SdCardFontFileInfo {
|
|
std::string path; // v4 on-disk naming: "/<root>/<Family>/<Family>_<size>.cpfont"
|
|
// where <root> is "/.fonts" (preferred, hidden) or "/fonts" (visible).
|
|
// e.g. "/.fonts/NotoSansCJK/NotoSansCJK_14.cpfont"
|
|
uint8_t pointSize; // parsed from filename: 14
|
|
uint8_t style; // always 0 in v4 (all 4 styles bundled in one file);
|
|
// kept for potential future formats
|
|
};
|
|
|
|
struct SdCardFontFamilyInfo {
|
|
std::string name; // directory name, e.g. "NotoSansCJK"
|
|
std::vector<SdCardFontFileInfo> files;
|
|
|
|
const SdCardFontFileInfo* findFile(uint8_t size, uint8_t style = 0) const;
|
|
bool hasSize(uint8_t size) const;
|
|
std::vector<uint8_t> availableSizes() const;
|
|
};
|
|
|
|
class SdCardFontRegistry {
|
|
public:
|
|
static constexpr int MAX_SD_FAMILIES = 128;
|
|
// Two top-level roots are scanned at discovery time. Hidden is preferred
|
|
// when creating new installs; both are read from if present.
|
|
static constexpr const char* FONTS_DIR_HIDDEN = "/.fonts";
|
|
static constexpr const char* FONTS_DIR_VISIBLE = "/fonts";
|
|
|
|
// Returns the existing root for `familyName` (the one that contains
|
|
// /<root>/<familyName>/), or nullptr if the family is not installed in
|
|
// either root. Used by writers to keep re-installs in their existing dir.
|
|
static const char* findFamilyRoot(const char* familyName);
|
|
|
|
// Returns the root path that should be used when creating a brand-new
|
|
// family on disk (no prior install): the existing root if exactly one of
|
|
// the two roots exists, otherwise the hidden root.
|
|
static const char* defaultWriteRoot();
|
|
|
|
// Scan SD card, populate families_. Returns true if any families found.
|
|
bool discover();
|
|
|
|
const std::vector<SdCardFontFamilyInfo>& getFamilies() const { return families_; }
|
|
const SdCardFontFamilyInfo* findFamily(const std::string& name) const;
|
|
int getFamilyIndex(const std::string& name) const;
|
|
int getFamilyCount() const { return static_cast<int>(families_.size()); }
|
|
|
|
private:
|
|
std::vector<SdCardFontFamilyInfo> families_; // sorted alphabetically
|
|
|
|
static bool parseFilename(const char* filename, uint8_t& size, uint8_t& style);
|
|
static void scanDirectory(const char* dirPath, SdCardFontFamilyInfo& family);
|
|
// Scan one root (e.g. "/.fonts"), append families to `out`, dedup by name.
|
|
static void scanRoot(const char* rootPath, std::vector<SdCardFontFamilyInfo>& out);
|
|
};
|