diff --git a/src/font_render_lcd.h b/src/font_render_lcd.h index d8ab9df2..072ebb7b 100644 --- a/src/font_render_lcd.h +++ b/src/font_render_lcd.h @@ -68,6 +68,14 @@ public: return false; } + float scale_for_em_to_pixels(float size) { + int units_per_em = m_feng.face_units_em(); + if (units_per_em > 0) { + return size / units_per_em; + } + return 0.0; + } + bool load_font(const char *font_filename) { if(m_feng.load_font(font_filename, 0, agg::glyph_ren_outline)) { m_font_loaded = true; diff --git a/tests/agg_font_render_test.cpp b/tests/agg_font_render_test.cpp index 4dd1cba0..bcd1668e 100644 --- a/tests/agg_font_render_test.cpp +++ b/tests/agg_font_render_test.cpp @@ -66,9 +66,11 @@ RenFontA* ren_load_font_agg(const char *filename, float size) { font->renderer->get_font_vmetrics(ascender, descender); fprintf(stderr, "Font metrics ascender: %d descender: %d\n", ascender, descender); - // FIXME: figure out correct calculation for font->height with - // ascent, descent and linegap. - font->height = size; + float scale = font->renderer->scale_for_em_to_pixels(size); + font->height = (ascender - descender) * scale + 0.5; + + fprintf(stderr, "Font height: %d\n", font->height); + return font; }