mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Fix broken double-width chars when displaying menu or dialog.
This commit is contained in:
parent
69a1c40fbd
commit
c8a6a4c44d
@ -639,7 +639,15 @@ draw_dialog(struct dialog_data *dlg_data, int width, int height)
|
||||
/* Draw shadow */
|
||||
draw_shadow(term, &dlg_data->box,
|
||||
get_bfu_color(term, "dialog.shadow"), 2, 1);
|
||||
#ifdef CONFIG_UTF_8
|
||||
if (term->utf8)
|
||||
fix_dwchar_around_box(term, &dlg_data->box, 0, 2, 1);
|
||||
#endif /* CONFIG_UTF_8 */
|
||||
}
|
||||
#ifdef CONFIG_UTF_8
|
||||
else if(term->utf8)
|
||||
fix_dwchar_around_box(term, &dlg_data->box, 0, 0, 0);
|
||||
#endif /* CONFIG_UTF_8 */
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -518,7 +518,15 @@ display_menu(struct terminal *term, struct menu *menu)
|
||||
/* Draw shadow */
|
||||
draw_shadow(term, &menu->box,
|
||||
get_bfu_color(term, "dialog.shadow"), 2, 1);
|
||||
#ifdef CONFIG_UTF_8
|
||||
if (term->utf8)
|
||||
fix_dwchar_around_box(term, &box, 1, 2, 1);
|
||||
#endif /* CONFIG_UTF_8 */
|
||||
}
|
||||
#ifdef CONFIG_UTF_8
|
||||
else if(term->utf8)
|
||||
fix_dwchar_around_box(term, &box, 1, 0, 0);
|
||||
#endif /* CONFIG_UTF_8 */
|
||||
|
||||
menu_height = box.height;
|
||||
box.height = 1;
|
||||
|
@ -246,6 +246,77 @@ draw_border(struct terminal *term, struct box *box,
|
||||
set_screen_dirty(term->screen, borderbox.y, borderbox.y + borderbox.height);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_UTF_8
|
||||
/* Checks cells left and right to the box for broken double-width chars.
|
||||
* Replace it with ' '.
|
||||
* 1+---+3
|
||||
* 1|box|##4
|
||||
* 1| |##4
|
||||
* 1| |##4
|
||||
* 1+---+##4
|
||||
* 2#####4
|
||||
* 1,2,3,4 - needs to be checked, # - shadow , +,-,| - border
|
||||
*/
|
||||
void
|
||||
fix_dwchar_around_box(struct terminal *term, struct box *box, int border,
|
||||
int shadow_width, int shadow_height)
|
||||
{
|
||||
struct screen_char *schar;
|
||||
int height, x, y;
|
||||
|
||||
if (!term->utf8)
|
||||
return;
|
||||
|
||||
/* 1 */
|
||||
x = box->x - border - 1;
|
||||
if (x > 0) {
|
||||
y = box->y - border;
|
||||
height = box->height + 2 * border;
|
||||
|
||||
schar = get_char(term, x, y);
|
||||
for (;height--; schar += term->width)
|
||||
if (unicode_to_cell(schar->data) == 2)
|
||||
schar->data = ' ';
|
||||
}
|
||||
|
||||
/* 2 */
|
||||
x = box->x - border + shadow_width - 1;
|
||||
if (x > 0 && x < term->width) {
|
||||
y = box->y + border + box->height;
|
||||
height = shadow_height;
|
||||
|
||||
schar = get_char(term, x, y);
|
||||
for (;height--; schar += term->width)
|
||||
if (unicode_to_cell(schar->data) == 2)
|
||||
schar->data = ' ';
|
||||
}
|
||||
|
||||
/* 3 */
|
||||
x = box->x + box->width + border;
|
||||
if (x < term->width) {
|
||||
y = box->y - border;
|
||||
height = shadow_height;
|
||||
|
||||
schar = get_char(term, x, y);
|
||||
for (;height--; schar += term->width)
|
||||
if (schar->data == UCS_NO_CHAR)
|
||||
schar->data = ' ';
|
||||
}
|
||||
|
||||
/* 4 */
|
||||
x = box->x + box->width + border + shadow_width;
|
||||
if (x < term->width) {
|
||||
y = box->y - border + shadow_height;
|
||||
height = box->height + 2 * border;
|
||||
|
||||
schar = get_char(term, x, y);
|
||||
for (;height--; schar += term->width)
|
||||
if (schar->data == UCS_NO_CHAR)
|
||||
schar->data = ' ';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_UTF_8
|
||||
void
|
||||
draw_char(struct terminal *term, int x, int y,
|
||||
|
@ -246,6 +246,11 @@ void draw_shadow(struct terminal *term, struct box *box,
|
||||
void draw_border(struct terminal *term, struct box *box,
|
||||
struct color_pair *color, int width);
|
||||
|
||||
#ifdef CONFIG_UTF_8
|
||||
void fix_dwchar_around_box(struct terminal *term, struct box *box, int border,
|
||||
int shadow_width, int shadow_height);
|
||||
#endif /* CONFIG_UTF_8 */
|
||||
|
||||
/* Draws @length chars from @text. */
|
||||
void draw_text(struct terminal *term, int x, int y,
|
||||
unsigned char *text, int length,
|
||||
|
Loading…
Reference in New Issue
Block a user