Description: Use fontconfig to find TTFs
Author: chrysn <chrysn@fsfe.org>

This patch bridges the gap between the hardcoded font file path upstream uses
and a (finally easier) rewrite in SDL_Pango.

--- a/graph.cpp
+++ b/graph.cpp
@@ -28,6 +28,7 @@ int audiovolume = 60;
 #endif
 
 #include <SDL/SDL_ttf.h>
+#include <fontconfig/fontconfig.h>
 
 #ifdef GFX
 #include <SDL/SDL_gfxPrimitives.h>
@@ -67,6 +68,7 @@ int audiovolume = 60;
 #define NUMMODES 7
 
 SDL_Surface *s;
+char *fontfile = NULL;
 TTF_Font *font[256];
 
 #endif
@@ -150,7 +152,7 @@ int qpixel3(SDL_Surface *surf, int x, in
 
 void loadfont(int siz) {
   if(!font[siz]) {
-    font[siz] = TTF_OpenFont("VeraBd.ttf", siz);
+    font[siz] = TTF_OpenFont(fontfile, siz);
     if (font[siz] == NULL) {
       printf("error: Font file not found\n");
       exit(1);
@@ -2419,6 +2421,43 @@ void initgraph() {
       Mix_AllocateChannels(4);
       }
     }
+
+  if (FcInit())
+  {
+    FcResult result;
+    FcFontSet *fs;
+    FcPattern* pat;
+    FcPattern *match;
+
+    pat = FcNameParse((FcChar8 *)"Bitstream Vera Sans");
+    FcConfigSubstitute(0, pat, FcMatchPattern);
+
+    FcPatternDel(pat, FC_WEIGHT);
+    FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD);
+
+    FcDefaultSubstitute(pat);
+    fs = FcFontSetCreate();
+    match = FcFontMatch(0, pat, &result);
+
+    if (match) FcFontSetAdd(fs, match);
+    if (pat) FcPatternDestroy(pat);
+    if (fs) {
+      if( FcPatternGetString(fs->fonts[0], FC_FILE, 0, (FcChar8**)&fontfile) == FcResultMatch ) {
+        fontfile = strdup(fontfile);
+      };
+      if (fontfile == NULL)
+      {
+        printf("Failed to find suitable font\n");
+	exit(2);
+      }
+      FcFontSetDestroy(fs);
+    }
+    FcFini();
+  } else {
+    printf("Failed to initialize FontConfig.\n");
+    exit(2);
+  }
+
   #endif
     
   #endif
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
 CXXFLAGS ?=
 
 hyper: hyper.cpp graph.cpp hyperpoint.cpp geometry.cpp cell.cpp heptagon.cpp game.cpp classes.cpp polygons.cpp
-	g++ hyper.cpp -o hyper -lSDL -lSDL_ttf -lSDL_mixer -DFHS -Wall -g -lSDL_gfx ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -lGL -O3
+	g++ hyper.cpp -o hyper -lSDL -lSDL_ttf -lSDL_mixer -lfontconfig -DFHS -Wall -g -lSDL_gfx ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} -lGL -O3
