diff --git a/src/font_render_lcd.h b/src/font_render_lcd.h index d24aebf2..d8ab9df2 100644 --- a/src/font_render_lcd.h +++ b/src/font_render_lcd.h @@ -55,6 +55,19 @@ public: m_gamma_lut.gamma(m_gamma); } + bool get_font_vmetrics(int& ascender, int& descender) { + int face_height = m_feng.face_height(); + if (face_height > 0) { + double current_height = m_feng.height(); + m_feng.height(1.0); + ascender = m_feng.ascender() * face_height; + descender = m_feng.descender() * face_height; + m_feng.height(current_height); + return true; + } + return false; + } + 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 ea0b2666..4dd1cba0 100644 --- a/tests/agg_font_render_test.cpp +++ b/tests/agg_font_render_test.cpp @@ -62,6 +62,10 @@ RenFontA* ren_load_font_agg(const char *filename, float size) { font->renderer = new font_renderer_lcd(true, false, false, 1.8); font->renderer->load_font(filename); + int ascender, descender; + 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;