Support for querying current font size.
authorTimo Korvola <tkorvola@iki.fi>
Fri, 9 Mar 2018 21:23:19 +0000 (23:23 +0200)
committerDavid Griffith <dave@661.org>
Sun, 11 Mar 2018 11:48:51 +0000 (04:48 -0700)
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

index 19638753102e48f5b0cad36db9fe52830f6cc7b9..4174ef7830e61f1ab9daf1aff74e6fe0f6c269ac 100644 (file)
@@ -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