From d738c30dec8a7c9f351094851c00a4623f339084 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Tue, 6 Mar 2018 21:27:12 -0800 Subject: Added support for TTC and dfont format true type fonts. More robust font selection on Windows --HG-- branch : nuklear_ui --- nuklear_ui/font.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'nuklear_ui/font.c') diff --git a/nuklear_ui/font.c b/nuklear_ui/font.c index 6dd3232..006ae48 100644 --- a/nuklear_ui/font.c +++ b/nuklear_ui/font.c @@ -1,5 +1,8 @@ #include #include +#include +#include "../util.h" +#include "sfnt.h" char *default_font_path(void) { @@ -24,3 +27,31 @@ char *default_font_path(void) return buffer; } + +uint8_t *default_font(uint32_t *size_out) +{ + char *path = default_font_path(); + if (!path) { + goto error; + } + FILE *f = fopen(path, "rb"); + if (!f) { + goto error; + } + long size = file_size(f); + uint8_t *buffer = malloc(size); + if (size != fread(buffer, 1, size, f)) { + fclose(f); + goto error; + } + fclose(f); + sfnt_container *sfnt = load_sfnt(buffer, size); + if (!sfnt) { + free(buffer); + goto error; + } + return sfnt_flatten(sfnt->tables, size_out); +error: + //TODO: try to find a suitable font in /usr/share/fonts as a fallback + return NULL; +} \ No newline at end of file -- cgit v1.2.3