diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 38773453..a8af8e1d 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -95,8 +95,8 @@ uint8_t font_idx_options_n = 0; uint8_t font_idx_options[20]; static bool font_level_is_interface = false; -static bool font_idx_level_is_custom = false; -static uint8_t font_idx_level = 0; +bool font_idx_level_is_custom = false; +uint8_t font_idx_level = 0; static void codepoint_split( const uint32_t codepoint, @@ -765,13 +765,14 @@ static Font* container_get(FontContainer* container, uint8_t idx) return NULL; } -static Font* fontsel_to_font(int sel, bool* rtl) +static Font* fontsel_to_font(int sel, bool* rtl, bool custom) { /* Take font selection integer (0-31) and turn it into the correct Font * 0: PR_FONT_INTERFACE - use interface font * 1: PR_FONT_LEVEL - use level font * 2: PR_FONT_8X8 - use 8x8 font no matter what - * 3-31: - use (main) font index 0-28 + * 3-31: - use font index 0-28 (depending on custom, from + * PR_FONT_IDX_IS_CUSTOM) * * rtl will be set depending on whether we're requesting the interface * font (take it from the lang attributes) or level font (take it from @@ -808,6 +809,10 @@ static Font* fontsel_to_font(int sel, bool* rtl) return container_get(&fonts_main, font_idx_8x8); } + if (custom) + { + return container_get(&fonts_custom, sel-3); + } return container_get(&fonts_main, sel-3); } @@ -816,7 +821,9 @@ static PrintFlags decode_print_flags(uint32_t flags) { PrintFlags pf; pf.scale = FLAG_PART(0, 3) + 1; - pf.font_sel = fontsel_to_font(FLAG_PART(3, 5), &pf.rtl); + pf.font_sel = fontsel_to_font( + FLAG_PART(3, 5), &pf.rtl, flags & PR_FONT_IDX_IS_CUSTOM + ); if (flags & PR_RTL_FORCE) { pf.rtl = true; diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index 2e02c244..74de6d2d 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -56,6 +56,7 @@ #define PR_CJK_HIGH (2 << 20) /* larger fonts should stick out fully on the top */ #define PR_RTL_FORCE (1 << 22) /* force the RTL flag, not needed if the font is set to INTERFACE or LEVEL */ #define PR_RTL_XFLIP (1 << 23) /* in RTL languages, mirror the X axis, so left is 320 and right is 0, and invert the meaning of PR_LEFT and PR_RIGHT */ +#define PR_FONT_IDX_IS_CUSTOM (1 << 24) /* with PR_FONT_IDX, mark that the font index is of a custom font */ namespace font @@ -64,6 +65,9 @@ namespace font extern uint8_t font_idx_options_n; extern uint8_t font_idx_options[20]; +extern uint8_t font_idx_level; +extern bool font_idx_level_is_custom; + bool find_main_font_by_name(const char* name, uint8_t* idx); const char* get_main_font_name(uint8_t idx); const char* get_main_font_display_name(uint8_t idx); diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index b4dac088..0939503b 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -798,6 +798,16 @@ void scriptclass::run(void) graphics.textboxcentery(); } + if (map.custommode) + { + uint32_t flags = PR_FONT_IDX(font::font_idx_level, cl.rtl); + if (font::font_idx_level_is_custom) + { + flags |= PR_FONT_IDX_IS_CUSTOM; + } + graphics.textboxprintflags(flags); + } + graphics.textboxadjust(); if (words[0] == "speak_active") { @@ -2481,39 +2491,38 @@ void scriptclass::run(void) } else if (words[0] == "setfont" || words[0] == "setrtl") { - // If any textbox is currently fading out, wait for that first - bool blocked = false; - for (size_t i = 0; i < graphics.textboxes.size(); i++) + if (words[0] == "setrtl") { - if (graphics.textboxes[i].tm == 2) + if (words[1] == "on") { - scriptdelay = 1; - position--; - blocked = true; - break; + cl.rtl = true; + } + else if (words[1] == "off") + { + cl.rtl = false; } } - - if (!blocked) + else if (words[1] == "") { - if (words[0] == "setrtl") + font::set_level_font(cl.level_font_name.c_str()); + } + else + { + font::set_level_font(raw_words[1].c_str()); + } + if (argexists[2] && words[2] == "all") + { + /* Immediately update all text boxes. */ + uint32_t flags = PR_FONT_IDX(font::font_idx_level, cl.rtl); + if (font::font_idx_level_is_custom) { - if (words[1] == "on") - { - cl.rtl = true; - } - else if (words[1] == "off") - { - cl.rtl = false; - } + flags |= PR_FONT_IDX_IS_CUSTOM; } - else if (words[1] == "") + + for (size_t i = 0; i < graphics.textboxes.size(); i++) { - font::set_level_font(cl.level_font_name.c_str()); - } - else - { - font::set_level_font(raw_words[1].c_str()); + graphics.textboxes[i].print_flags = flags; + graphics.textboxes[i].resize(); } } }