From b1b32152c182fdb0b9494e75acb605d0486e30fa Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 8 May 2020 23:36:33 +0200 Subject: unicode-precompose: use fcft's precompose functionality This allows us more options when determining whether to use a pre-composed character or not: We now only use the pre-composed character if it's from the primary font, or if at least one of the base or combining characters are from a fallback font. I.e. use glyphs from the primary font if possible. But, if one or more of the decomposed glyphs are from a fallback font, use the pre-composed character anyway. --- vt.c | 61 +++++++++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'vt.c') diff --git a/vt.c b/vt.c index 157f7a9c..9c639431 100644 --- a/vt.c +++ b/vt.c @@ -14,10 +14,6 @@ #include "osc.h" #include "util.h" -#if FOOT_UNICODE_PRECOMPOSE - #include "unicode-compose-table.h" -#endif - #define UNHANDLED() LOG_DBG("unhandled: %s", esc_as_string(term, final)) /* https://vt100.net/emu/dec_ansi_parser */ @@ -527,36 +523,6 @@ action_utf8_4_entry(struct terminal *term, uint8_t c) term->vt.utf8.data[term->vt.utf8.idx++] = c; } -#if FOOT_UNICODE_PRECOMPOSE -static wchar_t -precompose(wchar_t base, wchar_t comb) -{ - static_assert(2 * sizeof(wchar_t) <= sizeof(uint64_t), - "two wchars does not fit in an uint64_t"); - - const uint64_t match = (uint64_t)base << 32 | comb; - - ssize_t start = 0; - ssize_t end = ALEN(precompose_table) - 1; - - while (start <= end) { - size_t middle = (start + end) / 2; - - const uint64_t maybe = - (uint64_t)precompose_table[middle].base << 32 | precompose_table[middle].comb; - - if (maybe < match) - start = middle + 1; - else if (maybe > match) - end = middle - 1; - else - return precompose_table[middle].replacement; - } - - return (wchar_t)-1; -} -#endif - static void action_utf8_print(struct terminal *term, uint8_t c) { @@ -631,9 +597,32 @@ action_utf8_print(struct terminal *term, uint8_t c) #if FOOT_UNICODE_PRECOMPOSE if (composed == NULL) { - wchar_t precomposed = precompose(base, wc); + bool base_from_primary; + bool comb_from_primary; + bool pre_from_primary; + + wchar_t precomposed = fcft_precompose( + term->fonts[0], base, wc, &base_from_primary, + &comb_from_primary, &pre_from_primary); + int precomposed_width = wcwidth(precomposed); - if (precomposed != (wchar_t)-1 && precomposed_width == base_width) { + + /* + * Only use the pre-composed character if: + * + * 1. we *have* a pre-composed character + * 2. the width matches the base characters width + * 3. it's in the primary font, OR one of the base or + * combining characters are *not* from the primary + * font + */ + + if (precomposed != (wchar_t)-1 && + precomposed_width == base_width && + (pre_from_primary || + !base_from_primary || + !comb_from_primary)) + { term_print(term, precomposed, precomposed_width); return; } -- cgit v1.3 From 00df12f1a3cfee6c0f876f4e082ce3efbeba0bda Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 10 May 2020 17:10:33 +0200 Subject: unicode-combine: simplify - remove -Dunicode-precompose option Since the pre-composing functionality is now part of fcft, it makes little sense to have a compile time option - there's no size benefit to be had. Furthermore, virtually all terminal emulators do pre-composing (alacritty being an exception), this really isn't that controversial. --- CHANGELOG.md | 4 +--- README.md | 28 ---------------------------- meson.build | 15 ++++++--------- meson_options.txt | 2 -- vt.c | 2 -- 5 files changed, 7 insertions(+), 44 deletions(-) delete mode 100644 meson_options.txt (limited to 'vt.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c2e7c68..e763f6dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,9 +22,7 @@ * Right mouse button extends the current selection. * `CSI Ps ; Ps ; Ps t` escape sequences for the following parameters: `11t`, `13t`, `13;2t`, `14t`, `14;2t`, `15t`, `19t`. -* Unicode combining characters. Parts of this feature are compile time - optional. See [README.md](README.md#user-content-unicode-combining) - for details. +* Unicode combining characters. ### Changed diff --git a/README.md b/README.md index 08a9fdb1..b55dd8aa 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ The fast, lightweight and minimalistic Wayland terminal emulator. 1. [Backspace](#backspace) 1. [DPI and font size](#dpi-and-font-size) 1. [Supported OSCs](#supported-oscs) -1. [Unicode combining](#unicode-combining) 1. [Requirements](#requirements) 1. [Running](#running) 1. [Building](#building) @@ -269,33 +268,6 @@ with the terminal emulator itself. Foot implements the following OSCs: * `OSC 555` - flash screen (**foot specific**) -## Unicode combining - -When the client prints Unicode combining characters, e.g `a\\u0308` -('a' + `COMBINING DIAERESIS`), foot will be default try to create a -pre-composed character. For example, `\\u0061\\u0308` (`a\\u0308`) -will be transformed into `\\u00e5` (`å`). - -This is to improve the looks of the rendered grapheme. When rendering -a decomposed string, `a\\u0308`, the glyphs for `a` and `\\u0308` are -rendered independently, on top off each other. The result if often not -optimal, with e.g. diacritics looking a bit out of place. If we are -really unlucky, the base character and the combining characters may be -picked from different fonts, making the result look even more awkward. - -When rendering a pre-composed character, we are rendering a single -glyph only and thus it is guaranteed to look the way the font designer -intended it to. - -Note that foot currently will choose to render the decomposed form -**if** the pre-composed character **does not** exist in the primary -font, **and** both the decomposed characters **do**. In all other -cases, the pre-composed character is preferred. - -Still, if you do not want this, you can disable pre-composing at -**compile time** with `-Dunicode-precompose=false`. - - ## Requirements ### Running diff --git a/meson.build b/meson.build index 6d02b38f..83df931a 100644 --- a/meson.build +++ b/meson.build @@ -58,9 +58,6 @@ wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') xkb = dependency('xkbcommon') -add_project_arguments('-DFOOT_UNICODE_PRECOMPOSE=@0@'.format( - get_option('unicode-precompose')), language: 'c') - tllist = dependency('tllist', version: '>=1.0.1', fallback: 'tllist') fcft = dependency('fcft', version: ['>=2.1.0', '<3.0.0'], fallback: 'fcft') @@ -153,9 +150,9 @@ install_data('footrc', install_dir: join_paths(get_option('datadir'), 'foot')) subdir('completions') subdir('doc') -summary( - { - 'Unicode precompose': get_option('unicode-precompose'), - }, - bool_yn: true -) +# summary( +# { +# '': false, +# }, +# bool_yn: true +# ) diff --git a/meson_options.txt b/meson_options.txt deleted file mode 100644 index 5052f66c..00000000 --- a/meson_options.txt +++ /dev/null @@ -1,2 +0,0 @@ -option('unicode-precompose', type: 'boolean', value: true, - description: 'Convert decomposed characters to precomposed. Ignored if "unicode-combining" has been disabled') diff --git a/vt.c b/vt.c index 9c639431..d80a7d86 100644 --- a/vt.c +++ b/vt.c @@ -595,7 +595,6 @@ action_utf8_print(struct terminal *term, uint8_t c) term->grid->cursor.point.col = base_col; term->grid->cursor.lcf = false; -#if FOOT_UNICODE_PRECOMPOSE if (composed == NULL) { bool base_from_primary; bool comb_from_primary; @@ -627,7 +626,6 @@ action_utf8_print(struct terminal *term, uint8_t c) return; } } -#endif size_t wanted_count = composed != NULL ? composed->count + 1 : 1; if (wanted_count > ALEN(composed->combining)) { -- cgit v1.3