From aa27f073c63cb8120e9debebb627c6282870397a Mon Sep 17 00:00:00 2001 From: Takamichi Horikawa Date: Wed, 20 Sep 2017 23:26:07 +0900 Subject: fmplayer common: move font.rom loading to common --- common/fmplayer_fontrom_unix.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 common/fmplayer_fontrom_unix.c (limited to 'common/fmplayer_fontrom_unix.c') diff --git a/common/fmplayer_fontrom_unix.c b/common/fmplayer_fontrom_unix.c new file mode 100644 index 0000000..bac8a81 --- /dev/null +++ b/common/fmplayer_fontrom_unix.c @@ -0,0 +1,48 @@ +#include "fmplayer_fontrom.h" +#include "fmdsp/font.h" +#include +#include +#include +#include + +#include "fmdsp/fontrom_shinonome.inc" + +#define DATADIR "/.local/share/fmplayer/" + +static struct { + uint8_t fontrombuf[FONT_ROM_FILESIZE]; +} g; + +void fmplayer_font_rom_load(struct fmdsp_font *font) { + const char *path = "font.rom"; + const char *home = getenv("HOME"); + char *dpath = 0; + FILE *f = 0; + fmdsp_font_from_font_rom(font, g.fontrombuf); + if (home) { + const char *datadir = DATADIR; + dpath = malloc(strlen(home)+strlen(datadir)+strlen(path)+1); + if (dpath) { + strcpy(dpath, home); + strcat(dpath, datadir); + strcat(dpath, path); + path = dpath; + } + } + f = fopen(path, "r"); + free(dpath); + if (!f) goto err; + if (fseek(f, 0, SEEK_END) != 0) goto err; + long size = ftell(f); + if (size != FONT_ROM_FILESIZE) goto err; + if (fseek(f, 0, SEEK_SET) != 0) goto err; + if (fread(g.fontrombuf, 1, FONT_ROM_FILESIZE, f) != FONT_ROM_FILESIZE) { + goto err; + } + fclose(f); + return; + +err: + if (f) fclose(f); + fmdsp_font_from_font_rom(font, fmdsp_shinonome_font_rom); +} -- cgit v1.2.3