diff options
author | pommicket <pommicket@gmail.com> | 2022-07-29 12:18:10 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-07-29 12:18:10 -0400 |
commit | 8b970f5b47ac14d6e55b0caf5cfe7890ca17d23b (patch) | |
tree | d9031142955670a84492448ca88108fac061626c /text.c | |
parent | d424dcbfd9586d5cf587e2cfb643e307b9d5e1bd (diff) |
fix syntax highlighting and spacing for weird characters
Diffstat (limited to 'text.c')
-rw-r--r-- | text.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -42,6 +42,7 @@ typedef struct { } TextTriangle; struct Font { + bool force_monospace; float char_width; // width of the character 'a'. calculated when font is loaded. float char_height; GLuint textures[CHAR_PAGE_COUNT]; @@ -220,6 +221,10 @@ Font *text_font_load(char const *ttf_filename, float font_size) { return font; } +void text_font_set_force_monospace(Font *font, bool force) { + font->force_monospace = force; +} + float text_font_char_height(Font *font) { return font->char_height; } @@ -280,11 +285,20 @@ top: } stbtt_bakedchar *char_data = font->char_pages[page]; float const char_height = font->char_height; + float const char_width = font->char_width; if (char_data) { // if page was successfully loaded stbtt_aligned_quad q = {0}; state->y += char_height * 0.75f; - stbtt_GetBakedQuad(char_data, font->tex_widths[page], font->tex_heights[page], - (int)index, &state->x, &state->y, &q, 1); + { + float x = state->x, y = state->y; + float *xp = &state->x, *yp = &state->y; + if (font->force_monospace) + xp = &x, yp = &y; + stbtt_GetBakedQuad(char_data, font->tex_widths[page], font->tex_heights[page], + (int)index, xp, yp, &q, 1); + if (font->force_monospace) + state->x += char_width; // ignore actual character width + } state->y -= char_height * 0.75f; float s0 = q.s0, t0 = q.t0; float s1 = q.s1, t1 = q.t1; |