mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
Added better support for displaying double-width UTF-8 chars.
This commit is contained in:
parent
79d4d74a22
commit
b356da1850
@ -327,37 +327,53 @@ draw_text_utf8(struct terminal *term, int x, int y,
|
|||||||
|
|
||||||
data = utf_8_to_unicode(&text, end);
|
data = utf_8_to_unicode(&text, end);
|
||||||
if (data == UCS_NO_CHAR) return;
|
if (data == UCS_NO_CHAR) return;
|
||||||
start = get_char(term, x++, y);
|
start = get_char(term, x, y);
|
||||||
start->data = (uint16_t)data;
|
|
||||||
if (color) {
|
if (color) {
|
||||||
start->attr = attr;
|
start->attr = attr;
|
||||||
set_term_color(start, color, 0,
|
set_term_color(start, color, 0,
|
||||||
get_opt_int_tree(term->spec, "colors"));
|
get_opt_int_tree(term->spec, "colors"));
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = start + 1;
|
pos = start;
|
||||||
|
|
||||||
if (unicode_to_cell(data) == 2) {
|
if (unicode_to_cell(data) == 2) {
|
||||||
|
/* Is there enough room for whole double-width char? */
|
||||||
#ifdef CONFIG_DEBUG
|
if (x + 1 < term->width) {
|
||||||
/* Detect attempt to draw double-width char on the last
|
pos->data = data;
|
||||||
* collumn of terminal. */
|
pos++;
|
||||||
if (x+1 > term->width)
|
x++;
|
||||||
INTERNAL("Attempt to draw double-width character on "
|
|
||||||
"last collumn!!");
|
|
||||||
#endif /* CONFIG_DEBUG */
|
|
||||||
|
|
||||||
pos->data = UCS_NO_CHAR;
|
pos->data = UCS_NO_CHAR;
|
||||||
if (color) copy_screen_chars(pos, start, 1);
|
pos->attr = 0;
|
||||||
x++;
|
} else {
|
||||||
pos++;
|
pos->data = (unicode_val_T)' ';
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pos->data = data;
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
x++;
|
||||||
|
|
||||||
for (; x < term->width; x++, pos++) {
|
for (; x < term->width; x++, pos++) {
|
||||||
data = utf_8_to_unicode(&text, end);
|
data = utf_8_to_unicode(&text, end);
|
||||||
if (data == UCS_NO_CHAR) break;
|
if (data == UCS_NO_CHAR) break;
|
||||||
if (color) copy_screen_chars(pos, start, 1);
|
if (color) copy_screen_chars(pos, start, 1);
|
||||||
pos->data = (uint16_t)data;
|
|
||||||
|
if (unicode_to_cell(data) == 2) {
|
||||||
|
/* Is there enough room for whole double-width char? */
|
||||||
|
if (x + 1 < term->width) {
|
||||||
|
pos->data = data;
|
||||||
|
|
||||||
|
x++;
|
||||||
|
pos++;
|
||||||
|
pos->data = UCS_NO_CHAR;
|
||||||
|
pos->attr = 0;
|
||||||
|
} else {
|
||||||
|
pos->data = (unicode_val_T)' ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pos->data = data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set_screen_dirty(term->screen, y, y);
|
set_screen_dirty(term->screen, y, y);
|
||||||
|
|
||||||
|
@ -450,7 +450,12 @@ add_char_data(struct string *screen, struct screen_driver *driver,
|
|||||||
unsigned char data, unsigned char border)
|
unsigned char data, unsigned char border)
|
||||||
#endif /* CONFIG_UTF_8 */
|
#endif /* CONFIG_UTF_8 */
|
||||||
{
|
{
|
||||||
if (!isscreensafe(data)) {
|
if (
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
!use_utf8_io(driver) &&
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
!isscreensafe(data)
|
||||||
|
) {
|
||||||
add_char_to_string(screen, ' ');
|
add_char_to_string(screen, ' ');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -485,17 +490,32 @@ add_char16(struct string *screen, struct screen_driver *driver,
|
|||||||
unsigned char underline = (ch->attr & SCREEN_ATTR_UNDERLINE);
|
unsigned char underline = (ch->attr & SCREEN_ATTR_UNDERLINE);
|
||||||
unsigned char bold = (ch->attr & SCREEN_ATTR_BOLD);
|
unsigned char bold = (ch->attr & SCREEN_ATTR_BOLD);
|
||||||
|
|
||||||
if (border != state->border && driver->frame_seqs) {
|
if (
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
(!use_utf8_io(driver) || ch->data != UCS_NO_CHAR) &&
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
border != state->border && driver->frame_seqs
|
||||||
|
) {
|
||||||
state->border = border;
|
state->border = border;
|
||||||
add_term_string(screen, driver->frame_seqs[!!border]);
|
add_term_string(screen, driver->frame_seqs[!!border]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (underline != state->underline && driver->underline) {
|
if (
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
(!use_utf8_io(driver) || ch->data != UCS_NO_CHAR) &&
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
underline != state->underline && driver->underline
|
||||||
|
) {
|
||||||
state->underline = underline;
|
state->underline = underline;
|
||||||
add_term_string(screen, driver->underline[!!underline]);
|
add_term_string(screen, driver->underline[!!underline]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bold != state->bold) {
|
if (
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
(!use_utf8_io(driver) || ch->data != UCS_NO_CHAR) &&
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
bold != state->bold
|
||||||
|
) {
|
||||||
state->bold = bold;
|
state->bold = bold;
|
||||||
if (bold) {
|
if (bold) {
|
||||||
add_bytes_to_string(screen, "\033[1m", 4);
|
add_bytes_to_string(screen, "\033[1m", 4);
|
||||||
@ -505,7 +525,12 @@ add_char16(struct string *screen, struct screen_driver *driver,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compare_color(ch->color, state->color)) {
|
if (
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
(!use_utf8_io(driver) || ch->data != UCS_NO_CHAR) &&
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
!compare_color(ch->color, state->color)
|
||||||
|
) {
|
||||||
copy_color(state->color, ch->color);
|
copy_color(state->color, ch->color);
|
||||||
|
|
||||||
add_bytes_to_string(screen, "\033[0", 3);
|
add_bytes_to_string(screen, "\033[0", 3);
|
||||||
@ -607,7 +632,12 @@ add_char256(struct string *screen, struct screen_driver *driver,
|
|||||||
{
|
{
|
||||||
unsigned char attr_delta = (ch->attr ^ state->attr);
|
unsigned char attr_delta = (ch->attr ^ state->attr);
|
||||||
|
|
||||||
if (attr_delta) {
|
if (
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
(!use_utf8_io(driver) || ch->data != UCS_NO_CHAR) &&
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
attr_delta
|
||||||
|
) {
|
||||||
if ((attr_delta & SCREEN_ATTR_FRAME) && driver->frame_seqs) {
|
if ((attr_delta & SCREEN_ATTR_FRAME) && driver->frame_seqs) {
|
||||||
state->border = !!(ch->attr & SCREEN_ATTR_FRAME);
|
state->border = !!(ch->attr & SCREEN_ATTR_FRAME);
|
||||||
add_term_string(screen, driver->frame_seqs[state->border]);
|
add_term_string(screen, driver->frame_seqs[state->border]);
|
||||||
@ -630,7 +660,12 @@ add_char256(struct string *screen, struct screen_driver *driver,
|
|||||||
state->attr = ch->attr;
|
state->attr = ch->attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compare_color(ch->color, state->color)) {
|
if (
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
(!use_utf8_io(driver) || ch->data != UCS_NO_CHAR) &&
|
||||||
|
#endif /* CONFIG_UTF_8 */
|
||||||
|
!compare_color(ch->color, state->color)
|
||||||
|
) {
|
||||||
copy_color(state->color, ch->color);
|
copy_color(state->color, ch->color);
|
||||||
|
|
||||||
add_foreground_color(screen, color256_seqs, ch);
|
add_foreground_color(screen, color256_seqs, ch);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user