diff options
author | Takamichi Horikawa <takamichiho@gmail.com> | 2017-09-20 23:26:07 +0900 |
---|---|---|
committer | Takamichi Horikawa <takamichiho@gmail.com> | 2017-09-20 23:26:07 +0900 |
commit | aa27f073c63cb8120e9debebb627c6282870397a (patch) | |
tree | 07ecb85419120bbe1804f094ee3824ecf0243c67 /common/fmplayer_fontrom_unix.c | |
parent | 96d11d0e5bd23b6a7128f48dfc6233132c6166c6 (diff) |
fmplayer common: move font.rom loading to common
Diffstat (limited to 'common/fmplayer_fontrom_unix.c')
-rw-r--r-- | common/fmplayer_fontrom_unix.c | 48 |
1 files changed, 48 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> + +#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); +} |