From 9417f59a071174424f88a206f7789c863d9eb718 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Fri, 12 Jan 2024 03:45:33 +0100 Subject: Move font and codegen to the source folder --- domitian_roman.ttf | Bin 198512 -> 0 bytes gen_font.c | 48 ------------------------------------------ source/saw/_gen.c | 48 ++++++++++++++++++++++++++++++++++++++++++ source/saw/domitian_roman.ttf | Bin 0 -> 198512 bytes 4 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 domitian_roman.ttf delete mode 100644 gen_font.c create mode 100644 source/saw/_gen.c create mode 100644 source/saw/domitian_roman.ttf diff --git a/domitian_roman.ttf b/domitian_roman.ttf deleted file mode 100644 index 01c0ee6..0000000 Binary files a/domitian_roman.ttf and /dev/null differ diff --git a/gen_font.c b/gen_font.c deleted file mode 100644 index 952e2ac..0000000 --- a/gen_font.c +++ /dev/null @@ -1,48 +0,0 @@ -#if 0 -gcc -fsanitize=undefined,address,leak -o gen_font gen_font.c && ./gen_font && rm gen_font -exit -#endif - -#include -#include - -int main(int argc, char **argv) { - FILE *in = fopen("domitian_roman.ttf", "rb"); - FILE *out = fopen("source/saw/font.inl.h", "wb"); - assert(in != NULL); - assert(out != NULL); - - fprintf(out, - "// \"Domitian-Roman\" by Daniel Benjamin Miller\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; -} diff --git a/source/saw/_gen.c b/source/saw/_gen.c new file mode 100644 index 0000000..0c4e4a6 --- /dev/null +++ b/source/saw/_gen.c @@ -0,0 +1,48 @@ +#if 0 +gcc -fsanitize=undefined,address,leak -o _gen _gen.c && ./_gen && rm _gen +exit +#endif + +#include +#include + +int main(int argc, char **argv) { + FILE *in = fopen("domitian_roman.ttf", "rb"); + FILE *out = fopen("font.inl.h", "wb"); + assert(in != NULL); + assert(out != NULL); + + fprintf(out, + "// \"Domitian-Roman\" by Daniel Benjamin Miller\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; +} diff --git a/source/saw/domitian_roman.ttf b/source/saw/domitian_roman.ttf new file mode 100644 index 0000000..01c0ee6 Binary files /dev/null and b/source/saw/domitian_roman.ttf differ -- cgit v1.2.3