mirror of
https://github.com/libretro/RetroArch.git
synced 2025-04-02 10:51:52 -04:00
Default fonts.
This commit is contained in:
parent
3db79ab2f0
commit
7d33cccc8e
4 changed files with 46 additions and 5 deletions
2
file.h
2
file.h
|
@ -26,6 +26,8 @@
|
|||
#include <sys/types.h>
|
||||
#include "general.h"
|
||||
|
||||
// Generic file, path and directory handling.
|
||||
|
||||
ssize_t read_file(const char *path, void **buf);
|
||||
|
||||
bool load_state(const char *path);
|
||||
|
|
31
gfx/fonts.c
31
gfx/fonts.c
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "fonts.h"
|
||||
#include "file.h"
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
10
gfx/fonts.h
10
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
|
||||
|
|
8
gfx/gl.c
8
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue