From 45e3044ed47fcaab15579da516df8922b3b48954 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Sun, 1 Aug 2010 13:52:04 +0200 Subject: Add wide character support to the Hurd console * hurd/console.h (CONS_WCHAR_MASK, CONS_WCHAR_CONTINUED): New macros. * console/console.c: Include (main): Call setlocale. * console/display.c (display_output_one): Call wcwidth() to know the width of the character to be displayed. Iterate over this with to insert characters with the additional CONS_WCHAR_CONTINUED flag. Update screen_shift_right and display_record_filechange calls accordingly. * console-client/vga-dynafont.c (WCHAR_BOLD, WCHAR_ITALIC, WCHAR_MASK): Change macro values. (dynafont_new): Use glyph->bbox.{width,height} instead of df->font->bbox.{width,height}. (dynafont_change_font): Likewise. (dynafont_lookup_internal): Likewise. Mask out CONS_WCHAR_CONTINUED before calling bdf_find_glyph, but test it for the second position of a double-width glyph. (dynafont_activate): Enable 9-bit width only when font width is not dividable by 8. --- console/display.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'console/display.c') diff --git a/console/display.c b/console/display.c index 090aaf80..f6a24a8a 100644 --- a/console/display.c +++ b/console/display.c @@ -1593,23 +1593,38 @@ display_output_one (display_t display, wchar_t chr) int line = (user->screen.cur_line + user->cursor.row) % user->screen.lines; int idx = line * user->screen.width + user->cursor.col; + int width, i; + + width = wcwidth (chr); + if (width < 0) + width = 1; if (display->insert_mode - && user->cursor.col != user->screen.width - 1) + && user->cursor.col < user->screen.width - width) { /* If in insert mode, do the same as . */ screen_shift_right (display, user->cursor.col, user->cursor.row, user->screen.width - 1, user->cursor.row, - 1, L' ', display->attr.current); + width, L' ', display->attr.current); + } + + if (display->attr.altchar) + chr = altchar_to_ucs4 (chr); + + for (i = 0; i < width; i++) + { + if (user->cursor.col >= user->screen.width) + break; + user->_matrix[idx+i].chr = chr; + user->_matrix[idx+i].attr = display->attr.current; + user->cursor.col++; + chr |= CONS_WCHAR_CONTINUED; } - user->_matrix[idx].chr = display->attr.altchar - ? altchar_to_ucs4 (chr) : chr; - user->_matrix[idx].attr = display->attr.current; + if (i > 0) + display_record_filechange (display, idx, idx + i - 1); - display_record_filechange (display, idx, idx); - user->cursor.col++; if (user->cursor.col == user->screen.width) { user->cursor.col = 0; -- cgit v1.2.3