From 404ca23de3755081b8d5c8323713d1c076d8a066 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 Jan 2018 09:14:46 +0530 Subject: [PATCH] Make handling of last glyph a little more intelligent --- kitty/fonts.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 5d0dacc7a..f808e0206 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -701,16 +701,20 @@ shape_run(Cell *first_cell, index_type num_cells, Font *font) { current_group->first_glyph_idx = G(glyph_idx); current_group->first_cell_idx = G(cell_idx); } +#define MOVE_GLYPH_TO_NEXT_GROUP(start_cell_idx) { \ + current_group->num_glyphs--; \ + G(group_idx)++; current_group = G(groups) + G(group_idx); \ + current_group->first_cell_idx = start_cell_idx; \ + current_group->num_glyphs = 1; \ + current_group->first_glyph_idx = G(glyph_idx); \ +} if (is_last_glyph) { // soak up all remaining cells - while (G(cell_idx) < G(num_cells)) { - while(current_group->num_cells < MAX_GLYPHS_IN_GROUP && G(cell_idx) < G(num_cells)) { - current_group->num_cells++; - G(cell_idx)++; - } - G(group_idx)++; current_group = G(groups) + G(group_idx); - current_group->first_cell_idx = G(cell_idx); - current_group->num_glyphs = 1; + if (G(cell_idx) < G(num_cells)) { + unsigned int num_left = G(num_cells) - G(cell_idx); + if (current_group->num_cells + num_left > MAX_GLYPHS_IN_GROUP) MOVE_GLYPH_TO_NEXT_GROUP(G(cell_idx)); + current_group->num_cells += num_left; + G(cell_idx) += num_left; } } else { unsigned int num_cells_consumed = 0, start_cell_idx = G(cell_idx); @@ -721,13 +725,7 @@ shape_run(Cell *first_cell, index_type num_cells, Font *font) { num_codepoints_used_by_glyph--; } if (num_cells_consumed) { - if (num_cells_consumed + current_group->num_cells > MAX_GLYPHS_IN_GROUP) { - current_group->num_glyphs--; - G(group_idx)++; current_group = G(groups) + G(group_idx); - current_group->first_glyph_idx = G(glyph_idx); - current_group->first_cell_idx = start_cell_idx; - current_group->num_glyphs = 1; - } + if (num_cells_consumed + current_group->num_cells > MAX_GLYPHS_IN_GROUP) MOVE_GLYPH_TO_NEXT_GROUP(start_cell_idx); current_group->num_cells += num_cells_consumed; if (!is_special) { // not a ligature, end the group G(group_idx)++; current_group = G(groups) + G(group_idx); @@ -739,6 +737,7 @@ shape_run(Cell *first_cell, index_type num_cells, Font *font) { G(previous_cluster) = cluster; G(glyph_idx)++; } +#undef MOVE_GLYPH_TO_NEXT_GROUP #undef MAX_GLYPHS_IN_GROUP }