diff options
Diffstat (limited to 'tools/convbdf.c')
-rw-r--r-- | tools/convbdf.c | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/tools/convbdf.c b/tools/convbdf.c index 6dcd2d8394..c75b5fb444 100644 --- a/tools/convbdf.c +++ b/tools/convbdf.c | |||
@@ -64,6 +64,7 @@ struct font { | |||
64 | #define EXTRA 300 /* # bytes extra allocation for buggy .bdf files*/ | 64 | #define EXTRA 300 /* # bytes extra allocation for buggy .bdf files*/ |
65 | 65 | ||
66 | int gen_c = 0; | 66 | int gen_c = 0; |
67 | int gen_h = 0; | ||
67 | int gen_fnt = 0; | 68 | int gen_fnt = 0; |
68 | int gen_map = 1; | 69 | int gen_map = 1; |
69 | int start_char = 0; | 70 | int start_char = 0; |
@@ -83,6 +84,7 @@ char * bdf_getline(FILE *fp, char *buf, int len); | |||
83 | bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2); | 84 | bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2); |
84 | 85 | ||
85 | int gen_c_source(struct font* pf, char *path); | 86 | int gen_c_source(struct font* pf, char *path); |
87 | int gen_h_header(struct font* pf, char *path); | ||
86 | int gen_fnt_file(struct font* pf, char *path); | 88 | int gen_fnt_file(struct font* pf, char *path); |
87 | 89 | ||
88 | void | 90 | void |
@@ -93,6 +95,7 @@ usage(void) | |||
93 | " convbdf [options] [-o output-file] [single-input-file]\n" | 95 | " convbdf [options] [-o output-file] [single-input-file]\n" |
94 | "Options:\n" | 96 | "Options:\n" |
95 | " -c Convert .bdf to .c source file\n" | 97 | " -c Convert .bdf to .c source file\n" |
98 | " -h Convert .bdf to .h header file (to create sysfont.h)\n" | ||
96 | " -f Convert .bdf to .fnt font file\n" | 99 | " -f Convert .bdf to .fnt font file\n" |
97 | " -s N Start output at character encodings >= N\n" | 100 | " -s N Start output at character encodings >= N\n" |
98 | " -l N Limit output to character encodings <= N\n" | 101 | " -l N Limit output to character encodings <= N\n" |
@@ -124,6 +127,9 @@ void getopts(int *pac, char ***pav) | |||
124 | case 'c': /* generate .c output*/ | 127 | case 'c': /* generate .c output*/ |
125 | gen_c = 1; | 128 | gen_c = 1; |
126 | break; | 129 | break; |
130 | case 'h': /* generate .h output*/ | ||
131 | gen_h = 1; | ||
132 | break; | ||
127 | case 'f': /* generate .fnt output*/ | 133 | case 'f': /* generate .fnt output*/ |
128 | gen_fnt = 1; | 134 | gen_fnt = 1; |
129 | break; | 135 | break; |
@@ -214,6 +220,14 @@ int convbdf(char *path) | |||
214 | } | 220 | } |
215 | ret |= gen_c_source(pf, outfile); | 221 | ret |= gen_c_source(pf, outfile); |
216 | } | 222 | } |
223 | |||
224 | if (gen_h) { | ||
225 | if (!oflag) { | ||
226 | strcpy(outfile, basename(path)); | ||
227 | strcat(outfile, ".h"); | ||
228 | } | ||
229 | ret |= gen_h_header(pf, outfile); | ||
230 | } | ||
217 | 231 | ||
218 | if (gen_fnt) { | 232 | if (gen_fnt) { |
219 | if (!oflag) { | 233 | if (!oflag) { |
@@ -234,12 +248,12 @@ int main(int ac, char **av) | |||
234 | ++av; --ac; /* skip av[0]*/ | 248 | ++av; --ac; /* skip av[0]*/ |
235 | getopts(&ac, &av); /* read command line options*/ | 249 | getopts(&ac, &av); /* read command line options*/ |
236 | 250 | ||
237 | if (ac < 1 || (!gen_c && !gen_fnt)) { | 251 | if (ac < 1 || (!gen_c && !gen_h && !gen_fnt)) { |
238 | usage(); | 252 | usage(); |
239 | exit(1); | 253 | exit(1); |
240 | } | 254 | } |
241 | if (oflag) { | 255 | if (oflag) { |
242 | if (ac > 1 || (gen_c && gen_fnt)) { | 256 | if (ac > 1 || (gen_c && gen_fnt) || (gen_c && gen_h) || (gen_h && gen_fnt)) { |
243 | usage(); | 257 | usage(); |
244 | exit(1); | 258 | exit(1); |
245 | } | 259 | } |
@@ -965,6 +979,58 @@ int gen_c_source(struct font* pf, char *path) | |||
965 | return 0; | 979 | return 0; |
966 | } | 980 | } |
967 | 981 | ||
982 | /* generate C header from in-core font*/ | ||
983 | int gen_h_header(struct font* pf, char *path) | ||
984 | { | ||
985 | FILE *ofp; | ||
986 | time_t t = time(0); | ||
987 | char buf[256]; | ||
988 | char hdr1[] = { | ||
989 | "/* Generated by convbdf on %s. */\n" | ||
990 | "#ifdef HAVE_LCD_BITMAP\n" | ||
991 | "\n" | ||
992 | "/* Font information*/\n" | ||
993 | "#define SYSFONT_NAME %s\n" | ||
994 | "#define SYSFONT_FACENAME %s\n" | ||
995 | "#define SYSFONT_WIDTH %d\n" | ||
996 | "#define SYSFONT_HEIGHT %d\n" | ||
997 | "#define SYSFONT_SIZE %d\n" | ||
998 | "#define SYSFONT_ASCENT %d\n" | ||
999 | "#define SYSFONT_DESCENT %d\n" | ||
1000 | "#define SYSFONT_FIRST_CHAR %d\n" | ||
1001 | "#define SYSFONT_LAST_CHAR %d\n" | ||
1002 | "#define SYSFONT_DEFAULT_CHAR %d\n" | ||
1003 | "#define SYSFONT_PROPORTIONAL %s\n" | ||
1004 | "#define SYSFONT_COPYRIGHT %s\n" | ||
1005 | "#define SYSFONT_BITS_SIZE %d\n" | ||
1006 | "\n" | ||
1007 | "#endif\n" | ||
1008 | }; | ||
1009 | |||
1010 | ofp = fopen(path, "w"); | ||
1011 | if (!ofp) { | ||
1012 | fprintf(stderr, "Can't create %s\n", path); | ||
1013 | return 1; | ||
1014 | } | ||
1015 | |||
1016 | strcpy(buf, ctime(&t)); | ||
1017 | buf[strlen(buf)-1] = 0; | ||
1018 | |||
1019 | fprintf(ofp, hdr1, buf, | ||
1020 | pf->name, | ||
1021 | pf->facename? pf->facename: "", | ||
1022 | pf->maxwidth, pf->height, | ||
1023 | pf->size, | ||
1024 | pf->ascent, pf->descent, | ||
1025 | pf->firstchar, | ||
1026 | pf->firstchar+pf->size-1, | ||
1027 | pf->defaultchar, | ||
1028 | pf->width? 1: 0, | ||
1029 | pf->copyright? pf->copyright: ""); | ||
1030 | |||
1031 | return 0; | ||
1032 | } | ||
1033 | |||
968 | static int writebyte(FILE *fp, unsigned char c) | 1034 | static int writebyte(FILE *fp, unsigned char c) |
969 | { | 1035 | { |
970 | return putc(c, fp) != EOF; | 1036 | return putc(c, fp) != EOF; |