summaryrefslogtreecommitdiff
path: root/gen_font.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-27 04:29:34 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-27 04:29:34 +0200
commitf0350659cf5e0166128f07d4770a1ff6357ca5af (patch)
treeebb397b8599600c6dd1f9afbf723a1b279255184 /gen_font.c
parenta342858da040ac2f54a083b93c483d20408eb268 (diff)
downloadsaw-f0350659cf5e0166128f07d4770a1ff6357ca5af.zip
Update TODO; add TTF font
Diffstat (limited to 'gen_font.c')
-rw-r--r--gen_font.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/gen_font.c b/gen_font.c
new file mode 100644
index 0000000..89659c3
--- /dev/null
+++ b/gen_font.c
@@ -0,0 +1,47 @@
+#if 0
+gcc -fsanitize=undefined,address,leak -o gen_font gen_font.c && ./gen_font && rm gen_font
+exit
+#endif
+
+#include <stdio.h>
+#include <assert.h>
+
+int main(int argc, char **argv) {
+ FILE *in = fopen("font.ttf", "rb");
+ FILE *out = fopen("source/saw/font.inl.h", "wb");
+ assert(in != NULL);
+ assert(out != NULL);
+
+ fprintf(out, "// \"Black Chancery\" by Doug Miles\n//\n\n");
+ fprintf(out, "#ifndef SAW_FONT_INL_H\n");
+ fprintf(out, "#define SAW_FONT_INL_H\n\n");
+ fprintf(out, "#include \"../kit/types.h\"\n\n");
+ fprintf(out, "static u8 saw_font_ttf[] = {");
+
+ long long n = 0, k = 0;
+ unsigned char buf[128];
+
+ while (!feof(in)) {
+ k = fread(buf, 1, 128, in);
+ if (k <= 0)
+ break;
+
+ for (long long i = 0; i < k; ++i) {
+ if (n > 0)
+ fprintf(out, ",");
+ if ((n % 20) == 0)
+ fprintf(out, "\n ");
+
+ fprintf(out, "%4d", (unsigned) buf[i]);
+
+ ++n;
+ }
+ }
+
+ fprintf(out, "\n};\n\n");
+ fprintf(out, "enum { SAW_FONT_TTF_SIZE = %lld };\n\n", n);
+ fprintf(out, "#endif\n");
+
+ fclose(in);
+ return 0;
+}