mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-29 07:58:01 -04:00
vt: cache grapheme cluster width in composed struct
* Use regular wcswidth() to calculate the width * Explicitly set to ‘2’ if we see a emoji variant selector * Cache the result in the composed struct
This commit is contained in:
parent
b9ef703eb1
commit
0a9531ac6c
3 changed files with 11 additions and 12 deletions
|
|
@ -87,6 +87,7 @@ struct damage {
|
||||||
struct composed {
|
struct composed {
|
||||||
wchar_t chars[20];
|
wchar_t chars[20];
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
|
int width;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct row_uri_range {
|
struct row_uri_range {
|
||||||
|
|
|
||||||
8
util.h
8
util.h
|
|
@ -35,11 +35,3 @@ sdbm_hash(const char *s)
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <wchar.h>
|
|
||||||
static inline int
|
|
||||||
my_wcswidth(const wchar_t *s, size_t n)
|
|
||||||
{
|
|
||||||
int ret = wcswidth(s, n);
|
|
||||||
return max(0, ret);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
14
vt.c
14
vt.c
|
|
@ -716,9 +716,8 @@ action_utf8_print(struct terminal *term, wchar_t wc)
|
||||||
if (cc->chars[wanted_count - 1] != wc)
|
if (cc->chars[wanted_count - 1] != wc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int grapheme_width = my_wcswidth(cc->chars, cc->count);
|
if (cc->width > 0)
|
||||||
if (grapheme_width > 0)
|
term_print(term, CELL_COMB_CHARS_LO + i, cc->width);
|
||||||
term_print(term, CELL_COMB_CHARS_LO + i, grapheme_width);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -732,11 +731,18 @@ action_utf8_print(struct terminal *term, wchar_t wc)
|
||||||
new_cc.chars[wanted_count - 1] = wc;
|
new_cc.chars[wanted_count - 1] = wc;
|
||||||
|
|
||||||
if (term->composed_count < CELL_COMB_CHARS_HI) {
|
if (term->composed_count < CELL_COMB_CHARS_HI) {
|
||||||
|
/* TODO: grapheme cluster width */
|
||||||
|
int grapheme_width = wcswidth(new_cc.chars, new_cc.count);
|
||||||
|
if (new_cc.chars[new_cc.count - 1] == 0xfe0f) {
|
||||||
|
/* Emoji selector */
|
||||||
|
grapheme_width = 2;
|
||||||
|
}
|
||||||
|
new_cc.width = grapheme_width;
|
||||||
|
|
||||||
term->composed_count++;
|
term->composed_count++;
|
||||||
term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));
|
term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));
|
||||||
term->composed[term->composed_count - 1] = new_cc;
|
term->composed[term->composed_count - 1] = new_cc;
|
||||||
|
|
||||||
int grapheme_width = my_wcswidth(new_cc.chars, new_cc.count);
|
|
||||||
if (grapheme_width > 0)
|
if (grapheme_width > 0)
|
||||||
term_print(term, CELL_COMB_CHARS_LO + term->composed_count - 1, grapheme_width);
|
term_print(term, CELL_COMB_CHARS_LO + term->composed_count - 1, grapheme_width);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue