From c1c0f11821e36e96add5060916d83533308b4126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 22 Nov 2021 23:02:25 +0100 Subject: [PATCH] config: add tweak.grapheme-width-method=max MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ‘max’ is a new value for ‘tweak.grapheme-width-method’. When enabled, the width of a grapheme cluster is that of the cluster’s widest codepoint. --- CHANGELOG.md | 5 +++++ config.c | 2 +- config.h | 6 +++++- doc/foot.ini.5.scd | 4 +++- vt.c | 4 ++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cffc2c25..a2255c08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,12 @@ ## Unreleased + ### Added + +* New value, `max`, for `[tweak].grapheme-width-method`. + + ### Changed ### Deprecated ### Removed diff --git a/config.c b/config.c index 68061cc3..0616e87a 100644 --- a/config.c +++ b/config.c @@ -2248,7 +2248,7 @@ parse_section_tweak(struct context *ctx) return value_to_enum( ctx, - (const char *[]){"wcswidth", "double-width", NULL}, + (const char *[]){"wcswidth", "double-width", "max", NULL}, (int *)&conf->tweak.grapheme_width_method); } diff --git a/config.h b/config.h index 652f8422..afe9cf74 100644 --- a/config.h +++ b/config.h @@ -256,7 +256,11 @@ struct config { enum fcft_scaling_filter fcft_filter; bool overflowing_glyphs; bool grapheme_shaping; - enum {GRAPHEME_WIDTH_WCSWIDTH, GRAPHEME_WIDTH_DOUBLE} grapheme_width_method; + enum { + GRAPHEME_WIDTH_WCSWIDTH, + GRAPHEME_WIDTH_DOUBLE, + GRAPHEME_WIDTH_MAX, + } grapheme_width_method; bool render_timer_osd; bool render_timer_log; bool damage_whole_window; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 9f5c429b..1b6c4d8c 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -1093,7 +1093,7 @@ any of these options. *grapheme-width-method* Selects which method to use when calculating the width (i.e. number of columns) of a grapheme cluster. One of - *double-width* and *wcswidth*. + *wcswidth*, *double-width* and *max*. *wcswidth* simply adds together the individual width of all codepoints making up the cluster. @@ -1104,6 +1104,8 @@ any of these options. internally to calculate the width. This results in cursor de-synchronization issues. + *max* uses the width of the largest codepoint in the cluster. + Default: _wcswidth_ *font-monospace-warn* diff --git a/vt.c b/vt.c index 687be912..736a2cfd 100644 --- a/vt.c +++ b/vt.c @@ -792,6 +792,10 @@ action_utf8_print(struct terminal *term, wchar_t wc) composed != NULL ? composed->width : base_width; switch (term->conf->tweak.grapheme_width_method) { + case GRAPHEME_WIDTH_MAX: + new_cc->width = max(grapheme_width, width); + break; + case GRAPHEME_WIDTH_DOUBLE: if (unlikely(wc == 0xfe0f)) width = 2;