feat: Word Processor discovers fonts automatically (via 0:/fonts), UI fix

This commit is contained in:
2026-06-06 10:12:11 +02:00
parent 8341082bd6
commit 0728dd58e5
7 changed files with 435 additions and 106 deletions
+28 -12
View File
@@ -82,20 +82,17 @@ static constexpr int WP_DIVIDER_FLYOUT_W = 216;
static constexpr int WP_SPECIAL_CHAR_ROW_H = 24;
static constexpr int WP_SPECIAL_CHAR_FLYOUT_W = 144;
static constexpr int FONT_ROBOTO = 0;
static constexpr int FONT_NOTOSERIF = 1;
static constexpr int FONT_C059 = 2;
static constexpr int FONT_COUNT = 3;
// Fonts are discovered at runtime by scanning 0:/fonts (see wp_load_fonts).
// A font id is an index into the discovered family table (g_wp_fonts). The
// table is bounded by WP_MAX_FONTS; ids beyond the table fall back to default.
static constexpr int WP_MAX_FONTS = 24; // max discovered families
static constexpr int WP_FONT_NAME_MAX = 32; // family/display name
static constexpr int WP_FONT_PATH_MAX = 96; // "0:/fonts/<file>.ttf"
static constexpr int WP_FONT_BASENAME_MAX = 48; // filename stem (PDF base font)
static constexpr uint8_t STYLE_BOLD = 0x01;
static constexpr uint8_t STYLE_ITALIC = 0x02;
inline constexpr const char* WP_FONT_NAMES[FONT_COUNT] = {
"Roboto",
"NotoSerif",
"C059",
};
inline constexpr int WP_SIZE_OPTIONS[] = { 12, 14, 16, 18, 20, 24, 28, 36 };
static constexpr int WP_SIZE_OPTION_COUNT = 8;
inline constexpr int WP_LINE_SPACING_OPTIONS[] = { 100, 125, 150, 200 };
@@ -178,9 +175,22 @@ inline constexpr WpDividerOption WP_DIVIDER_OPTIONS[] = {
};
static constexpr int WP_DIVIDER_OPTION_COUNT = 7;
// One font family with up to four style variants, indexed:
// [0] regular [1] bold [2] italic [3] bold-italic
// A missing variant has an empty path/basename and a null font; callers fall
// back to the regular face via wp_get_font().
struct WpFontFamily {
char name[WP_FONT_NAME_MAX]; // e.g. "Roboto"
char paths[4][WP_FONT_PATH_MAX]; // vfs path per variant ("" if absent)
char basenames[4][WP_FONT_BASENAME_MAX]; // filename stem per variant (PDF base font)
TrueTypeFont* fonts[4];
bool serif; // PDF font descriptor hint
};
struct WPFontTable {
TrueTypeFont* fonts[FONT_COUNT][4];
bool loaded;
WpFontFamily families[WP_MAX_FONTS];
int count;
bool loaded;
};
struct StyledRun {
@@ -422,6 +432,12 @@ void wp_free_document(WordProcessorState* wp);
void wp_cleanup_state();
TrueTypeFont* wp_get_font(int font_id, uint8_t flags);
int wp_font_count(); // number of discovered families
const char* wp_font_name(int font_id); // family display name ("" if out of range)
int wp_default_font_id(); // index of "Roboto", else 0
int wp_find_font_by_name(const char* name); // -1 if not found
int wp_resolve_variant(int font_id, int variant); // closest available face, -1 if none
int wp_font_dropdown_width(); // popup width fitted to the longest font name
int wp_abs_pos(WordProcessorState* wp, int run, int offset);
void wp_pos_to_run(WordProcessorState* wp, int abs_pos, int* out_run, int* out_offset);