From a82890fffcb113f48fee854e5fc38aca9ec39158 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 29 Mar 2010 03:37:24 +0200 Subject: [PATCH] Shape arabic code when on UTF-8 visual --- include/grub/unicode.h | 2 ++ normal/charset.c | 36 ++++++++++++++++++++++++++++++++++++ normal/term.c | 9 ++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/include/grub/unicode.h b/include/grub/unicode.h index 9fde69cc8..a779e2c9c 100644 --- a/include/grub/unicode.h +++ b/include/grub/unicode.h @@ -222,5 +222,7 @@ grub_unicode_glyph_from_code (grub_uint32_t code) grub_uint32_t grub_unicode_mirror_code (grub_uint32_t in); +grub_uint32_t +grub_unicode_shape_code (grub_uint32_t in, grub_uint8_t attr); #endif diff --git a/normal/charset.c b/normal/charset.c index 55a9894a9..6f09fac90 100644 --- a/normal/charset.c +++ b/normal/charset.c @@ -1227,3 +1227,39 @@ grub_unicode_mirror_code (grub_uint32_t in) return grub_unicode_bidi_pairs[i].replace; return in; } + +grub_uint32_t +grub_unicode_shape_code (grub_uint32_t in, grub_uint8_t attr) +{ + int i; + if (!(in >= GRUB_UNICODE_ARABIC_START + && in < GRUB_UNICODE_ARABIC_END)) + return in; + + for (i = 0; grub_unicode_arabic_shapes[i].code; i++) + if (grub_unicode_arabic_shapes[i].code == in) + { + grub_uint32_t out; + switch (attr & (GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED + | GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED)) + { + case 0: + out = grub_unicode_arabic_shapes[i].isolated; + break; + case GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED: + out = grub_unicode_arabic_shapes[i].right_linked; + break; + case GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED: + out = grub_unicode_arabic_shapes[i].left_linked; + break; + case GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED + |GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED: + out = grub_unicode_arabic_shapes[i].both_linked; + break; + } + if (out) + return out; + } + + return in; +} diff --git a/normal/term.c b/normal/term.c index 09299f647..4724c5d41 100644 --- a/normal/term.c +++ b/normal/term.c @@ -392,9 +392,12 @@ putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term) { code = c->base; if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) - == GRUB_TERM_CODE_TYPE_UTF8_VISUAL - && (c->attributes & GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR)) - code = grub_unicode_mirror_code (code); + == GRUB_TERM_CODE_TYPE_UTF8_VISUAL) + { + if ((c->attributes & GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR)) + code = grub_unicode_mirror_code (code); + code = grub_unicode_shape_code (code, c->attributes); + } } else code = c->combining[i].code;