summaryrefslogtreecommitdiff
path: root/source/saw/_gen.c
blob: 0c4e4a6d800a580f3bf640619e9b2df2dd081a5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#if 0
gcc -fsanitize=undefined,address,leak -o _gen _gen.c && ./_gen && rm _gen
exit
#endif

#include <stdio.h>
#include <assert.h>

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;
}