vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: a06b563b61a7d24a15141e317536925bf9be8167
Parent: cf566d9520dd9278f38630d5a83474592abb5d0d
Author: Randy Palamar
Date:   Thu, 17 Oct 2024 11:38:07 -0600

fix glyph rendering with bolding/italics in certain cases

When the previous font in the list did not have the correct style
all further fonts would assume the style was normal. This should
now be fixed.

Also the style is stored directly in the highest 8 bits in the
cached codepoint instead of the less readable thing that was
there.

Diffstat:
Mfont.c | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/font.c b/font.c @@ -127,7 +127,7 @@ render_glyph(Arena *a, FontAtlas *fa, u32 cp, enum face_style style, CachedGlyph /* NOTE: first check if glyph is in the cache and valid */ /* NOTE: 8 MSB are not used for UTF8 so we can use that to store the style of the glyph */ - u32 idx = get_glyph_entry_index(&fa->glyph_cache, cp|(1 << (30 - style))); + u32 idx = get_glyph_entry_index(&fa->glyph_cache, cp|((u32)style << 24)); CachedGlyph *cg = fa->glyph_cache.glyphs + idx; *out_idx = idx; @@ -138,9 +138,10 @@ render_glyph(Arena *a, FontAtlas *fa, u32 cp, enum face_style style, CachedGlyph i32 glyph_idx = 0; i32 font_idx = 0; for (u32 i = 0; i < fa->nfonts; i++) { - if (!fa->fonts[i][style].buf) - style = FS_NORMAL; - glyph_idx = stbtt_FindGlyphIndex(&fa->fonts[i][style].font_info, cp); + u32 test_style = style; + if (!fa->fonts[i][test_style].buf) + test_style = FS_NORMAL; + glyph_idx = stbtt_FindGlyphIndex(&fa->fonts[i][test_style].font_info, cp); if (!glyph_idx) glyph_idx = stbtt_FindGlyphIndex(&fa->fonts[i][FS_NORMAL].font_info, cp); if (glyph_idx) {