From 62e07743194c8051334ed9b23be90ce31ab80773 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 3 May 2020 11:03:22 +0200 Subject: unicode-combining: store seen combining chains "globally" in the term struct Instead of storing combining data per cell, realize that most combinations are re-occurring and that there's lots of available space left in the unicode range, and store seen base+combining combinations chains in a per-terminal array. When we encounter a combining character, we first try to pre-compose, like before. If that fails, we then search for the current base+combining combo in the list of previously seen combinations. If not found there either, we allocate a new combo and add it to the list. Regardless, the result is an index into this array. We store this index, offsetted by COMB_CHARS_LO=0x40000000ul in the cell. When rendering, we need to check if the cell character is a plain character, or if it's a composed character (identified by checking if the cell character is >= COMB_CHARS_LO). Then we render the grapheme pretty much like before. --- grid.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'grid.c') diff --git a/grid.c b/grid.c index 522df101..51d76191 100644 --- a/grid.c +++ b/grid.c @@ -34,17 +34,10 @@ grid_row_alloc(int cols, bool initialize) if (initialize) { row->cells = calloc(cols, sizeof(row->cells[0])); -#if FOOT_UNICODE_MAX_COMBINING_CHARS > 0 - row->comb_chars = calloc(cols, sizeof(row->comb_chars[0])); -#endif for (size_t c = 0; c < cols; c++) row->cells[c].attrs.clean = 1; - } else { + } else row->cells = malloc(cols * sizeof(row->cells[0])); -#if FOOT_UNICODE_MAX_COMBINING_CHARS > 0 - row->comb_chars = malloc(cols * sizeof(row->comb_chars[0])); -#endif - } return row; } @@ -55,9 +48,6 @@ grid_row_free(struct row *row) if (row == NULL) return; -#if FOOT_UNICODE_MAX_COMBINING_CHARS > 0 - free(row->comb_chars); -#endif free(row->cells); free(row); } @@ -214,17 +204,6 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, new_row->cells[new_col_idx] = *old_cell; new_row->cells[new_col_idx].attrs.clean = 1; -#if FOOT_UNICODE_MAX_COMBINING_CHARS > 0 - struct combining_chars *old_comb_chars - = &old_row->comb_chars[c - empty_count + i]; - struct combining_chars *new_comb_chars - = &new_row->comb_chars[new_col_idx]; - - new_comb_chars->count = old_comb_chars->count; - for (size_t j = 0; j < ALEN(new_comb_chars->chars); j++) - new_comb_chars->chars[j] = old_comb_chars->chars[j]; -#endif - /* Translate tracking point(s) */ if (is_tracking_point && i >= empty_count) { tll_foreach(tracking_points, it) { -- cgit v1.3