From 421b0914489acc17a62e2c26e812157f793dffe9 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 10 Dec 2017 17:04:02 +1100 Subject: [PATCH] [client] Added fontconfig for font path detection --- client/main.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/client/main.c b/client/main.c index 5fc4f6c8..a9243dbd 100644 --- a/client/main.c +++ b/client/main.c @@ -32,6 +32,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include +#include #define GL_GLEXT_PROTOTYPES #include @@ -715,12 +716,35 @@ int run() return -1; } - state.font = TTF_OpenFont("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 14); - if (!state.font) + FcConfig * config = FcInitLoadConfigAndFonts(); + if (!config) { - DEBUG_ERROR("TTL_OpenFont Failed"); + DEBUG_ERROR("FcInitLoadConfigAndFonts Failed"); return -1; } + + FcPattern * pat = FcNameParse((const FcChar8*)"FreeMono"); + FcConfigSubstitute (config, pat, FcMatchPattern); + FcDefaultSubstitute(pat); + FcResult result; + FcChar8 * file = NULL; + FcPattern * font = FcFontMatch(config, pat, &result); + + if (font && (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch)) + { + state.font = TTF_OpenFont((char *)file, 14); + if (!state.font) + { + DEBUG_ERROR("TTL_OpenFont Failed"); + return -1; + } + } + else + { + DEBUG_ERROR("Failed to locate a font for FPS display"); + return -1; + } + FcPatternDestroy(pat); } state.window = SDL_CreateWindow(