From 700c42088aea8d82218f6d5fbb70c791b46457ed Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Fri, 9 Mar 2018 23:23:19 +0200 Subject: [PATCH] Support for querying current font size. os_font_data(0, &h, &w) stores the current font height and width into h and w, also accounting for style (with a non-zero font os_font_data returns dimensions for Roman style as before). Currently properly implemented only in SDL where the call returns true. On other front ends it returns false and either does not touch h & w (curses) or sets them correctly anyway (dos). --- src/sdl/sf_fonts.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/sdl/sf_fonts.c b/src/sdl/sf_fonts.c index 1963875..4174ef7 100644 --- a/src/sdl/sf_fonts.c +++ b/src/sdl/sf_fonts.c @@ -498,27 +498,29 @@ static void setstyle( int style){ * the given font is unavailable then these values must _not_ * be changed. * + * Font can also be 0 to query the size of the current font in the current + * style. Not all front end support this. Those that do return true. */ -int os_font_data( int font, int *height, int *width) - { - switch (font) - { - case TEXT_FONT: - case FIXED_WIDTH_FONT: - case GRAPHICS_FONT: - { - sf_pushtextsettings(); - setfont(font); - setstyle(0); - *height = current.font->height(current.font); - *width = os_char_width((zword)('0')); - sf_poptextsettings(); - return 1; - } - default: break; - } - return 0; - } +int os_font_data( int font, int *height, int *width) { + switch (font) { + case TEXT_FONT: + case FIXED_WIDTH_FONT: + case GRAPHICS_FONT: + sf_pushtextsettings(); + setfont(font); + setstyle(0); + *height = current.font->height(current.font); + *width = os_char_width((zword)('0')); + sf_poptextsettings(); + return 1; + case 0: + *height = current.font->height(current.font); + *width = os_char_width((zword)('0')); + return 1; + default: + return 0; + } +} /* * os_set_font -- 2.34.1