diff -urN lcdtest-1.18-old/src/get_font_file.c lcdtest-1.18/src/get_font_file.c
--- lcdtest-1.18-old/src/get_font_file.c 1970-01-01 01:00:00.000000000 +0100
+++ lcdtest-1.18/src/get_font_file.c 2019-11-20 23:07:52.379800111 +0100
@@ -0,0 +1,39 @@
+#include "get_font_file.h"
+#include <fontconfig/fontconfig.h>
+#include <stddef.h>
+
+static FcPattern *font_file = NULL;
+
+const char *get_font_file (const char *font_name)
+{
+ FcConfig* config = FcInitLoadConfigAndFonts();
+ //make pattern from font name
+ FcPattern* pat = FcNameParse((const FcChar8*)"LiberationMono-Regular");
+ FcConfigSubstitute(config, pat, FcMatchPattern);
+ FcDefaultSubstitute(pat);
+ char* fontFile = NULL;
+ // find the font
+ FcResult result;
+ font_file = FcFontMatch(config, pat, &result);
+ if (font_file)
+ {
+ FcChar8* file = NULL;
+ if (FcPatternGetString(font_file, FC_FILE, 0, &file) == FcResultMatch)
+ {
+ //we found the font
+ //This might be a fallback font
+ fontFile = (char *) file;
+ }
+ }
+ FcPatternDestroy(pat);
+ FcConfigDestroy(config);
+ return fontFile;
+}
+
+void free_font_file()
+{
+ if (font_file != NULL)
+ {
+ FcPatternDestroy(font_file);
+ }
+}
diff -urN lcdtest-1.18-old/src/get_font_file.h lcdtest-1.18/src/get_font_file.h
--- lcdtest-1.18-old/src/get_font_file.h 1970-01-01 01:00:00.000000000 +0100
+++ lcdtest-1.18/src/get_font_file.h 2019-11-20 23:03:04.194198571 +0100
@@ -0,0 +1,5 @@
+#ifndef GETFONTFILE_H
+#define GETFONTFILE_H
+const char *get_font_file();
+void free_font_file();
+#endif
Binary files lcdtest-1.18-old/src/.get_font_gile.c.swp and lcdtest-1.18/src/.get_font_gile.c.swp differ
diff -urN lcdtest-1.18-old/src/lcdtest.c lcdtest-1.18/src/lcdtest.c
--- lcdtest-1.18-old/src/lcdtest.c 2019-11-20 21:55:43.769742357 +0100
+++ lcdtest-1.18/src/lcdtest.c 2019-11-20 23:07:59.139626577 +0100
@@ -33,6 +33,8 @@
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
+#include "get_font_file.h"
+
#define UNUSED __attribute__ ((unused))
#define QMAKESTR(x) #x
@@ -742,8 +744,6 @@
}
-const char font_path [] = "/usr/share/fonts/liberation/LiberationMono-Regular.ttf";
-
int main (int argc, char *argv [])
{
SDL_Surface *screen;
@@ -756,6 +756,13 @@
progname = argv [0];
+ const char *font_path = get_font_file ("LiberationMono-Regular");
+ if (font_path == 0)
+ {
+ fatal (5, "Could not fint LiberationMono-Regular font\n");
+ }
+ atexit (free_font_file);
+
if (SDL_Init (SDL_INIT_VIDEO) < 0)
fatal (2, "SDL initialization error %s\n", SDL_GetError ());
atexit (SDL_Quit);
Binary files lcdtest-1.18-old/src/.lcdtest.c.swp and lcdtest-1.18/src/.lcdtest.c.swp differ
diff -urN lcdtest-1.18-old/src/SConscript lcdtest-1.18/src/SConscript
--- lcdtest-1.18-old/src/SConscript 2019-11-20 21:55:43.769742357 +0100
+++ lcdtest-1.18/src/SConscript 2019-11-20 23:09:31.968243555 +0100
@@ -25,7 +25,7 @@
#-----------------------------------------------------------------------------
headers = []
-srcs = Split ("""lcdtest.c""")
+srcs = Split ("""lcdtest.c get_font_file.c""")
objs = [env.Object(src) for src in srcs]
@@ -37,7 +37,7 @@
else:
env.Append (CCFLAGS = ['-g', '-Wall', '-Wextra'])
-env.Append (LIBS = ['SDL', 'SDL_image', 'SDL_ttf']);
+env.Append (LIBS = ['SDL', 'SDL_image', 'SDL_ttf', 'fontconfig']);
env.Append (CPPDEFINES = [ ('RELEASE', env ['RELEASE'])])