diff --git a/file.h b/file.h index 12abc13b60..7f754939db 100644 --- a/file.h +++ b/file.h @@ -26,6 +26,8 @@ #include #include "general.h" +// Generic file, path and directory handling. + ssize_t read_file(const char *path, void **buf); bool load_state(const char *path); diff --git a/gfx/fonts.c b/gfx/fonts.c index 15fda1ebc0..ac3d8e0af1 100644 --- a/gfx/fonts.c +++ b/gfx/fonts.c @@ -16,6 +16,7 @@ */ #include "fonts.h" +#include "file.h" #include #include #include @@ -131,3 +132,33 @@ void font_renderer_free(font_renderer_t *handle) if (handle->lib) FT_Done_FreeType(handle->lib); } + +// Not the cleanest way to do things for sure, but should hopefully work ... :) + +#if defined(_WIN32) +static const char *font_paths[] = { + "C:\\Windows\\Fonts\\consola.ttf", + "C:\\Windows\\Fonts\\verdana.ttf", +#elif defined(__APPLE__) +static const char *font_paths[] = { + "/Library/Fonts/Microsoft/Lucidia Console.ttf", +#else +static const char *font_paths[] = { + "/usr/share/fonts/TTF/DejaVuSansMono.ttf", + "/usr/share/fonts/TTF/DejaVuSans.ttf", +#endif + "osd-font.ttf", // Magic font to search for, useful for distribution. +}; + +// Highly OS/platform dependent. +const char *font_renderer_get_default_font(void) +{ + for (unsigned i = 0; i < sizeof(font_paths) / sizeof(font_paths[0]); i++) + { + if (path_file_exists(font_paths[i])) + return font_paths[i]; + } + + return NULL; +} + diff --git a/gfx/fonts.h b/gfx/fonts.h index d2fbd8b9c6..7b32e5fc28 100644 --- a/gfx/fonts.h +++ b/gfx/fonts.h @@ -25,10 +25,10 @@ typedef struct font_renderer font_renderer_t; struct font_output { - uint8_t *output; + uint8_t *output; // 8-bit intensity. unsigned width, height, pitch; int off_x, off_y; - struct font_output *next; + struct font_output *next; // linked list. }; struct font_output_list @@ -37,8 +37,12 @@ struct font_output_list }; font_renderer_t *font_renderer_new(const char *font_path, unsigned font_size); -void font_renderer_msg(font_renderer_t *handle, const char *msg, struct font_output_list *output); +void font_renderer_msg(font_renderer_t *handle, const char *msg, + struct font_output_list *output); + void font_renderer_free_output(struct font_output_list *list); void font_renderer_free(font_renderer_t *handle); +const char *font_renderer_get_default_font(void); + #endif diff --git a/gfx/gl.c b/gfx/gl.c index 4a811bf177..c7176cf86f 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -332,9 +332,13 @@ static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) static inline void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) { #ifdef HAVE_FREETYPE - if (*font_path) + const char *path = font_path; + if (!*path) + path = font_renderer_get_default_font(); + + if (path) { - gl->font = font_renderer_new(font_path, font_size); + gl->font = font_renderer_new(path, font_size); if (gl->font) { glGenTextures(1, &gl->font_tex);