From eac612c30944b4d28d1f9ef3890f4836e9212ad2 Mon Sep 17 00:00:00 2001 From: Dav999 Date: Wed, 3 Jan 2024 22:21:37 +0100 Subject: [PATCH] Add PR_RTL_XFLIP print flag This lets you mirror the X axis specifically in RTL languages, so the left border is 320 and the right border is 0, and invert the meaning of PR_LEFT (0) and PR_RIGHT. Most of the time this is not necessary, it's just for stuff where a label is followed by a different print, like "Font: " followed by the font name, time trial time displays, etc --- desktop_version/lang/README-programmers.txt | 3 +++ desktop_version/src/Font.cpp | 12 ++++++++++-- desktop_version/src/Font.h | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/desktop_version/lang/README-programmers.txt b/desktop_version/lang/README-programmers.txt index ecaf5ee7..d0388b44 100644 --- a/desktop_version/lang/README-programmers.txt +++ b/desktop_version/lang/README-programmers.txt @@ -103,6 +103,9 @@ A not-technically-exhaustive list of all flags (which are defined in Font.h): - PR_CJK_LOW Larger fonts should stick out fully on the bottom (draw at Y) - PR_CJK_HIGH Larger fonts should stick out fully on the top +- PR_RTL_XFLIP 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 diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 3396d3aa..932bd1cd 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -86,6 +86,7 @@ struct PrintFlags bool cjk_low; bool cjk_high; bool rtl; + bool rtl_xflip; }; static FontContainer fonts_main = {}; @@ -830,6 +831,7 @@ static PrintFlags decode_print_flags(uint32_t flags) pf.align_right = flags & PR_RIGHT; pf.cjk_low = flags & PR_CJK_LOW; pf.cjk_high = flags & PR_CJK_HIGH; + pf.rtl_xflip = flags & PR_RTL_XFLIP; if (pf.full_border) { @@ -1269,6 +1271,12 @@ void print( return; } + if (pf.rtl && pf.rtl_xflip && (!pf.align_cen || x != -1)) + { + x = SCREEN_WIDTH_PIXELS - x; + pf.align_right = !pf.align_right; + } + if (pf.align_cen || pf.align_right) { const int textlen = len(flags, text); @@ -1294,7 +1302,7 @@ void print( for (int offset = 0; offset < 4; offset++) { print( - flags & ~PR_BOR & ~PR_CEN & ~PR_RIGHT, + flags & ~PR_BOR & ~PR_CEN & ~PR_RIGHT & ~PR_RTL_XFLIP, x + offsets[offset][0]*pf.scale, y + offsets[offset][1]*pf.scale, text, @@ -1310,7 +1318,7 @@ void print( for (int offset = 0; offset < 8; offset++) { print( - flags & ~PR_FULLBOR & ~PR_CEN & ~PR_RIGHT, + flags & ~PR_FULLBOR & ~PR_CEN & ~PR_RIGHT & ~PR_RTL_XFLIP, x + offsets[offset][0] * pf.scale, y + offsets[offset][1] * pf.scale, text, diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index 662f882e..2e02c244 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -55,6 +55,7 @@ #define PR_CJK_LOW (1 << 20) /* larger fonts should stick out fully on the bottom (draw at Y) */ #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 */ namespace font