]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2005-08-21 Yoshinori K. Okuji <okuji@enbug.org>
authorokuji <okuji@localhost>
Sun, 21 Aug 2005 07:22:51 +0000 (07:22 +0000)
committerokuji <okuji@localhost>
Sun, 21 Aug 2005 07:22:51 +0000 (07:22 +0000)
        * util/console.c (grub_ncurses_putchar): If C is greater than
        0x7f, set C to a question mark.
        (grub_ncurses_getcharwidth): New function.
        (grub_ncurses_term): Specify grub_ncurses_getcharwidth as
        getcharwidth.

        * normal/menu.c (print_entry): Made aware of Unicode. First,
        convert TITLE to UCS-4, and predict the cursor position by
        grub_getcharwidth.

        * include/grub/misc.h (grub_utf8_to_ucs4): Specify the qualifier
        const to SRC.
        * kern/misc.c (grub_utf16_to_utf8): Likewise.

ChangeLog
include/grub/misc.h
kern/misc.c
normal/menu.c
util/console.c

index 634123b7a2fe70ab6e9a7e88fd6d59ba162cb443..1b13776deaede30e47c9c29049e2ca2ea6658aba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2005-08-21  Yoshinori K. Okuji  <okuji@enbug.org>
+
+       * util/console.c (grub_ncurses_putchar): If C is greater than
+       0x7f, set C to a question mark.
+       (grub_ncurses_getcharwidth): New function.
+       (grub_ncurses_term): Specify grub_ncurses_getcharwidth as
+       getcharwidth.
+
+       * normal/menu.c (print_entry): Made aware of Unicode. First,
+       convert TITLE to UCS-4, and predict the cursor position by
+       grub_getcharwidth.
+
+       * include/grub/misc.h (grub_utf8_to_ucs4): Specify the qualifier
+       const to SRC.
+       * kern/misc.c (grub_utf16_to_utf8): Likewise.
+
 2005-08-20  Yoshinori K. Okuji  <okuji@enbug.org>
 
        * loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Specify
index b549c3e2fc9453b16c3cad5a6ede385bcb0e2aaf..051fbe0012dbb75387a9ab8a412e7ae026c9a6cd 100644 (file)
@@ -73,7 +73,7 @@ grub_uint8_t *EXPORT_FUNC(grub_utf16_to_utf8) (grub_uint8_t *dest,
                                               grub_uint16_t *src,
                                               grub_size_t size);
 grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
-                                            grub_uint8_t *src,
+                                            const grub_uint8_t *src,
                                             grub_size_t size);
 
 grub_err_t EXPORT_FUNC(grub_split_cmdline) (const char *str, 
index 255ebb250b325efee277d9522c2b3aab36b96831..df5efa6a6ae156b359a2218c81f3cbec239e5daf 100644 (file)
@@ -809,7 +809,8 @@ grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src,
    characters (when the input is unknown). If an invalid sequence is found,
    return -1.  */
 grub_ssize_t
-grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_uint8_t *src, grub_size_t size)
+grub_utf8_to_ucs4 (grub_uint32_t *dest, const grub_uint8_t *src,
+                  grub_size_t size)
 {
   grub_uint32_t *p = dest;
   int count = 0;
index 8fc755c63c37c2268a8edd5044ab7f04c604c3ad..dd7fd1bd942ea54d1ff39e4c1ef05446a9cb9567 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003,2004  Free Software Foundation, Inc.
+ *  Copyright (C) 2003,2004,2005  Free Software Foundation, Inc.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -41,11 +41,13 @@ draw_border (void)
     {
       grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1);
       grub_putcode (GRUB_TERM_DISP_VLINE);
-      grub_gotoxy (GRUB_TERM_MARGIN + GRUB_TERM_BORDER_WIDTH - 1, GRUB_TERM_TOP_BORDER_Y + i + 1);
+      grub_gotoxy (GRUB_TERM_MARGIN + GRUB_TERM_BORDER_WIDTH - 1,
+                  GRUB_TERM_TOP_BORDER_Y + i + 1);
       grub_putcode (GRUB_TERM_DISP_VLINE);
     }
 
