diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-07-31 16:03:35 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-07-31 16:03:35 +0000 |
| commit | 858a0d9906a66f2eb9c2ffaf6d71e1153dad33f7 (patch) | |
| tree | f1ee47f7dd884924656727bf27976a56a8af9b60 /vt.c | |
| parent | vt: disable flash on bell, it's too annoying in e.g. zsh (diff) | |
font: initial support for double-width *and* color emoji glyphs
Fonts are now loaded with FT_LOAD_COLOR and we recognize and support
the FT_PIXEL_MODE_BGRA pixel mode.
This is mapped to a CAIRO_FORMAT_ARGB32 surface, that is blitted
as-is (instead of used as a mask like we do for gray and mono glyphs).
Furthermore, since many emojis are double-width, we add initial
support for double-width glyphs.
These are assumed to always be utf8. When PRINT:ing an utf8 character,
we check its width, and add empty "spacer" cells after the cell with
the multi-column glyph.
When rendering, we render the columns in each row backwards. This
ensures the spacer cells get cleared *before* we render the glyph (so
that we don't end up erasing part of the glyph).
Finally, emoji fonts are usually bitmap fonts with *large*
glyphs. These aren't automatically scaled down. I.e. even if we
request a glyph of 13 pixels, we might end up getting a 100px glyph.
To handle this, fontconfig must be configured to scale bitmap
fonts. When it is, we can look at the 'scalable' and 'pixelsizefixup'
properties, and use these to scale the rendered glyph.
Diffstat (limited to 'vt.c')
| -rw-r--r-- | vt.c | 34 |
1 files changed, 26 insertions, 8 deletions
@@ -691,6 +691,7 @@ pre_print(struct terminal *term) } } +#include <wchar.h> static inline void post_print(struct terminal *term) { @@ -721,12 +722,9 @@ action_print_utf8(struct terminal *term) struct row *row = term->grid->cur_row; struct cell *cell = &row->cells[term->cursor.col]; -#if 0 - term_damage_update(term, term->cursor.linear, 1); -#else + row->dirty = true; cell->attrs.clean = 0; -#endif print_insert(term); @@ -736,6 +734,29 @@ action_print_utf8(struct terminal *term) term->vt.utf8.idx = 0; cell->attrs = term->vt.attrs; + + /* Hack: zero- and double-width characters */ + mbstate_t ps = {0}; + wchar_t wc; + if (mbrtowc(&wc, cell->c, 4, &ps) >= 0) { + int width = wcwidth(wc); + if (width <= 0) { + /* Skip post_print() below - i.e. don't advance cursor */ + return; + } + + /* Advance cursor the 'additional' columns (last step is done + * by post_print()) */ + for (int i = 1; i < width && term->cursor.col < term->cols - 1; i++) { + term_cursor_right(term, 1); + + assert(term->cursor.col < term->cols); + struct cell *cell = &row->cells[term->cursor.col]; + cell->c[0] = '\0'; + cell->attrs.clean = 0; + } + } + post_print(term); } @@ -746,12 +767,9 @@ action_print(struct terminal *term, uint8_t c) struct row *row = term->grid->cur_row; struct cell *cell = &row->cells[term->cursor.col]; -#if 0 - term_damage_update(term, term->cursor.linear, 1); -#else + row->dirty = true; cell->attrs.clean = 0; -#endif print_insert(term); |
