From 67308f2ca1274745f1c30739538875cdd7e17dcd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 Jan 2018 11:35:25 +0530 Subject: [PATCH] Add some documentation for the shaping algorithm --- kitty/fonts.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index b20b42d91..08796ad4c 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -681,7 +681,19 @@ shape_run(Cell *first_cell, index_type num_cells, Font *font) { printf("\n%s\n", (char*)canvas); clear_canvas(); #endif - // Now distribute the glyphs into groups of cells + /* Now distribute the glyphs into groups of cells + * Considerations to keep in mind: + * Group sizes should be as small as possible for best performance + * Combining chars can result in multiple glyphs rendered into a single cell + * Emoji and East Asian wide chars can cause a single glyph to be rendered over multiple cells + * Ligature fonts, take two common approaches: + * 1. ABC becomes EMPTY, EMPTY, WIDE GLYPH this means we have to render N glyphs in N cells (example Fira Code) + * 2. ABC becomes WIDE GLYPH this means we have to render one glyph in N cells (example Operator Mono Lig) + * + * We rely on the cluster numbers from harfbuzz to tell us how many unicode codepoints a glyph corresponds to. + * Then we check if the glyph is a ligature glyph (is_special_glyph) and if it is an empty glyph. These three + * datapoints give us enough information to satisfy the constraint above, for a wide variety of fonts. + */ uint32_t cluster, next_cluster; bool add_to_current_group; #define G(x) (group_state.x)