-  grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + 1);
+  grub_gotoxy (GRUB_TERM_MARGIN,
+              GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + 1);
   grub_putcode (GRUB_TERM_DISP_LL);
   for (i = 0; i < (unsigned) GRUB_TERM_BORDER_WIDTH - 2; i++)
     grub_putcode (GRUB_TERM_DISP_HLINE);
@@ -53,7 +55,9 @@ draw_border (void)
 
   grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
 
-  grub_gotoxy (GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES + GRUB_TERM_MARGIN + 1);
+  grub_gotoxy (GRUB_TERM_MARGIN,
+              (GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES
+               + GRUB_TERM_MARGIN + 1));
 }
 
 static void
@@ -97,8 +101,23 @@ print_entry (int y, int highlight, grub_menu_entry_t entry)
 {
   int x;
   const char *title;
-
+  grub_ssize_t len;
+  grub_uint32_t *unicode_title;
+  grub_ssize_t i;
+  
   title = entry ? entry->title : "";
+  unicode_title = grub_malloc (grub_strlen (title) * sizeof (*unicode_title));
+  if (! unicode_title)
+    /* XXX How to show this error?  */
+    return;
+  
+  len = grub_utf8_to_ucs4 (unicode_title, title, grub_strlen (title));
+  if (len < 0)
+    {
+      /* It is an invalid sequence.  */
+      grub_free (unicode_title);
+      return;
+    }
   
   grub_setcolorstate (highlight
                      ? GRUB_TERM_COLOR_HIGHLIGHT
@@ -106,23 +125,36 @@ print_entry (int y, int highlight, grub_menu_entry_t entry)
 
   grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
 
-  for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1;
+  for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, i = 0;
        x < GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN;
-       x++)
+       i++)
     {
-      if (*title && x <= GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN - 1)
+      if (i < len
+         && x <= (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH
+                  - GRUB_TERM_MARGIN - 1))
        {
-         if (x == GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH - GRUB_TERM_MARGIN - 1)
+         grub_ssize_t width;
+
+         width = grub_getcharwidth (unicode_title[i]);
+         
+         if (x + width > (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH
+                          - GRUB_TERM_MARGIN - 1))
            grub_putcode (GRUB_TERM_DISP_RIGHT);
          else
-           grub_putchar (*title++);
+           grub_putcode (unicode_title[i]);
+
+         x += width;
        }
       else
-       grub_putchar (' ');
+       {
+         grub_putchar (' ');
+         x++;
+       }
     }
   grub_gotoxy (GRUB_TERM_CURSOR_X, y);
 
   grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
+  grub_free (unicode_title);
 }
 
 static void
index ec3c855fcb7475ed6e8b8f9f2803a6efdc206338..3af2cbe6250db743c4bbbae34294cfa8ea2ffc69 100644 (file)
@@ -80,12 +80,21 @@ grub_ncurses_putchar (grub_uint32_t c)
       break;
 
     default:
+      /* ncurses does not support Unicode.  */
+      if (c > 0x7f)
+       c = '?';
       break;
     }
   
   addch (c | grub_console_attr);
 }
 
+static grub_ssize_t
+grub_ncurses_getcharwidth (grub_uint32_t code __attribute__ ((unused)))
+{
+  return 1;
+}
+
 static void
 grub_ncurses_setcolorstate (grub_term_color_state state)
 {
@@ -283,6 +292,7 @@ static struct grub_term grub_ncurses_term =
     .init = grub_ncurses_init,
     .fini = grub_ncurses_fini,
     .putchar = grub_ncurses_putchar,
+    .getcharwidth = grub_ncurses_getcharwidth,
     .checkkey = grub_ncurses_checkkey,
     .getkey = grub_ncurses_getkey,
     .getxy = grub_ncurses_getxy,