Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly fix using setfont()/setrtl() script commands in between text boxes #1132

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions desktop_version/src/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions desktop_version/src/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
59 changes: 34 additions & 25 deletions desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down Expand Up @@ -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;
}
}

if (!blocked)
{
if (words[0] == "setrtl")
else if (words[1] == "off")
{
if (words[1] == "on")
{
cl.rtl = true;
}
else if (words[1] == "off")
{
cl.rtl = false;
}
cl.rtl = false;
}
else if (words[1] == "")
}
else if (words[1] == "")
{
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)
{
font::set_level_font(cl.level_font_name.c_str());
flags |= PR_FONT_IDX_IS_CUSTOM;
}
else

for (size_t i = 0; i < graphics.textboxes.size(); i++)
{
font::set_level_font(raw_words[1].c_str());
graphics.textboxes[i].print_flags = flags;
graphics.textboxes[i].resize();
}
}
}
Expand Down