1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Support for double-width glyphs in DOM renderer

Removed duplicate code for UTF-8 in DOM renderer. Modified DOM renderer
to correctly displaying multi-width glyphs.
This commit is contained in:
Pavol Babincak 2006-02-08 22:03:40 +01:00 committed by Jonas Fonseca
parent 5561437629
commit f4a430e480

View File

@ -250,11 +250,11 @@ render_dom_line(struct dom_renderer *renderer, struct screen_char *template,
struct document *document = renderer->document; struct document *document = renderer->document;
struct conv_table *convert = renderer->convert_table; struct conv_table *convert = renderer->convert_table;
enum convert_string_mode mode = renderer->convert_mode; enum convert_string_mode mode = renderer->convert_mode;
int x, charlen;
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
int utf8 = document->options.utf8; int utf8 = document->options.utf8;
unsigned char *end, *text; unsigned char *end;
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
int x;
assert(renderer && template && string && length); assert(renderer && template && string && length);
@ -271,14 +271,14 @@ render_dom_line(struct dom_renderer *renderer, struct screen_char *template,
add_search_node(renderer, length); add_search_node(renderer, length);
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
if (utf8) goto utf_8; end = string + length;
#endif /* CONFIG_UTF_8 */ #endif /* CONFIG_UTF_8 */
for (x = 0; x < length; x++, renderer->canvas_x++) { for (x = 0, charlen = 1; x < length;x += charlen, renderer->canvas_x++) {
unsigned char data = string[x]; unsigned char *text = &string[x];
/* This is mostly to be able to break out so the indentation /* This is mostly to be able to break out so the indentation
* level won't get to high. */ * level won't get to high. */
switch (data) { switch (*text) {
case ASCII_TAB: case ASCII_TAB:
{ {
int tab_width = 7 - (X(renderer) & 7); int tab_width = 7 - (X(renderer) & 7);
@ -293,52 +293,33 @@ render_dom_line(struct dom_renderer *renderer, struct screen_char *template,
* ``main loop'' add the actual tab char. */ * ``main loop'' add the actual tab char. */
for (; tab_width-- > 0; renderer->canvas_x++) for (; tab_width-- > 0; renderer->canvas_x++)
copy_screen_chars(POS(renderer), template, 1); copy_screen_chars(POS(renderer), template, 1);
charlen = 1;
break; break;
} }
default: default:
template->data = isscreensafe(data) ? data : '.';
}
copy_screen_chars(POS(renderer), template, 1);
}
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
goto end; if (utf8) {
utf_8: unicode_val_T data;
end = string + length; charlen = utf8charlen(text);
for (text = string; text < end; renderer->canvas_x++) { data = utf_8_to_unicode(&text, end);
unsigned char data = *text;
unicode_val_T d2;
/* This is mostly to be able to break out so the indentation template->data = (uint16_t)data;
* level won't get to high. */
switch (data) {
case ASCII_TAB:
{
int tab_width = 7 - (X(renderer) & 7);
int width = WIDTH(renderer, end - text + tab_width);
template->data = ' '; if (unicode_to_cell(data) == 2) {
copy_screen_chars(POS(renderer),
template, 1);
if (!realloc_line(document, width, Y(renderer))) X(renderer)++;
break; template->data = UCS_NO_CHAR;
}
/* Only loop over the expanded tab chars and let the } else
* ``main loop'' add the actual tab char. */ #endif /* CONFIG_UTF_8 */
for (; tab_width-- > 0; renderer->canvas_x++) template->data = isscreensafe(*text) ? *text:'.';
copy_screen_chars(POS(renderer), template, 1);
text++;
break;
}
default:
d2 = utf_8_to_unicode(&text, end);
if (d2 == UCS_NO_CHAR) text++;
template->data = (uint16_t)d2;
} }
copy_screen_chars(POS(renderer), template, 1); copy_screen_chars(POS(renderer), template, 1);
} }
end:
#endif /* CONFIG_UTF_8 */
mem_free(string); mem_free(string);
} }