mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05: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);
|
||||
if (data == UCS_NO_CHAR) return;
|
||||
start = get_char(term, x++, y);
|
||||
start->data = (uint16_t)data;
|
||||
start = get_char(term, x, y);
|
||||
if (color) {
|
||||
start->attr = attr;
|
||||
set_term_color(start, color, 0,
|
||||
get_opt_int_tree(term->spec, "colors"));
|
||||
}
|
||||
|
||||
pos = start + 1;
|
||||
pos = start;
|
||||
|
||||
if (unicode_to_cell(data) == 2) {
|
||||
/* Is there enough room for whole double-width char? */
|
||||
if (x + 1 < term->width) {
|
||||
pos->data = data;
|
||||
pos++;
|
||||
x++;
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
/* Detect attempt to draw double-width char on the last
|
||||
* collumn of terminal. */
|
||||
if (x+1 > term->width)
|
||||
INTERNAL("Attempt to draw double-width character on "
|
||||
"last collumn!!");
|
||||
#endif /* CONFIG_DEBUG */
|
||||
|
||||
pos->data = UCS_NO_CHAR;
|
||||
if (color) copy_screen_chars(pos, start, 1);
|
||||
x++;
|
||||
pos++;
|
||||
pos->data = UCS_NO_CHAR;
|
||||
pos->attr = 0;
|
||||
} else {
|
||||
pos->data = (unicode_val_T)' ';
|
||||
}
|
||||
} else {
|
||||
pos->data = data;
|
||||
}
|
||||
pos++;
|
||||
x++;
|
||||
|
||||
for (; x < term->width; x++, pos++) {
|
||||
data = utf_8_to_unicode(&text, end);
|
||||
if (data == UCS_NO_CHAR) break;
|
||||
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);
|
||||
|
||||
|
@ -450,7 +450,12 @@ add_char_data(struct string *screen, struct screen_driver *driver,
|
||||
unsigned char data, unsigned char border)
|
||||
#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, ' ');
|
||||
return;
|
||||
}
|
||||
@ -485,17 +490,32 @@ add_char16(struct string *screen, struct screen_driver *driver,
|
||||
unsigned char underline = (ch->attr & SCREEN_ATTR_UNDERLINE);
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
if (bold) {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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) {
|
||||
state->border = !!(ch->attr & SCREEN_ATTR_FRAME);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
add_foreground_color(screen, color256_seqs, ch);
|
||||
|
Loading…
x
Reference in New Issue
Block a user