From af641426fad35cd857c1f14bda523db3d85a70cd Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 May 2024 16:44:28 -0700 Subject: Initial commit. --- font/font.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 font/font.c (limited to 'font/font.c') diff --git a/font/font.c b/font/font.c new file mode 100644 index 0000000..2d30c50 --- /dev/null +++ b/font/font.c @@ -0,0 +1,45 @@ +#include + +#include +#include +#include +#include + +static size_t GetFileSize(FILE* file) { + fseek(file, 0, SEEK_END); + const size_t size = ftell(file); + fseek(file, 0, SEEK_SET); + return size; +} + +FontAtlas* LoadFontAtlas(const char* path) { + assert(path); + + FILE* file = NULL; + FontAtlas* atlas = 0; + + if ((file = fopen(path, "rb")) == NULL) { + goto cleanup; + } + + const size_t size = GetFileSize(file); + if (size == (size_t)-1) { + goto cleanup; + } + + atlas = calloc(1, size); + if (!atlas) { + goto cleanup; + } + + if (fread(atlas, size, 1, file) != 1) { + free(atlas); + atlas = 0; + } + +cleanup: + if (file != NULL) { + fclose(file); + } + return atlas; +} -- cgit v1.2.3