Fix rendering of wide chars

This commit is contained in:
Kovid Goyal 2017-11-05 06:22:11 +05:30
parent 4234a9d963
commit 1db4286a12
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 5 deletions

View File

@ -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);

View File

@ -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')

View File

@ -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;