diff --git a/autogen.sh b/autogen.sh index 5d0b5a282..524b908f5 100755 --- a/autogen.sh +++ b/autogen.sh @@ -13,7 +13,7 @@ echo timestamp > stamp-h.in python util/import_gcry.py lib/libgcrypt/ . -python util/import_unicode.py util/UnicodeData.txt unidata.c +python util/import_unicode.py util/UnicodeData.txt util/BidiMirroring.txt unidata.c for rmk in conf/*.rmk ${GRUB_CONTRIB}/*/conf/*.rmk; do if test -e $rmk ; then diff --git a/include/grub/unicode.h b/include/grub/unicode.h index 2bc9753ed..c96d8854d 100644 --- a/include/grub/unicode.h +++ b/include/grub/unicode.h @@ -23,6 +23,12 @@ #include #include +struct grub_unicode_bidi_pair +{ + grub_uint32_t key; + grub_uint32_t replace; +}; + struct grub_unicode_compact_range { grub_uint32_t start:21; @@ -97,6 +103,7 @@ struct grub_unicode_glyph #define GRUB_UNICODE_VARIATION_SELECTOR_256 0xe01ef extern struct grub_unicode_compact_range grub_unicode_compact[]; +extern struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[]; #define GRUB_UNICODE_MAX_CACHED_CHAR 0x20000 /* Unicode mandates an arbitrary limit. */ diff --git a/normal/charset.c b/normal/charset.c index 143836bf2..8b81910dc 100644 --- a/normal/charset.c +++ b/normal/charset.c @@ -1087,6 +1087,16 @@ map_code (grub_uint32_t in, struct grub_term_output *term) return in; } +static grub_uint32_t +mirror_code (grub_uint32_t in) +{ + int i; + for (i = 0; grub_unicode_bidi_pairs[i].key; i++) + if (grub_unicode_bidi_pairs[i].key == in) + return grub_unicode_bidi_pairs[i].replace; + return in; +} + static void putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term) { @@ -1124,7 +1134,11 @@ putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term) grub_uint32_t code; if (i == -1) - code = c->base; + { + code = c->base; + if (c->attributes & GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR) + code = mirror_code (code); + } else code = c->combining[i].code; diff --git a/util/import_unicode.py b/util/import_unicode.py index e2f0561f0..0fc36c5c2 100644 --- a/util/import_unicode.py +++ b/util/import_unicode.py @@ -25,7 +25,7 @@ if len (sys.argv) < 3: print ("Usage: %s SOURCE DESTINATION" % sys.argv[0]) exit (0) infile = open (sys.argv[1], "r") -outfile = open (sys.argv[2], "w") +outfile = open (sys.argv[3], "w") outfile.write ("#include \n") outfile.write ("\n") outfile.write ("struct grub_unicode_compact_range grub_unicode_compact[] = {\n") @@ -69,4 +69,24 @@ if lastbiditype != "L" or lastcombtype != 0 or lastmirrortype: lastmirrortype))) outfile.write ("{0, 0, 0, 0, 0},\n") -outfile.write ("};") +outfile.write ("};\n") + +infile.close () + +infile = open (sys.argv[2], "r") + +outfile.write ("struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[] = {\n") + +for line in infile: + line = re.sub ("#.*$", "", line) + line = line.replace ("\n", "") + line = line.replace (" ", "") + if len (line) == 0 or line[0] == '\n': + continue + sp = line.split (";") + code1 = int (sp[0], 16) + code2 = int (sp[1], 16) + outfile.write ("{0x%x, 0x%x},\n" % (code1, code2)) +outfile.write ("{0, 0},\n") +outfile.write ("};\n") +