summaryrefslogtreecommitdiff
path: root/font/font.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-05-04 16:44:28 -0700
committer3gg <3gg@shellblade.net>2024-05-04 16:52:53 -0700
commitaf641426fad35cd857c1f14bda523db3d85a70cd (patch)
tree8a219b03aef0c80cac56cd6b88571a7a6988b35b /font/font.c
Initial commit.
Diffstat (limited to 'font/font.c')
-rw-r--r--font/font.c45
1 files changed, 45 insertions, 0 deletions
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 @@
1#include <font.h>
2
3#include <assert.h>
4#include <stdbool.h>
5#include <stdio.h>
6#include <stdlib.h>
7
8static size_t GetFileSize(FILE* file) {
9 fseek(file, 0, SEEK_END);
10 const size_t size = ftell(file);
11 fseek(file, 0, SEEK_SET);
12 return size;
13}
14
15FontAtlas* LoadFontAtlas(const char* path) {
16 assert(path);
17
18 FILE* file = NULL;
19 FontAtlas* atlas = 0;
20
21 if ((file = fopen(path, "rb")) == NULL) {
22 goto cleanup;
23 }
24
25 const size_t size = GetFileSize(file);
26 if (size == (size_t)-1) {
27 goto cleanup;
28 }
29
30 atlas = calloc(1, size);
31 if (!atlas) {
32 goto cleanup;
33 }
34
35 if (fread(atlas, size, 1, file) != 1) {
36 free(atlas);
37 atlas = 0;
38 }
39
40cleanup:
41 if (file != NULL) {
42 fclose(file);
43 }
44 return atlas;
45}