From 1db4286a12a0c09f1299a5b825f90544f8afcf48 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 5 Nov 2017 06:22:11 +0530 Subject: [PATCH] Fix rendering of wide chars --- kitty/fonts.c | 5 ++++- kitty/fonts/render.py | 7 ++++--- kitty/freetype.c | 1 - 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index c42be1d6f..ce184eb6d 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -367,8 +367,11 @@ load_hb_buffer(Cell *first_cell, index_type num_cells) { index_type num; hb_buffer_clear_contents(harfbuzz_buffer); while (num_cells) { + attrs_type prev_width = 0; for (num = 0; num_cells && num < sizeof(shape_buffer)/sizeof(shape_buffer[0]) - 20; first_cell++, num_cells--) { + if (prev_width == 2) { prev_width = 0; continue; } shape_buffer[num++] = first_cell->ch; + prev_width = first_cell->attrs & WIDTH_MASK; if (first_cell->cc) { shape_buffer[num++] = first_cell->cc & CC_MASK; combining_type cc2 = first_cell->cc >> 16; @@ -512,7 +515,7 @@ render_line(Line *line) { index_type first_cell_in_run, i; attrs_type prev_width = 0; for (i=0, first_cell_in_run=0; i < line->xnum; i++) { - if (prev_width == 2) continue; + if (prev_width == 2) { prev_width = 0; continue; } Cell *cell = line->cells + i; Font *cell_font = NULL; FontType cell_font_type = font_for_cell(cell, &cell_font); diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index 0585faa59..613add3c3 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -207,11 +207,12 @@ def test_render_string(text='Hello, world!', family='monospace', size=144.0, dpi rgb_data = concat_cells(cell_width, cell_height, tuple(cells)) with NamedTemporaryFile(delete=False) as f: f.write(rgb_data) - print('Rendered string {!r} below: ({}x{})'.format(text, cell_width, cell_height)) + print('Rendered string {!r} below, with font: {}'.format(text, family)) show(f.name, cell_width * len(cells), cell_height, 24) print('\n') def showcase(): - test_render_string(family='Fira Code Medium') - test_render_string('==A=== -> -->', family='Fira Code Medium') + test_render_string('He\u0347\u0305llo\u0341, w\u0302or\u0306l\u0354d!', family='Consolas') + test_render_string('你好,世界') + test_render_string('A=>>B!=C', family='Fira Code Medium') diff --git a/kitty/freetype.c b/kitty/freetype.c index 81fe625d9..114df1b4b 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -297,7 +297,6 @@ render_glyphs_in_cells(PyObject *f, bool bold, bool italic, hb_glyph_info_t *inf float x = 0.f, y = 0.f, x_offset = 0.f; ProcessedBitmap bm; for (unsigned int i = 0; i < num_glyphs; i++) { - if (info[i].codepoint == 0) continue; if (!render_bitmap(self, info[i].codepoint, &bm, cell_width, num_cells, bold, italic, true)) return false; x_offset = x + (float)positions[i].x_offset / 64.0f; y = (float)positions[i].y_offset / 64.0f;