From 4c954be7a6d86b21da512fc533eb3362ac737221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 31 May 2021 17:10:05 +0200 Subject: [PATCH] config: add boolean option tweak.pua-double-width When enabled, PUA (Private Usage Area) codepoints are always treated as double-width glyphs, regardless of the actual glyph width. Requires allow-overflowing-double-width-glyphs=yes --- CHANGELOG.md | 3 +++ config.c | 7 +++++++ config.h | 1 + doc/foot.ini.5.scd | 14 +++++++++++++- render.c | 18 +++++++++++------- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d8e604a..5fe9b236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,9 @@ (https://codeberg.org/dnkl/foot/issues/555). * `ENVIRONMENT` section in **foot**(1) and **footclient**(1) man pages (https://codeberg.org/dnkl/foot/issues/556). +* `tweak.pua-double-width` option to `foot.ini`, letting you force + _Private Usage Area_ codepoints to be treated as double-width + characters. ### Changed diff --git a/config.c b/config.c index 92ef0c99..17d6ce5f 100644 --- a/config.c +++ b/config.c @@ -2005,6 +2005,12 @@ parse_section_tweak( LOG_WARN("tweak: disabled overflowing double-width glyphs"); } + else if (strcmp(key, "pua-double-width") == 0) { + conf->tweak.pua_double_width = str_to_bool(value); + if (conf->tweak.pua_double_width) + LOG_WARN("tweak: PUA double width glyphs enabled"); + } + else if (strcmp(key, "damage-whole-window") == 0) { conf->tweak.damage_whole_window = str_to_bool(value); if (conf->tweak.damage_whole_window) @@ -2573,6 +2579,7 @@ config_load(struct config *conf, const char *conf_path, .damage_whole_window = false, .box_drawing_base_thickness = 0.04, .box_drawing_solid_shades = true, + .pua_double_width = false, }, .notifications = tll_init(), diff --git a/config.h b/config.h index 95083e6c..f5e20879 100644 --- a/config.h +++ b/config.h @@ -237,6 +237,7 @@ struct config { off_t max_shm_pool_size; float box_drawing_base_thickness; bool box_drawing_solid_shades; + bool pua_double_width; } tweak; user_notifications_t notifications; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index d9b61c39..e434c84b 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -826,7 +826,7 @@ any of these options. Default: _lanczos3_. *allow-overflowing-double-width-glyphs* - Boolean. when enabled, double width glyphs with a character width + Boolean. When enabled, double width glyphs with a character width of 1 are allowed to overflow into the neighbouring cell. One use case for this is fonts "icon" characters in the Unicode @@ -839,8 +839,20 @@ any of these options. Note: this feature uses _heuristics_ to determine *which* glyphs should be allowed to overflow. + See also: *pua-double-width* + Default: _yes_. +*pua-double-width* + Boolean. When enabled, Unicode code points from the private usage + area (PUA) are always considered to be double width, regardless of + the actual glyph width. + + Ignored if *allow-overflowing-double-width-glyphs* has been + disabled. + + Default: _no_. + *render-timer* Enables a frame rendering timer, that prints the time it takes to render each frame, in microseconds, either on-screen, to stderr, diff --git a/render.c b/render.c index 5ca64738..d66058c8 100644 --- a/render.c +++ b/render.c @@ -499,9 +499,9 @@ render_cell(struct terminal *term, pixman_image_t *pix, const struct fcft_glyph *glyph = NULL; const struct composed *composed = NULL; - if (cell->wc != 0) { - wchar_t base = cell->wc; + wchar_t base = cell->wc; + if (base != 0) { if (base >= CELL_COMB_CHARS_LO && base < (CELL_COMB_CHARS_LO + term->composed_count)) { @@ -576,11 +576,15 @@ render_cell(struct terminal *term, pixman_image_t *pix, * - *this* cells is followed by an empty cell, or a space */ 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 && - col < term->cols - 1 && + ((glyph != NULL && + glyph->cols == 1 && + glyph->width >= term->cell_width * 15 / 10 && + glyph->width < 3 * term->cell_width && + col < term->cols - 1) || + (term->conf->tweak.pua_double_width && + ((base >= 0x00e000 && base <= 0x00f8ff) || + (base >= 0x0f0000 && base <= 0x0ffffd) || + (base >= 0x100000 && base <= 0x10fffd)))) && (row->cells[col + 1].wc == 0 || row->cells[col + 1].wc == L' ')) { cell_cols = 2;