From c02a9c5ab3b0d2c4a6d9fb0e558fa5e8e9271770 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sat, 27 Jun 2020 20:23:13 -0400 Subject: puzzles: refuse to draw non-ASCII characters We had some issues in Keen with the arithmetic operators not being rendered properly. This is still a kludge (we should intelligently search the font) but is still less ugly than the garbage it was drawing before. Change-Id: I5b957c7371b659ea6d64847145f9913b2a892e48 --- apps/plugins/puzzles/rockbox.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/apps/plugins/puzzles/rockbox.c b/apps/plugins/puzzles/rockbox.c index de89c42eed..a10bf7dd5c 100644 --- a/apps/plugins/puzzles/rockbox.c +++ b/apps/plugins/puzzles/rockbox.c @@ -1421,11 +1421,41 @@ static void draw_mouse(void) } } +/* doesn't work, disabled (can't find a good mechanism to check if a + * glyph exists in a font) */ +#if 0 +/* See: https://www.chiark.greenend.org.uk/~sgtatham/puzzles/devel/drawing.html#drawing-text-fallback */ static char *rb_text_fallback(void *handle, const char *const *strings, int nstrings) { - return dupstr(strings[0]); + struct font *pf = rb->font_get(cur_font); + + for(int i = 0; i < nstrings; i++) + { + LOGF("checking alternative \"%s\"", strings[i]); + const unsigned char *ptr = strings[i]; + unsigned short code; + bool valid = true; + + while(*ptr) + { + ptr = rb->utf8decode(ptr, &code); + + if(!rb->font_get_bits(pf, code)) + { + valid = false; + break; + } + } + + if(valid) + return dupstr(strings[i]); + } + + /* shouldn't get here */ + return dupstr(strings[nstrings - 1]); } +#endif const drawing_api rb_drawing = { rb_draw_text, @@ -1443,9 +1473,10 @@ const drawing_api rb_drawing = { rb_blitter_free, rb_blitter_save, rb_blitter_load, + /* printing functions */ NULL, NULL, NULL, NULL, NULL, NULL, /* {begin,end}_{doc,page,puzzle} */ - NULL, NULL, /* line_width, line_dotted */ - rb_text_fallback, + NULL, NULL, /* line_width, line_dotted */ + NULL, /* fall back to ASCII */ NULL, }; -- cgit v1.2.3