Merge pull request #13 from rdebath/patch-fixes
[congif.git] / mbf2c.c
blob96c5ec85fdacd2096d27b2f5ee5087c506e2eaac
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdint.h>
5 #include <sys/stat.h>
7 #include "mbf.h"
9 #define MAX_NAME 0x10
10 #define FN "default_font"
12 int
13 main(int argc, char *argv[])
15 Font *font;
16 int i;
18 if (argc != 2) {
19 fprintf(stderr, "Usage: %s font.mbf\n", argv[0]);
20 return 1;
22 font = load_font(argv[1]);
23 if (font == NULL) {
24 fprintf(stderr, "Failed to load font '%s'.\n", argv[1]);
25 return 1;
28 printf("static Range "FN"_ranges[%d] = {\n", font->header.nr);
29 for(i=0; i<font->header.nr; i++) {
30 printf(" { %d, %d }%s\n",
31 (int) font->ranges[i].offset,
32 (int) font->ranges[i].length,
33 i+1 == font->header.nr?"":",");
35 printf("};\n\n");
37 printf("static uint8_t "FN"_data[] = {\n");
38 for (i = 0; i < font->header.ng * font->stride * font->header.h; i++) {
39 if (i%12 == 0) {
40 if (i) printf(",\n");
41 printf(" ");
42 } else
43 printf(", ");
44 printf("0x%02x", font->data[i]);
46 printf("\n};\n\n");
48 printf("Font "FN"[1] = {{ ");
50 printf("{ %d, %d, %d, %d }, ",
51 (int) font->header.ng,
52 (int) font->header.w,
53 (int) font->header.h,
54 (int) font->header.nr);
56 printf("%d, "FN"_ranges, "FN"_data }};\n",
57 (int) font->stride);
59 free(font);
60 return 0;