Skip to content

Commit

Permalink
Add mirroring for visual UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
phcoder committed Mar 16, 2010
1 parent 703cbe6 commit 6f5568e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions include/grub/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#include <grub/mm.h>
#include <grub/misc.h>

struct grub_unicode_bidi_pair
{
grub_uint32_t key;
grub_uint32_t replace;
};

struct grub_unicode_compact_range
{
grub_uint32_t start:21;
Expand Down Expand Up @@ -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. */
Expand Down
16 changes: 15 additions & 1 deletion normal/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down
24 changes: 22 additions & 2 deletions util/import_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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 <grub/unicode.h>\n")
outfile.write ("\n")
outfile.write ("struct grub_unicode_compact_range grub_unicode_compact[] = {\n")
Expand Down Expand Up @@ -69,4 +69,24 @@
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")

0 comments on commit 6f5568e

Please sign in to comment.