summaryrefslogtreecommitdiff
path: root/nuklear_ui/font.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2018-03-06 21:27:12 -0800
committerMichael Pavone <pavone@retrodev.com>2018-03-06 21:27:12 -0800
commitd738c30dec8a7c9f351094851c00a4623f339084 (patch)
treed74219313a54b16466a53f4be180093cd5775a02 /nuklear_ui/font.c
parent94b11b186fa4cf46c64bc3fad55f74c7b5096ffe (diff)
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
--HG-- branch : nuklear_ui
Diffstat (limited to 'nuklear_ui/font.c')
-rw-r--r--nuklear_ui/font.c31
1 files changed, 31 insertions, 0 deletions
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 <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
+#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