share/gui: allow fall back to non-localised font path
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 30 Apr 2009 22:40:17 +0000 (22:40 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 30 Apr 2009 22:40:17 +0000 (22:40 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@2845 78b8d119-cf0a-0410-b17c-f493084dd1d7

share/gui.c
share/gui.h

index 6f85e9b..cf4c764 100644 (file)
@@ -22,6 +22,7 @@
 #include "image.h"
 #include "vec3.h"
 #include "gui.h"
+#include "common.h"
 
 /*---------------------------------------------------------------------------*/
 
@@ -212,6 +213,23 @@ static GLuint gui_rect(int x, int y, int w, int h, int f, int r)
 
 /*---------------------------------------------------------------------------*/
 
+static const char *pick_font_path(void)
+{
+    const char *path;
+
+    path = config_data(_(GUI_FACE));
+
+    if (!file_exists(path))
+    {
+        fprintf(stderr, _("Font \"%s\" doesn't exist, trying default font.\n"),
+                path);
+
+        path = config_data(GUI_FACE);
+    }
+
+    return path;
+}
+
 void gui_init(void)
 {
     const float *c0 = gui_yel;
@@ -225,6 +243,8 @@ void gui_init(void)
 
     if (TTF_Init() == 0)
     {
+        const char *fontpath = pick_font_path();
+
         int s0 = s / 26;
         int s1 = s / 13;
         int s2 = s /  7;
@@ -233,9 +253,9 @@ void gui_init(void)
 
         /* Load small, medium, and large typefaces. */
 
-        font[GUI_SML] = TTF_OpenFont(config_data(GUI_FACE), s0);
-        font[GUI_MED] = TTF_OpenFont(config_data(GUI_FACE), s1);
-        font[GUI_LRG] = TTF_OpenFont(config_data(GUI_FACE), s2);
+        font[GUI_SML] = TTF_OpenFont(fontpath, s0);
+        font[GUI_MED] = TTF_OpenFont(fontpath, s1);
+        font[GUI_LRG] = TTF_OpenFont(fontpath, s2);
         radius = s / 60;
 
         /* Initialize digit glyphs and lists for counters and clocks. */
index a3f131c..d90abbf 100644 (file)
@@ -20,7 +20,7 @@
 
 /*---------------------------------------------------------------------------*/
 
-#define GUI_FACE _("ttf/DejaVuSans-Bold.ttf")
+#define GUI_FACE N_("ttf/DejaVuSans-Bold.ttf")
 
 #define GUI_SML  0
 #define GUI_MED  1