diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-09-12 13:43:22 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-09-12 13:43:22 +0000 |
commit | 05e353acfc6c84c7105972fd8cf21e9fef5e9a62 (patch) | |
tree | 36134794f35bdcc9fbcba07605a49f999a701016 /tools | |
parent | 47a16e04903b710ff78115d139d84094b768756c (diff) | |
download | rockbox-05e353acfc6c84c7105972fd8cf21e9fef5e9a62.tar.gz rockbox-05e353acfc6c84c7105972fd8cf21e9fef5e9a62.zip |
bdf2ajf is not needed/used anymore
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2271 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile | 5 | ||||
-rw-r--r-- | tools/bdf2ajf.c | 927 | ||||
-rw-r--r-- | tools/bdf2ajf.h | 84 |
3 files changed, 1 insertions, 1015 deletions
diff --git a/tools/Makefile b/tools/Makefile index 7a51ae17fb..5102261e6d 100644 --- a/tools/Makefile +++ b/tools/Makefile | |||
@@ -8,7 +8,7 @@ | |||
8 | # | 8 | # |
9 | CFLAGS := -O -s -ansi | 9 | CFLAGS := -O -s -ansi |
10 | 10 | ||
11 | TARGETS := scramble descramble sh2d bdf2ajf bmp2rb | 11 | TARGETS := scramble descramble sh2d bmp2rb |
12 | 12 | ||
13 | all: $(TARGETS) | 13 | all: $(TARGETS) |
14 | 14 | ||
@@ -18,9 +18,6 @@ descramble: descramble.c | |||
18 | 18 | ||
19 | sh2d: sh2d.c | 19 | sh2d: sh2d.c |
20 | 20 | ||
21 | bdf2ajf: bdf2ajf.c | ||
22 | gcc -g -ansi $+ -o $@ | ||
23 | |||
24 | bmp2rb: bmp2rb.c | 21 | bmp2rb: bmp2rb.c |
25 | gcc -DAPPLICATION_NAME=\"$@\" -g $+ -o $@ | 22 | gcc -DAPPLICATION_NAME=\"$@\" -g $+ -o $@ |
26 | 23 | ||
diff --git a/tools/bdf2ajf.c b/tools/bdf2ajf.c deleted file mode 100644 index 4d47c5a7db..0000000000 --- a/tools/bdf2ajf.c +++ /dev/null | |||
@@ -1,927 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alex Gitelman | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "bdf2ajf.h" | ||
20 | #include <stdio.h> | ||
21 | #include <malloc.h> | ||
22 | #include <string.h> | ||
23 | #include <errno.h> | ||
24 | |||
25 | int _font_error_code = 0; | ||
26 | char _font_error_msg[1024]; | ||
27 | |||
28 | |||
29 | short win_alt_map[] = { | ||
30 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 - 0f */ | ||
31 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 - 1f */ | ||
32 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 - 2f */ | ||
33 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 30 - 3f */ | ||
34 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 - 4f */ | ||
35 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 - 5f */ | ||
36 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 - 6f */ | ||
37 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 - 7f */ | ||
38 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 - 8f */ | ||
39 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 90 - 9f */ | ||
40 | -1, -1, -1, -1, -1, -1, -1, -1, 0x85, -1, -1, -1, -1, -1, -1, -1, /* A0 - Af */ | ||
41 | -1, -1, -1, -1, -1, -1, -1, -1, 0xA5, -1, -1, -1, -1, -1, -1, -1, /* B0 - Bf */ | ||
42 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, /* C0 - Cf */ | ||
43 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, /* D0 - Df */ | ||
44 | 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, /* E0 - Ef */ | ||
45 | 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, /* F0 - Ff */ | ||
46 | }; | ||
47 | |||
48 | char* bufcat(char* buf1, char *buf2, int len1, int len2) | ||
49 | { | ||
50 | char *newbuf = malloc(len1+len2); | ||
51 | if (newbuf==0) | ||
52 | { | ||
53 | fprintf(stderr, "Can't allocate storage in bufcat (malloc returned 0)\n"); | ||
54 | return NULL; | ||
55 | } | ||
56 | memcpy(newbuf, buf1, len1); | ||
57 | memcpy(&newbuf[len1], buf2, len2); | ||
58 | return newbuf; | ||
59 | } | ||
60 | |||
61 | void write_short(unsigned short s, unsigned char* buf) | ||
62 | { | ||
63 | WRITE_SHORT(s, buf); | ||
64 | } | ||
65 | |||
66 | |||
67 | void usage() | ||
68 | { | ||
69 | printf("bdf2ajf - compile BDF font for use with Rockbox\n" | ||
70 | "Usage: bdf2ajf -f <font> -o <outfile>\n" | ||
71 | "Options:\n" | ||
72 | " -f - input BDF file\n" | ||
73 | " -o - output AJF file\n" | ||
74 | " -v - verbose debug output\n" | ||
75 | " -h - print help\n" | ||
76 | " -t <string> - print string as bitmap\n" | ||
77 | " -t2 <string> - print string as Archos bitmap (must be the same result as -t)\n"); | ||
78 | exit(0); | ||
79 | |||
80 | } | ||
81 | |||
82 | int do_test1 = 0; | ||
83 | int do_test2 = 0; | ||
84 | |||
85 | int verbose; | ||
86 | |||
87 | int main(int argc, char** argv) | ||
88 | { | ||
89 | FILE *outfd = 0; | ||
90 | unsigned char outbuf[20000]; | ||
91 | unsigned char buf[1000]; | ||
92 | unsigned char test_str1[300]; | ||
93 | unsigned char test_str2[300]; | ||
94 | int height = 8, rows; | ||
95 | int size = 0; | ||
96 | int i, offset; | ||
97 | unsigned char *p, *p1; | ||
98 | int c; | ||
99 | char in_file[1024]; | ||
100 | char out_file[1024]; | ||
101 | BDF *bdf = 0; | ||
102 | in_file[0] = 0; | ||
103 | out_file[0] = 0; | ||
104 | |||
105 | for(i=1;i<argc;i++) | ||
106 | { | ||
107 | if (!strcmp(argv[i], "-f")) | ||
108 | { | ||
109 | i++; | ||
110 | if (i==argc) usage(); | ||
111 | strcpy(in_file, argv[i]); | ||
112 | } | ||
113 | else if (!strcmp(argv[i], "-o")) | ||
114 | { | ||
115 | i++; | ||
116 | if (i==argc) usage(); | ||
117 | strcpy(out_file, argv[i]); | ||
118 | } | ||
119 | else if (!strcmp(argv[i], "-v")) | ||
120 | { | ||
121 | i++; | ||
122 | verbose = 1; | ||
123 | } | ||
124 | else if (!strcmp(argv[i], "-t")) | ||
125 | { | ||
126 | i++; | ||
127 | if (i==argc) usage(); | ||
128 | do_test1 = 1; | ||
129 | strcpy(test_str1, argv[i]); | ||
130 | } | ||
131 | else if (!strcmp(argv[i], "-t2")) | ||
132 | { | ||
133 | i++; | ||
134 | if (i==argc) usage(); | ||
135 | do_test2 = 1; | ||
136 | strcpy(test_str2, argv[i]); | ||
137 | } | ||
138 | else | ||
139 | usage(); | ||
140 | } | ||
141 | if (strlen(in_file)==0 || strlen(out_file)==0) | ||
142 | usage(); | ||
143 | |||
144 | bdf = readFont(in_file); | ||
145 | if (do_test1) | ||
146 | { | ||
147 | unsigned char *p = test_str1; | ||
148 | printf("Begin Test Print1 for %s", test_str1); | ||
149 | while(p[0]) | ||
150 | test_print(p++[0], bdf, win_alt_map); | ||
151 | |||
152 | } | ||
153 | if (do_test2) | ||
154 | { | ||
155 | unsigned char *p = test_str2; | ||
156 | printf("Begin Test Print2 for %s", test_str2); | ||
157 | while(p[0]) | ||
158 | { | ||
159 | BDF_GLYPH *g = getGlyph(p++[0], bdf, win_alt_map); | ||
160 | int rows = (g->bbx_height-1)/8+1; | ||
161 | |||
162 | unsigned char tst_src[100]; | ||
163 | if (!g) | ||
164 | { | ||
165 | printf("No Glyph for %c", p[-1]); | ||
166 | continue; | ||
167 | } | ||
168 | getBitmap(g, tst_src); | ||
169 | test_print2(tst_src, g->bbx_height, g->bitmap_len*rows); | ||
170 | } | ||
171 | |||
172 | } | ||
173 | |||
174 | writeAJF(bdf, out_file); | ||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | |||
179 | void writeAJF(BDF* bdf, const char* out_file) | ||
180 | { | ||
181 | FILE *outfd = 0; | ||
182 | unsigned char outbuf[20000]; | ||
183 | unsigned char char_map[20000]; | ||
184 | unsigned char buf[1000]; | ||
185 | unsigned char test_str1[300]; | ||
186 | unsigned char test_str2[300]; | ||
187 | unsigned short height = 8, rows, width; | ||
188 | unsigned short first_char = 0; | ||
189 | unsigned short char_count = 255; | ||
190 | int size = 0; | ||
191 | int i, offset; | ||
192 | unsigned char *p, *p1; | ||
193 | int c, idx, chars_offset; | ||
194 | |||
195 | memset(outbuf,0, sizeof(outbuf)); | ||
196 | height = bdf->bound_height; | ||
197 | rows = (bdf->bound_height-1)/8 + 1; | ||
198 | width = bdf->bound_width; | ||
199 | |||
200 | idx = 0; | ||
201 | outbuf[idx++] = MAGIC1; | ||
202 | outbuf[idx++] = MAGIC2; | ||
203 | if (bdf->name) | ||
204 | { | ||
205 | int len = strlen(bdf->name); | ||
206 | if (len<FONT_NAME_LEN) | ||
207 | strcpy(&outbuf[FONT_NAME_OFFSET], bdf->name); | ||
208 | else | ||
209 | memcpy(&outbuf[FONT_NAME_OFFSET], bdf->name, FONT_NAME_LEN); | ||
210 | |||
211 | } | ||
212 | |||
213 | idx = MAX_WIDTH_OFFSET; | ||
214 | write_short(width, &outbuf[idx]); | ||
215 | /* outbuf[idx] = (unsigned short)width; */ | ||
216 | idx = HEIGHT_OFFSET; | ||
217 | write_short(height, &outbuf[idx]); | ||
218 | /* outbuf[idx] = (unsigned short)height; */ | ||
219 | |||
220 | idx = FIRST_CHAR_OFFSET; | ||
221 | write_short(first_char, &outbuf[idx]); | ||
222 | |||
223 | idx = SIZE_OFFSET; | ||
224 | write_short(char_count, &outbuf[idx]); | ||
225 | |||
226 | chars_offset = LOOKUP_MAP_OFFSET + char_count*3; | ||
227 | idx = chars_offset; | ||
228 | |||
229 | /* Put bitmaps in outbuf */ | ||
230 | for (c=first_char;c<=char_count;c++) | ||
231 | { | ||
232 | int map_offset = LOOKUP_MAP_OFFSET + (c-first_char)*3; /* index in char map. Takes 3 bytes - 1 width, 2 - offset */ | ||
233 | unsigned char bmp_bytes = 0; | ||
234 | BDF_GLYPH *glyph = getGlyph((unsigned int)c, bdf, win_alt_map); | ||
235 | |||
236 | if (glyph) | ||
237 | { | ||
238 | bmp_bytes = rows*glyph->dwidth_x; | ||
239 | getBitmap(glyph, &outbuf[idx]); | ||
240 | if(verbose) { | ||
241 | int i; | ||
242 | printf("char %c (%02x) width %d\n", c, c, glyph->dwidth_x); | ||
243 | for(i=0; i< bmp_bytes;i++) | ||
244 | printf("%02x, ", outbuf[idx+i]); | ||
245 | printf("\n"); | ||
246 | } | ||
247 | } | ||
248 | else | ||
249 | { | ||
250 | bmp_bytes = 0; | ||
251 | } | ||
252 | |||
253 | outbuf[map_offset++] = bmp_bytes; | ||
254 | write_short((unsigned short)(idx-chars_offset), &outbuf[map_offset]); | ||
255 | idx+=bmp_bytes; | ||
256 | } | ||
257 | |||
258 | outfd = fopen(out_file,"wb"); | ||
259 | if (!outfd) | ||
260 | { | ||
261 | fprintf(stderr, "Can't create output file\n"); | ||
262 | } | ||
263 | |||
264 | i = 0; | ||
265 | for (p1=outbuf; p1 < &outbuf[idx]; p1++) | ||
266 | { | ||
267 | if (i==sizeof(buf)) | ||
268 | { | ||
269 | fwrite(buf, sizeof(unsigned char), sizeof(buf), outfd); | ||
270 | i=0; | ||
271 | } | ||
272 | |||
273 | i++; | ||
274 | buf[i-1] = p1[0]; | ||
275 | } | ||
276 | if (i>0) | ||
277 | fwrite(buf, sizeof(unsigned char), i, outfd); | ||
278 | |||
279 | fclose(outfd); | ||
280 | } | ||
281 | |||
282 | void freeGlyph(BDF_GLYPH* glyph) | ||
283 | { | ||
284 | if ( glyph->glyph_name ) | ||
285 | free( glyph->glyph_name ); | ||
286 | |||
287 | if ( glyph->bitmap ) | ||
288 | free( glyph->bitmap ); | ||
289 | |||
290 | free(glyph); | ||
291 | } | ||
292 | |||
293 | void freeBDF(BDF* bdf) | ||
294 | { | ||
295 | int i; | ||
296 | if ( bdf->bdf_ver ) | ||
297 | free( bdf->bdf_ver ); | ||
298 | if ( bdf->name ) | ||
299 | free( bdf->name ); | ||
300 | |||
301 | for (i=0; i<bdf->prop_count; i++) | ||
302 | { | ||
303 | if ( bdf->prop_name && bdf->prop_name[i] ) | ||
304 | free( bdf->prop_name[i] ); | ||
305 | if ( bdf->prop_value && bdf->prop_value[i] ) | ||
306 | free( bdf->prop_value[i] ); | ||
307 | } | ||
308 | if ( bdf->prop_name ) | ||
309 | free( bdf->prop_name ); | ||
310 | if ( bdf->prop_name ) | ||
311 | free( bdf->prop_value ); | ||
312 | for (i=0; i<bdf->char_count; i++) | ||
313 | { | ||
314 | if ( bdf->glyph && bdf->glyph[i] ) | ||
315 | freeGlyph( bdf->glyph[i] ); | ||
316 | } | ||
317 | if ( bdf->glyph ) | ||
318 | free( bdf->glyph ); | ||
319 | free( bdf ); | ||
320 | } | ||
321 | |||
322 | char *readLine(char *buf, char* line) | ||
323 | { | ||
324 | while (buf[0]=='\n' || buf[0]=='\r') | ||
325 | buf++; | ||
326 | while (buf[0]!='\n' && buf[0]!='\r' && (buf[0])) | ||
327 | { | ||
328 | line++[0] = buf++[0]; | ||
329 | } | ||
330 | line[0] = 0; | ||
331 | return buf; | ||
332 | } | ||
333 | |||
334 | char* readNextToken() | ||
335 | { | ||
336 | char *ret; | ||
337 | char *tok = strtok(0, " "); | ||
338 | if (!tok) | ||
339 | { | ||
340 | fprintf(stderr, "Next token is NULL\n"); | ||
341 | return NULL; | ||
342 | } | ||
343 | |||
344 | ret = malloc(strlen(tok)+1); | ||
345 | if (!ret) | ||
346 | { | ||
347 | fprintf(stderr, "malloc returned 0 in readNextToken\n"); | ||
348 | return NULL; | ||
349 | } | ||
350 | strcpy(ret, tok); | ||
351 | return ret; | ||
352 | } | ||
353 | |||
354 | |||
355 | int readNextIntToken() | ||
356 | { | ||
357 | int ret; | ||
358 | char* tok = readNextToken(); | ||
359 | if (!tok) | ||
360 | { | ||
361 | fprintf(stderr, "Could not int token\n"); | ||
362 | return 0; | ||
363 | } | ||
364 | ret = atoi(tok); | ||
365 | free(tok); | ||
366 | return ret; | ||
367 | } | ||
368 | |||
369 | unsigned char getHexDigit(char c) | ||
370 | { | ||
371 | if (c<='F' && c>='A') | ||
372 | return c-'A'+10; | ||
373 | if (c<='f' && c>='a') | ||
374 | return c-'a'+10; | ||
375 | if (c<='9' && c>='0') | ||
376 | return c-'0'; | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | void toHex(char *str, unsigned char *out) | ||
381 | { | ||
382 | int len = strlen(str); | ||
383 | out[0] = (unsigned char)16*getHexDigit(str[0]) + getHexDigit(str[1]); | ||
384 | out[1] = 0; | ||
385 | |||
386 | if (str[2] && len>2) | ||
387 | out[1] += (unsigned char)16*getHexDigit(str[2]); | ||
388 | if (str[3] && len>3) | ||
389 | out[1] += (unsigned char)getHexDigit(str[3]); | ||
390 | |||
391 | } | ||
392 | |||
393 | BDF* parseBDF(char *bdf) | ||
394 | { | ||
395 | char *p = bdf; | ||
396 | char line[255]; | ||
397 | char *tok = NULL; | ||
398 | int i=0; | ||
399 | int reading_font = 0; | ||
400 | int reading_properties = 0; | ||
401 | int reading_glyph = 0; | ||
402 | int reading_bitmap = 0; | ||
403 | int current_glyph_idx = 0; | ||
404 | int current_property = 0; | ||
405 | unsigned char bitmap[255]; | ||
406 | short bitmap_idx = 0; | ||
407 | |||
408 | BDF *ret = malloc(sizeof(BDF)); | ||
409 | if (!ret) | ||
410 | return NULL; | ||
411 | |||
412 | memset(ret,0,sizeof(BDF)); | ||
413 | |||
414 | while(p[0]) | ||
415 | { | ||
416 | p = readLine(p, line); | ||
417 | tok = strtok(line, " "); | ||
418 | if (tok) | ||
419 | { | ||
420 | if (strcmp(tok, COMMENT)==0) | ||
421 | continue; | ||
422 | |||
423 | if (strcmp(tok, STARTFONT)==0) | ||
424 | { | ||
425 | if (reading_font) | ||
426 | { | ||
427 | fprintf(stderr, "Only one STARTFONT allowed\n"); | ||
428 | freeBDF(ret); | ||
429 | return NULL; | ||
430 | } | ||
431 | reading_font = 1; | ||
432 | ret->bdf_ver = readNextToken(); | ||
433 | if (ret->bdf_ver==0) | ||
434 | { | ||
435 | fprintf(stderr, "Could not read version of BDF\n"); | ||
436 | freeBDF(ret); | ||
437 | return NULL; | ||
438 | } | ||
439 | /* Ignore the rest */ | ||
440 | } | ||
441 | else | ||
442 | { | ||
443 | if (!reading_font) | ||
444 | { | ||
445 | fprintf(stderr, "Font must start with STARTFONT\n"); | ||
446 | freeBDF(ret); | ||
447 | return NULL; | ||
448 | } | ||
449 | |||
450 | if (!strcmp(tok, ENDFONT)) | ||
451 | { | ||
452 | break; | ||
453 | } | ||
454 | else if (!strcmp(tok, FONT)) | ||
455 | { | ||
456 | ret->name = readNextToken(); | ||
457 | if (ret->name==0) | ||
458 | { | ||
459 | fprintf(stderr, "Could not read name font\n"); | ||
460 | freeBDF(ret); | ||
461 | return NULL; | ||
462 | } | ||
463 | } | ||
464 | else if (!strcmp(tok, SIZE)) | ||
465 | { | ||
466 | ret->point_size = readNextIntToken(); | ||
467 | if (ret->point_size<=0) | ||
468 | { | ||
469 | fprintf(stderr, "Font point size is invalid\n"); | ||
470 | freeBDF(ret); | ||
471 | return NULL; | ||
472 | } | ||
473 | |||
474 | ret->x_res = readNextIntToken(); | ||
475 | if (ret->x_res<=0) | ||
476 | { | ||
477 | fprintf(stderr, "Device x resolution is invalid\n"); | ||
478 | freeBDF(ret); | ||
479 | return NULL; | ||
480 | } | ||
481 | ret->y_res = readNextIntToken(); | ||
482 | if (ret->y_res<=0) | ||
483 | { | ||
484 | fprintf(stderr, "Device y resolution is invalid\n"); | ||
485 | freeBDF(ret); | ||
486 | return NULL; | ||
487 | } | ||
488 | } | ||
489 | else if (!strcmp(tok, FONTBOUNDINGBOX)) | ||
490 | { | ||
491 | ret->bound_width = readNextIntToken(); | ||
492 | if (ret->bound_width<=0) | ||
493 | { | ||
494 | fprintf(stderr, "Bounding width is invalid\n"); | ||
495 | freeBDF(ret); | ||
496 | return NULL; | ||
497 | } | ||
498 | ret->bound_height = readNextIntToken(); | ||
499 | if (ret->bound_height<=0) | ||
500 | { | ||
501 | fprintf(stderr, "Bounding height is invalid\n"); | ||
502 | freeBDF(ret); | ||
503 | return NULL; | ||
504 | } | ||
505 | ret->bound_disp_x = readNextIntToken(); | ||
506 | ret->bound_disp_y = readNextIntToken(); | ||
507 | } | ||
508 | else if (!strcmp(tok, STARTPROPERTIES)) | ||
509 | { | ||
510 | ret->prop_count = readNextIntToken(); | ||
511 | if (ret->prop_count<=0) | ||
512 | { | ||
513 | fprintf(stderr, "Number of properties must be > 0\n"); | ||
514 | freeBDF(ret); | ||
515 | return NULL; | ||
516 | } | ||
517 | ret->prop_name = malloc(ret->prop_count*sizeof(char*)); | ||
518 | if (ret->prop_name == 0) | ||
519 | { | ||
520 | fprintf(stderr, "Can't allocate storage for properties (malloc returns 0)\n"); | ||
521 | freeBDF(ret); | ||
522 | return NULL; | ||
523 | } | ||
524 | memset(ret->prop_name, 0, ret->prop_count*sizeof(char*)); | ||
525 | |||
526 | ret->prop_value = malloc(ret->prop_count*sizeof(char*)); | ||
527 | if (ret->prop_value==0) | ||
528 | { | ||
529 | fprintf(stderr, "Can't allocate storage for properties (malloc returns 0)\n"); | ||
530 | freeBDF(ret); | ||
531 | return NULL; | ||
532 | } | ||
533 | memset(ret->prop_value, 0, ret->prop_count*sizeof(char*)); | ||
534 | current_property = 0; | ||
535 | reading_properties = 1; | ||
536 | } | ||
537 | else if (!strcmp(tok, ENDPROPERTIES)) | ||
538 | { | ||
539 | if (!reading_properties) | ||
540 | { | ||
541 | fprintf(stderr, "ENDPROPERTIES found while not reading properties\n"); | ||
542 | freeBDF(ret); | ||
543 | return NULL; | ||
544 | } | ||
545 | if (current_property!=ret->prop_count) | ||
546 | { | ||
547 | fprintf(stderr, "Property count mismatch\n"); | ||
548 | freeBDF(ret); | ||
549 | return NULL; | ||
550 | } | ||
551 | reading_properties = 0; | ||
552 | } | ||
553 | else if (!strcmp(tok, CHARS)) | ||
554 | { | ||
555 | ret->char_count = readNextIntToken(); | ||
556 | if (ret->char_count<=0) | ||
557 | { | ||
558 | fprintf(stderr, "Font must have >0 char glyphs\n"); | ||
559 | freeBDF(ret); | ||
560 | return NULL; | ||
561 | } | ||
562 | |||
563 | ret->glyph = malloc(ret->char_count*sizeof(BDF_GLYPH*)); | ||
564 | if (!ret->glyph) | ||
565 | { | ||
566 | fprintf(stderr, "Can't allocate storage for glyphs (malloc returns 0)\n"); | ||
567 | freeBDF(ret); | ||
568 | return NULL; | ||
569 | } | ||
570 | memset(ret->glyph, 0, ret->char_count*sizeof(BDF_GLYPH*)); | ||
571 | } | ||
572 | else if (!strcmp(tok, STARTCHAR)) | ||
573 | { | ||
574 | if (reading_glyph) | ||
575 | { | ||
576 | fprintf(stderr, "Nested STARTCHAR is not allowed\n"); | ||
577 | freeBDF(ret); | ||
578 | return NULL; | ||
579 | } | ||
580 | if (current_glyph_idx>=ret->char_count) | ||
581 | { | ||
582 | fprintf(stderr, "Too many glyphs (more than defined by CHARS)\n"); | ||
583 | freeBDF(ret); | ||
584 | return NULL; | ||
585 | } | ||
586 | |||
587 | reading_glyph = 1; | ||
588 | ret->glyph[current_glyph_idx] = malloc(sizeof(BDF_GLYPH)); | ||
589 | if (ret->glyph[current_glyph_idx]==0) | ||
590 | { | ||
591 | fprintf(stderr, "Can't allocate storage for one glyph (malloc returns 0)\n"); | ||
592 | freeBDF(ret); | ||
593 | return NULL; | ||
594 | } | ||
595 | memset(ret->glyph[current_glyph_idx],0, sizeof(BDF_GLYPH)); | ||
596 | ret->glyph[current_glyph_idx]->glyph_name = readNextToken(); | ||
597 | |||
598 | memset(bitmap, 0, sizeof(bitmap)); | ||
599 | bitmap_idx = 0; | ||
600 | |||
601 | } | ||
602 | else if (!strcmp(tok, ENDCHAR)) | ||
603 | { | ||
604 | if (!reading_glyph) | ||
605 | { | ||
606 | fprintf(stderr, "ENDCHAR only allowed after STARTCHAR\n"); | ||
607 | freeBDF(ret); | ||
608 | return NULL; | ||
609 | } | ||
610 | reading_glyph = 0; | ||
611 | reading_bitmap = 0; | ||
612 | ret->glyph[current_glyph_idx]->bitmap_len = bitmap_idx/2; | ||
613 | ret->glyph[current_glyph_idx]->bitmap = malloc(bitmap_idx); | ||
614 | if (ret->glyph[current_glyph_idx]->bitmap==0) | ||
615 | { | ||
616 | fprintf(stderr, "Can't allocate storage for bitmap (malloc returns 0)\n"); | ||
617 | freeBDF(ret); | ||
618 | return NULL; | ||
619 | } | ||
620 | |||
621 | for(i=0;i<bitmap_idx;i+=2) | ||
622 | { | ||
623 | ret->glyph[current_glyph_idx]->bitmap[i] = bitmap[i]; | ||
624 | ret->glyph[current_glyph_idx]->bitmap[i+1] = bitmap[i+1]; | ||
625 | } | ||
626 | if (ret->glyph[current_glyph_idx] ==0) | ||
627 | _font_error_code = 3; | ||
628 | |||
629 | if (ret->glyph[current_glyph_idx]->encoding>=0) | ||
630 | { | ||
631 | ret->enc_table[ret->glyph[current_glyph_idx]->encoding] = ret->glyph[current_glyph_idx]; | ||
632 | } | ||
633 | |||
634 | current_glyph_idx++; | ||
635 | } | ||
636 | else if (!strcmp(tok, ENCODING)) | ||
637 | { | ||
638 | if (!reading_glyph) | ||
639 | { | ||
640 | fprintf(stderr, "ENCODING only allowed after STARTCHAR\n"); | ||
641 | freeBDF(ret); | ||
642 | return NULL; | ||
643 | } | ||
644 | ret->glyph[current_glyph_idx]->encoding = readNextIntToken(); | ||
645 | /* TODO: Consider encoding ? */ | ||
646 | } | ||
647 | else if (!strcmp(tok, SWIDTH)) | ||
648 | { | ||
649 | if (!reading_glyph) | ||
650 | { | ||
651 | fprintf(stderr, "SWIDTH only allowed after STARTCHAR\n"); | ||
652 | freeBDF(ret); | ||
653 | return NULL; | ||
654 | } | ||
655 | ret->glyph[current_glyph_idx]->swidth_x = readNextIntToken(); | ||
656 | ret->glyph[current_glyph_idx]->swidth_y = readNextIntToken(); | ||
657 | } | ||
658 | else if (!strcmp(tok, DWIDTH)) | ||
659 | { | ||
660 | if (!reading_glyph) | ||
661 | { | ||
662 | fprintf(stderr, "DWIDTH only allowed after STARTCHAR\n"); | ||
663 | freeBDF(ret); | ||
664 | return NULL; | ||
665 | } | ||
666 | ret->glyph[current_glyph_idx]->dwidth_x = readNextIntToken(); | ||
667 | ret->glyph[current_glyph_idx]->dwidth_y = readNextIntToken(); | ||
668 | } | ||
669 | else if (!strcmp(tok, BBX)) | ||
670 | { | ||
671 | if (!reading_glyph) | ||
672 | { | ||
673 | fprintf(stderr, "BBX only allowed after STARTCHAR\n"); | ||
674 | freeBDF(ret); | ||
675 | return NULL; | ||
676 | } | ||
677 | ret->glyph[current_glyph_idx]->bbx_width = readNextIntToken(); | ||
678 | ret->glyph[current_glyph_idx]->bbx_height = readNextIntToken(); | ||
679 | ret->glyph[current_glyph_idx]->bbx_disp_x = readNextIntToken(); | ||
680 | ret->glyph[current_glyph_idx]->bbx_disp_y = readNextIntToken(); | ||
681 | } | ||
682 | else if (!strcmp(tok, BITMAP)) | ||
683 | { | ||
684 | if (!reading_glyph) | ||
685 | { | ||
686 | fprintf(stderr, "BITMAP only allowed after STARTCHAR\n"); | ||
687 | freeBDF(ret); | ||
688 | return NULL; | ||
689 | } | ||
690 | reading_bitmap = 1; | ||
691 | |||
692 | } | ||
693 | else /* Last one reading properties and bitmaps */ | ||
694 | { | ||
695 | if (reading_glyph && reading_bitmap) | ||
696 | { | ||
697 | toHex(tok, &bitmap[bitmap_idx]); | ||
698 | bitmap_idx+=2; | ||
699 | continue; | ||
700 | } | ||
701 | |||
702 | |||
703 | if (!reading_properties) | ||
704 | { | ||
705 | fprintf(stderr, "Unknown token %s", tok); | ||
706 | continue; | ||
707 | } | ||
708 | if (current_property>=ret->prop_count) | ||
709 | { | ||
710 | fprintf(stderr, "Too many properties\n"); | ||
711 | freeBDF(ret); | ||
712 | return NULL; | ||
713 | } | ||
714 | ret->prop_name[current_property] = malloc(strlen(tok)+1); | ||
715 | if (ret->prop_name[current_property]==0) | ||
716 | { | ||
717 | fprintf(stderr, "Can't allocate storage for one property name (malloc returned 0)\n"); | ||
718 | freeBDF(ret); | ||
719 | return NULL; | ||
720 | } | ||
721 | strcpy(ret->prop_name[current_property], tok); | ||
722 | ret->prop_value[current_property] = readNextToken(); | ||
723 | if (ret->prop_value[current_property]==0) | ||
724 | { | ||
725 | fprintf(stderr, "Can't allocate storage for one property value (malloc returned 0)\n"); | ||
726 | freeBDF(ret); | ||
727 | return NULL; | ||
728 | } | ||
729 | current_property++; | ||
730 | } | ||
731 | |||
732 | } | ||
733 | } | ||
734 | |||
735 | } | ||
736 | |||
737 | return ret; | ||
738 | } | ||
739 | |||
740 | |||
741 | |||
742 | BDF* readFont(const char *name) | ||
743 | { | ||
744 | char buf[1001]; | ||
745 | int count; | ||
746 | char *font_buf = 0; | ||
747 | char *new_buf; | ||
748 | int len = 0; | ||
749 | |||
750 | FILE *fd = fopen(name, "rt"); | ||
751 | if (!fd) | ||
752 | { | ||
753 | fprintf(stderr, "%d %s. ", errno, name); | ||
754 | return NULL; | ||
755 | } | ||
756 | |||
757 | count = fread(buf, sizeof(char), 1000, fd); | ||
758 | |||
759 | new_buf = malloc(count); | ||
760 | if (!new_buf) | ||
761 | { | ||
762 | fprintf(stderr, "mlc=0. len %d.", count); | ||
763 | fclose(fd); | ||
764 | return NULL; | ||
765 | } | ||
766 | |||
767 | memcpy(new_buf, buf, count); | ||
768 | len = count; | ||
769 | font_buf = new_buf; | ||
770 | while (count>0) | ||
771 | { | ||
772 | char *p; | ||
773 | count = fread( buf, sizeof(char), sizeof(buf)-1, fd); | ||
774 | if (count<=0) | ||
775 | break; | ||
776 | p = new_buf; | ||
777 | new_buf = bufcat(new_buf, buf, len, count); | ||
778 | if (!new_buf) | ||
779 | { | ||
780 | fclose(fd); | ||
781 | return NULL; | ||
782 | } | ||
783 | free(p); | ||
784 | len+=count; | ||
785 | font_buf = new_buf; | ||
786 | } | ||
787 | |||
788 | close(fd); | ||
789 | font_buf[len-1] =0; | ||
790 | return parseBDF(font_buf); | ||
791 | } | ||
792 | |||
793 | |||
794 | |||
795 | void test_print(unsigned char c, BDF* font, short* enc_map) | ||
796 | { | ||
797 | int i,j; | ||
798 | BDF_GLYPH *g; | ||
799 | |||
800 | if (enc_map && enc_map[c]>0) | ||
801 | c = enc_map[c]; | ||
802 | g = font->enc_table[c]; | ||
803 | if (!g) | ||
804 | g = font->glyph[c]; | ||
805 | if (!g) | ||
806 | { | ||
807 | fprintf(stderr,"Missing %d \n",c); | ||
808 | return; | ||
809 | } | ||
810 | else | ||
811 | printf("%s %d enc: %d %x \n", | ||
812 | g->glyph_name,c, c, g->encoding, g->encoding); | ||
813 | for (i=0; i < g->bitmap_len; i++) | ||
814 | { | ||
815 | unsigned short bmp = 0; | ||
816 | unsigned short sh; | ||
817 | int db= (g->bitmap[i*2] | (g->bitmap[i*2+1] <<8)); | ||
818 | |||
819 | sh = 1 << 7; /*g->dwidth_x;*/ | ||
820 | |||
821 | for(j=0; j < g->dwidth_x; j++) | ||
822 | { | ||
823 | int b; | ||
824 | unsigned short bit = sh>>j; | ||
825 | if (bit==0) | ||
826 | { | ||
827 | sh = 1 << (sizeof(unsigned short)*8-1); | ||
828 | bit = sh>>(j - 8); | ||
829 | } | ||
830 | b = bit & db; | ||
831 | printf( b ? "*" : " " ); | ||
832 | } | ||
833 | |||
834 | printf("\n"); | ||
835 | } | ||
836 | |||
837 | |||
838 | } | ||
839 | |||
840 | BDF_GLYPH* getGlyph(unsigned char c, BDF* bdf, short* enc_map) | ||
841 | { | ||
842 | BDF_GLYPH* ret; | ||
843 | if (enc_map && enc_map[c]>0) | ||
844 | c = enc_map[c]; | ||
845 | |||
846 | ret = bdf->enc_table[c]; | ||
847 | if (!ret && c < bdf->char_count) | ||
848 | ret = bdf->glyph[c]; | ||
849 | |||
850 | if (!ret) | ||
851 | fprintf(stderr, "Glyph %d is 0.\n", c); | ||
852 | |||
853 | return ret; | ||
854 | } | ||
855 | |||
856 | void test_print2(unsigned char *src, int height, int len) | ||
857 | { | ||
858 | int rows = (height-1)/8+1; | ||
859 | int r,c, bit; | ||
860 | int rp = 0; | ||
861 | int i; | ||
862 | printf("Bitmap: "); | ||
863 | for (i=0;i<len;i++) | ||
864 | printf("0x%x ", src[i]); | ||
865 | printf("\n"); | ||
866 | |||
867 | for (r=0; r < rows; r++) | ||
868 | { | ||
869 | for (bit=0; bit < 8; bit++) | ||
870 | { | ||
871 | int sh = 1 << bit; | ||
872 | for (c=0; c < len/rows; c++) | ||
873 | { | ||
874 | int tst = src[c*rows+r]&sh; | ||
875 | if (tst) | ||
876 | printf("*"); | ||
877 | else | ||
878 | printf(" "); | ||
879 | } | ||
880 | printf("\n"); | ||
881 | if (rp++ > height) | ||
882 | return; | ||
883 | } | ||
884 | } | ||
885 | |||
886 | } | ||
887 | |||
888 | void getBitmap(BDF_GLYPH* g, unsigned char* src) | ||
889 | { | ||
890 | int i,j,k; | ||
891 | int d = 0; | ||
892 | int map_shift = 0; | ||
893 | int rows = (g->bbx_height-1)/8+1; | ||
894 | memset(src, 0, g->bitmap_len*rows); | ||
895 | |||
896 | for (i=0; i < g->bitmap_len; i++) | ||
897 | { | ||
898 | unsigned short bmp = 0; | ||
899 | unsigned short sh, srcmap; | ||
900 | int db= (g->bitmap[i*2] | (g->bitmap[i*2+1] <<8)); | ||
901 | |||
902 | sh = 1 << 7; /*g->dwidth_x;*/ | ||
903 | |||
904 | if (i>0 && (i%8==0)) | ||
905 | { | ||
906 | d++; | ||
907 | map_shift = 0; | ||
908 | } | ||
909 | srcmap = 1<<map_shift++; | ||
910 | |||
911 | for(j=0; j < g->dwidth_x; j++) | ||
912 | { | ||
913 | int b; | ||
914 | unsigned short bit = sh>>j; | ||
915 | if (bit==0) | ||
916 | { | ||
917 | sh = 1 << (sizeof(unsigned short)*8-1); | ||
918 | bit = sh>>(j - 8); | ||
919 | } | ||
920 | b = bit&db; | ||
921 | |||
922 | if (b) | ||
923 | src[j*rows+d] |= srcmap; | ||
924 | } | ||
925 | } | ||
926 | } | ||
927 | |||
diff --git a/tools/bdf2ajf.h b/tools/bdf2ajf.h deleted file mode 100644 index 9f1e70f1fb..0000000000 --- a/tools/bdf2ajf.h +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | /** | ||
2 | * Copyright (C) 2002 Alex Gitelman | ||
3 | * | ||
4 | */ | ||
5 | #ifndef __BDF2AJF__ | ||
6 | #define __BDF2AJF__ | ||
7 | |||
8 | #include "../firmware/ajf.h" | ||
9 | |||
10 | |||
11 | #define STARTFONT "STARTFONT" | ||
12 | #define ENDFONT "ENDFONT" | ||
13 | #define COMMENT "COMMENT" | ||
14 | #define FONT "FONT" | ||
15 | #define SIZE "SIZE" | ||
16 | #define FONTBOUNDINGBOX "FONTBOUNDINGBOX" | ||
17 | #define STARTPROPERTIES "STARTPROPERTIES" | ||
18 | #define ENDPROPERTIES "ENDPROPERTIES" | ||
19 | #define CHARS "CHARS" | ||
20 | #define STARTCHAR "STARTCHAR" | ||
21 | #define ENDCHAR "ENDCHAR" | ||
22 | #define ENCODING "ENCODING" | ||
23 | #define SWIDTH "SWIDTH" | ||
24 | #define DWIDTH "DWIDTH" | ||
25 | #define BBX "BBX" | ||
26 | #define BITMAP "BITMAP" | ||
27 | |||
28 | typedef struct | ||
29 | { | ||
30 | char *glyph_name; | ||
31 | int encoding; | ||
32 | int swidth_x; | ||
33 | int swidth_y; | ||
34 | int dwidth_x; | ||
35 | int dwidth_y; | ||
36 | int bbx_width; | ||
37 | int bbx_height; | ||
38 | int bbx_disp_x; | ||
39 | int bbx_disp_y; | ||
40 | unsigned char *bitmap; | ||
41 | short bitmap_len; | ||
42 | } BDF_GLYPH; | ||
43 | |||
44 | typedef struct | ||
45 | { | ||
46 | char *bdf_ver; | ||
47 | char *name; | ||
48 | int point_size; | ||
49 | int x_res; | ||
50 | int y_res; | ||
51 | int bound_width; | ||
52 | int bound_height; | ||
53 | int bound_disp_x; | ||
54 | int bound_disp_y; | ||
55 | int prop_count; | ||
56 | char **prop_name; | ||
57 | char **prop_value; | ||
58 | int char_count; | ||
59 | BDF_GLYPH** glyph; | ||
60 | BDF_GLYPH* enc_table[256]; | ||
61 | } BDF; | ||
62 | |||
63 | BDF* readFont(const char *name); | ||
64 | BDF_GLYPH* getGlyph(unsigned char c, BDF* bdf, short* enc_map); | ||
65 | void getBitmap(BDF_GLYPH* g, unsigned char* src); | ||
66 | |||
67 | void test_print(unsigned char c, BDF* font, short *map); | ||
68 | void test_print2(unsigned char *src, int height, int len); | ||
69 | |||
70 | |||
71 | extern short win_koi_map[]; | ||
72 | |||
73 | extern int _font_error_code; | ||
74 | extern char _font_error_msg[]; | ||
75 | void report_error(int code, const char *msg); | ||
76 | void writeAJF(BDF* bdf, const char* fname); | ||
77 | |||
78 | |||
79 | |||
80 | |||
81 | |||
82 | |||
83 | #endif | ||
84 | |||