diff --git a/src/bfu/dialog.c b/src/bfu/dialog.c index db63eeb87..67be711b3 100644 --- a/src/bfu/dialog.c +++ b/src/bfu/dialog.c @@ -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 diff --git a/src/bfu/menu.c b/src/bfu/menu.c index 2fefb7ff8..ad64712d3 100644 --- a/src/bfu/menu.c +++ b/src/bfu/menu.c @@ -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; diff --git a/src/terminal/draw.c b/src/terminal/draw.c index aa03e2375..f539f961b 100644 --- a/src/terminal/draw.c +++ b/src/terminal/draw.c @@ -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, diff --git a/src/terminal/draw.h b/src/terminal/draw.h index 77e34679d..2598cd908 100644 --- a/src/terminal/draw.h +++ b/src/terminal/draw.h @@ -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,