From 240b1475c7dac9d6cd722ca7237dc771037f5491 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 5 Feb 2018 00:04:05 +0530 Subject: [PATCH] Fix regression that caused a few ligatures to not render correctly in rare circumstances This was caused by cache corruption. is_special_glyph() and is_empty_glyph() were treading over each other if called in the right sequence. Fixes #303 --- kitty/fonts.c | 9 +++++---- kitty_tests/fonts.py | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 31cccea8f..3e61a6507 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -156,15 +156,16 @@ sprite_position_for(Font *font, glyph_index glyph, ExtraGlyphs *extra_glyphs, ui } static inline SpecialGlyphCache* -special_glyph_cache_for(Font *font, glyph_index glyph, uint8_t mask) { +special_glyph_cache_for(Font *font, glyph_index glyph, uint8_t filled_mask) { SpecialGlyphCache *s = font->special_glyph_cache + (glyph & 0x3ff); // Optimize for the common case of glyph under 1024 already in the cache - if (LIKELY(s->glyph == glyph && s->data & mask)) return s; // Cache hit + if (LIKELY(s->glyph == glyph && s->data & filled_mask)) return s; // Cache hit while(true) { - if (s->data & mask) { + if (s->data & filled_mask) { if (s->glyph == glyph) return s; // Cache hit } else { - break; + if (!s->glyph) break; // Empty cache slot + else if (s->glyph == glyph) return s; // Cache slot that contains other data than the data indicated by filled_mask } if (!s->next) { s->next = calloc(1, sizeof(SpecialGlyphCache)); diff --git a/kitty_tests/fonts.py b/kitty_tests/fonts.py index 662b496db..3d27b4e9d 100644 --- a/kitty_tests/fonts.py +++ b/kitty_tests/fonts.py @@ -78,6 +78,7 @@ class Rendering(BaseTest): self.ae(groups('abcd'), [(1, 1) for i in range(4)]) self.ae(groups('A=>>B!=C', path='kitty_tests/FiraCode-Medium.otf'), [(1, 1), (3, 3), (1, 1), (2, 2), (1, 1)]) + self.ae(groups('F--a--', path='kitty_tests/FiraCode-Medium.otf'), [(1, 1), (2, 2), (1, 1), (2, 2)]) self.ae(groups('==!=<>==<><><>', path='kitty_tests/FiraCode-Medium.otf'), [(2, 2), (2, 2), (2, 2), (2, 2), (2, 2), (2, 2), (2, 2)]) colon_glyph = shape_string('9:30', path='kitty_tests/FiraCode-Medium.otf')[1][2] self.assertNotEqual(colon_glyph, shape_string(':', path='kitty_tests/FiraCode-Medium.otf')[0][2])