1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00
without ucdata stuff. UTF-8 code cleanup. Added Pavol Babincak
to the AUTHORS
This commit is contained in:
Pavol Babincak 2006-07-25 09:59:12 +02:00 committed by Witold Filipczyk
parent 6c8f532692
commit a7a7984d89
7 changed files with 48 additions and 39 deletions

View File

@ -423,6 +423,9 @@ Omar Khayam <omark@cyentec.com>
<otte@duke.edu> <otte@duke.edu>
Fix stdin reading on Mac OS X Fix stdin reading on Mac OS X
Pavol Babincak <scroolik@gmail.com>
Improved UTF-8 support with double-width chars
Peder Stray <peder@ifi.uio.no> Peder Stray <peder@ifi.uio.no>
Fix handling of key presses turning up as key prefixes Fix handling of key presses turning up as key prefixes

View File

@ -601,6 +601,27 @@ CONFIG_OWN_LIBC=no
CONFIG_SMALL=no CONFIG_SMALL=no
### Unicode UTF-8 support
#
# By enabling this option you get better Unicode support. At present only some
# parts of ELinks are influenced with this. It includes DOM, plain, HTML
# renderer and user interface. Beside normal Unicode characters there is
# support for double-width characters (like Japanese, etc.).
#
# Some features of Unicode are not handled at all. Combining characters is
# most visible absence.
# Some features are partially supported. Like line breaking between
# double-width characters. There is no other detection for determining when to
# break or not.
#
# Note: This UTF-8 support is experimental.
#
# Default: disabled
CONFIG_UTF_8=no
### Back-trace Printing ### Back-trace Printing
# #
# Once upon a time, a disaster happens and ELinks crashes. That is a very sad # Once upon a time, a disaster happens and ELinks crashes. That is a very sad

View File

@ -100,20 +100,19 @@ redraw_dialog(struct dialog_data *dlg_data, int layout)
int titlelen = strlen(title); int titlelen = strlen(title);
int titlecells = titlelen; int titlecells = titlelen;
int x, y; int x, y;
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if (term->utf8) if (term->utf8)
titlecells = utf8_ptr2cells(title, titlecells = utf8_ptr2cells(title,
&title[titlelen]); &title[titlelen]);
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
titlecells = int_min(box.width - 2, titlecells); titlecells = int_min(box.width - 2, titlecells);
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if (term->utf8) { if (term->utf8)
titlelen = utf8_cells2bytes(title, titlelen = utf8_cells2bytes(title, titlecells,
titlecells,
NULL); NULL);
}
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
x = (box.width - titlecells) / 2 + box.x; x = (box.width - titlecells) / 2 + box.x;

View File

@ -51,6 +51,7 @@ split_line(unsigned char *text, int max_width, int *cells)
while (*split && *split != '\n') { while (*split && *split != '\n') {
unsigned char *next_split; unsigned char *next_split;
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if (utf8) { if (utf8) {
unsigned char *next_char_begin = split unsigned char *next_char_begin = split

View File

@ -215,8 +215,7 @@ encode_utf_8(unicode_val_T u)
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
/* Number of bytes utf8 character indexed by first byte. Illegal bytes are /* Number of bytes utf8 character indexed by first byte. Illegal bytes are
* equal ones and handled different. */ * equal ones and handled different. */
static char utf8char_len_tab[256] = static char utf8char_len_tab[256] = {
{
1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
@ -229,11 +228,7 @@ static char utf8char_len_tab[256] =
inline int utf8charlen(const unsigned char *p) inline int utf8charlen(const unsigned char *p)
{ {
int len; return p ? utf8char_len_tab[*p] : 0;
if (p==NULL)
return 0;
len = utf8char_len_tab[*p];
return len;
} }
inline int inline int
@ -260,14 +255,14 @@ strlen_utf8(unsigned char **str)
inline unsigned char * inline unsigned char *
utf8_prevchar(unsigned char *current, int pos, unsigned char *start) utf8_prevchar(unsigned char *current, int pos, unsigned char *start)
{ {
if (current == NULL || start == NULL || pos < 0) if (current == NULL || start == NULL || pos < 0)
return NULL; return NULL;
while (pos > 0 && current != start) { while (pos > 0 && current != start) {
current--; current--;
if (utf8_islead(*current)) if (utf8_islead(*current))
pos--; pos--;
} }
return current; return current;
} }
/* Count number of standard terminal cells needed for displaying UTF-8 /* Count number of standard terminal cells needed for displaying UTF-8

View File

@ -118,9 +118,9 @@ draw_char_data(struct terminal *term, int x, int y, unsigned char data)
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
#ifdef CONFIG_DEBUG #ifdef CONFIG_DEBUG
/* Detect attempt to draw double-width char on the last /* Detect attempt to draw double-width char on the last
* collumn of terminal. */ * column of terminal. */
if (unicode_to_cell(data) == 2 && x + 1 > term->width) if (unicode_to_cell(data) == 2 && x + 1 > term->width)
INTERNAL("Attempt to draw double-width glyph on last collumn!"); INTERNAL("Attempt to draw double-width glyph on last column!");
#endif /* CONFIG_DEBUG */ #endif /* CONFIG_DEBUG */
if (data == UCS_NO_CHAR) if (data == UCS_NO_CHAR)
@ -161,7 +161,7 @@ draw_line(struct terminal *term, int x, int y, int l, struct screen_char *line)
screen_char++; screen_char++;
} }
/* Instead of displaying double-width character at last collumn /* Instead of displaying double-width character at last column
* display only space. */ * display only space. */
if (size - 1 > 0 && unicode_to_cell(line[size - 1].data) == 2) { if (size - 1 > 0 && unicode_to_cell(line[size - 1].data) == 2) {
sc = &line[size - 1]; sc = &line[size - 1];

View File

@ -251,9 +251,7 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
case EVENT_KBD: case EVENT_KBD:
{ {
#ifndef CONFIG_UTF_8
int utf8_io = -1; int utf8_io = -1;
#endif /* CONFIG_UTF_8 */
int key = get_kbd_key(ev); int key = get_kbd_key(ev);
reset_timer(); reset_timer();
@ -267,14 +265,14 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
return 0; return 0;
} }
if (interlink->utf_8.len) {
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if ((key & 0xC0) == 0x80 && term->utf8) utf8_io = !!term->utf8;
#else #else
utf8_io = get_opt_bool_tree(term->spec, "utf_8_io"); utf8_io = get_opt_bool_tree(term->spec, "utf_8_io");
if ((key & 0xC0) == 0x80 && utf8_io)
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
{
if (interlink->utf_8.len) {
if ((key & 0xC0) == 0x80 && utf8_io) {
interlink->utf_8.ucs <<= 6; interlink->utf_8.ucs <<= 6;
interlink->utf_8.ucs |= key & 0x3F; interlink->utf_8.ucs |= key & 0x3F;
if (! --interlink->utf_8.len) { if (! --interlink->utf_8.len) {
@ -292,15 +290,7 @@ handle_interlink_event(struct terminal *term, struct term_event *ev)
} }
} }
#ifdef CONFIG_UTF_8 if (key < 0x80 || key > 0xFF || !utf8_io) {
if (key < 0x80 || key > 0xFF || !term->utf8)
#else
if (key < 0x80 || key > 0xFF
|| (utf8_io == -1
? !get_opt_bool_tree(term->spec, "utf_8_io")
: !utf8_io))
#endif /* CONFIG_UTF_8 */
{
term_send_event(term, ev); term_send_event(term, ev);
break; break;