]> git.proxmox.com Git - grub2.git/commitdiff
Fix combining characters messing with width counter
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 16 Mar 2010 18:55:09 +0000 (19:55 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 16 Mar 2010 18:55:09 +0000 (19:55 +0100)
include/grub/unicode.h
kern/term.c
normal/charset.c
normal/menu_text.c
term/serial.c

index e7f176d0f0443e2574a9ea0b22fcf8be142aa6a4..2bc9753edd98eb347762b17f59c380a37e3fceca 100644 (file)
@@ -84,6 +84,9 @@ struct grub_unicode_glyph
     grub_uint32_t code;
     enum grub_comb_type type;
   } *combining;
+  /* Hint by unicode subsystem how wide this character usually is.
+     Real width is determined by font. Set only in UTF-8 stream.  */
+  int estimated_width;
 };
 
 #define GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR 0x1
@@ -134,15 +137,11 @@ static inline struct grub_unicode_glyph *
 grub_unicode_glyph_from_code (grub_uint32_t code)
 {
   struct grub_unicode_glyph *ret;
-  ret = grub_malloc (sizeof (*ret));
+  ret = grub_zalloc (sizeof (*ret));
   if (!ret)
     return NULL;
 
   ret->base = code;
-  ret->variant = 0;
-  ret->attributes = 0;
-  ret->ncomb = 0;
-  ret->combining = 0;
 
   return ret;
 }
index 8139e8118cd431816309d539bbe51657ebe4c0fe..a65d67196306549f81bbc2ed165d8cc2b737f037 100644 (file)
@@ -41,7 +41,8 @@ grub_putcode_dumb (grub_uint32_t code,
       .variant = 0,
       .attributes = 0,
       .ncomb = 0,
-      .combining = 0
+      .combining = 0,
+      .estimated_width = 1
     };
 
   if (code == '\t' && term->getxy)
index 53b9578e590775158bfa04bf4b4dbd15528a0a62..af53b31342c8d1403eb1f3899e8c1859c1a1f076 100644 (file)
@@ -538,6 +538,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen,
       out->variant = 0;
       out->attributes = 0;
       out->ncomb = 0;
+      out->estimated_width = 1;
       out->combining = NULL;
     }
   return ptr - in;
@@ -1075,7 +1076,8 @@ putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term)
       .variant = 0,
       .attributes = 0,
       .ncomb = 0,
-      .combining = 0
+      .combining = 0,
+      .estimated_width = 1
     };
 
   if (c->base == '\t' && term->getxy)
@@ -1096,6 +1098,7 @@ putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term)
       == GRUB_TERM_CODE_TYPE_UTF8_VISUAL)
     {
       int i;
+      c2.estimated_width = 1;
       for (i = -1; i < (int) c->ncomb; i++)
        {
          grub_uint8_t u8[20], *ptr;
@@ -1112,8 +1115,10 @@ putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term)
            {
              c2.base = *ptr;
              (term->putchar) (&c2);
+             c2.estimated_width = 0;
            }
        }
+      c2.estimated_width = 1;
     }
   else
     (term->putchar) (c);
@@ -1133,7 +1138,8 @@ putcode_real (grub_uint32_t code, struct grub_term_output *term)
       .variant = 0,
       .attributes = 0,
       .ncomb = 0,
-      .combining = 0
+      .combining = 0,
+      .estimated_width = 1
     };
 
   c.base = map_code (code, term);
index 61ddd2490fc3752db8bad99d58ac874008a27fdf..2e2cf0e0cb021d0c745a2f54cdc043871aad4c58 100644 (file)
@@ -273,7 +273,8 @@ print_entry (int y, int highlight, grub_menu_entry_t entry,
        .variant = 0,
        .attributes = 0,
        .ncomb = 0,
-       .combining = 0
+       .combining = 0,
+       .estimated_width = 1
       };
       x += grub_term_getcharwidth (term, &pseudo_glyph);
     }
index 18978911f7554a5fa0ba58c0bb961da4ccc338d2..666606fcc458825065b7644b31a2afdff0283c25 100644 (file)
@@ -356,7 +356,7 @@ grub_serial_putchar (const struct grub_unicode_glyph *c)
              serial_hw_put ('\r');
              serial_hw_put ('\n');
            }
-         xpos++;
+         xpos += c->estimated_width;
          break;
        }
     }