Commit: 6fbdb285997f8f06f5c15c25e2260e5b7ca65539
Parent: cb9aaf27887bb9bd183b5284bc168032bde0eda3
Author: Randy Palamar
Date: Sun, 1 Sep 2024 16:53:29 -0600
use freetypes face metrics for computing global font metrics
Diffstat:
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -6,7 +6,7 @@ static char *g_fonts[] = {
/* NOTE: terminal padding in pixels */
static v2 g_term_pad = {.w = 8, .h = 8};
/* NOTE: cell padding in pixels (glyphs will be centered) */
-static v2 g_cell_pad = {.w = 0, .h = 6};
+static v2 g_cell_pad = {.w = 0, .h = 2};
static u8 g_tabstop = 8;
diff --git a/font.c b/font.c
@@ -215,18 +215,16 @@ render_glyph(FontAtlas *fa, u32 cp, Glyph *out_glyph, u32 *out_idx)
static void
update_font_metrics(FontAtlas *fa)
{
- fa->size.h = 0;
- fa->size.w = 0;
- fa->deltay = 0;
+ /* NOTE: use FreeType's face metrics to compute sizes; the format is 26.6
+ * fixed point and we are choosing to ignore the fractional portion */
+ fa->size.h = fa->fonts[0].face->size->metrics.height >> 6;
+ fa->size.w = fa->fonts[0].face->size->metrics.max_advance >> 6;
+ fa->deltay = -(fa->fonts[0].face->size->metrics.descender >> 6);
+
+ /* NOTE: ' ' has 0 size in freetype but we need it to have a width! */
+ /* TODO: technically this is a hack which assumes that ' ' will always be in the cache */
Glyph g;
u32 index;
- for (u32 i = ' '; i <= '~'; i++) {
- render_glyph(fa, i, &g, &index);
- fa->size.h = MAX(fa->size.h, g.size.h);
- fa->size.w = MAX(fa->size.w, g.size.w);
- fa->deltay = MAX(fa->deltay, -g.delta.y);
- }
- /* NOTE: ' ' has 0 size in freetype but we need it to have a width! */
render_glyph(fa, ' ', &g, &index);
fa->glyph_cache.glyphs[index].g.size.w = fa->size.w;
}