From b71016c25dc18a2c098a87439046873c6c9ddb30 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 3 Sep 2020 17:37:44 +0200 Subject: render: optionally enable heuristics that deal with private usage area chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Try to detect double-width *glyphs* for single-width *characters*, and allow them to overflow into the next cell. This is only done for single-width chars with a glyph width that is at least 1.5 cells wide, but at most 3 cells. The feature is gated by the new ‘tweak.allow-overflowing-double-width-glyphs’, and is disabled by default. Closes #116 --- render.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 08caabc7..ea21b808 100644 --- a/render.c +++ b/render.c @@ -433,6 +433,31 @@ render_cell(struct terminal *term, pixman_image_t *pix, const int cols_left = term->cols - col; int cell_cols = glyph != NULL ? max(1, min(glyph->cols, cols_left)) : 1; + /* + * Hack! + * + * Deal with double-width glyphs for which wcwidth() returns + * 1. Typically Unicode private usage area characters, + * e.g. powerline, or nerd hack fonts. + * + * Users can enable a tweak option that lets this glyphs + * overflow/bleed into the neighbouring cell. + * + * We only apply this workaround if: + * - the user has explicitly enabled this feature + * - the *character* width is 1 + * - the *glyph* width is at least 1.5 cells + * - the *glyph* width is less than 3 cells + */ + if (term->conf->tweak.allow_overflowing_double_width_glyphs && + glyph != NULL && + glyph->cols == 1 && + glyph->width >= term->cell_width * 15 / 10 && + glyph->width < 3 * term->cell_width) + { + cell_cols = min(2, cols_left); + } + pixman_region32_t clip; pixman_region32_init_rect( &clip, x, y, -- cgit v1.3