diff nuklear_ui/font.c @ 1527:4f6e8acd7b6a nuklear_ui

Added support for TTC and dfont format true type fonts. More robust font selection on Windows
author Michael Pavone <pavone@retrodev.com>
date Tue, 06 Mar 2018 21:27:12 -0800
parents c5c022c7aa54
children 24508cb54f87
line wrap: on
line diff
--- a/nuklear_ui/font.c	Wed Feb 07 19:21:44 2018 -0800
+++ b/nuklear_ui/font.c	Tue Mar 06 21:27:12 2018 -0800
@@ -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 @@
 	
 	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