summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-09-12 13:59:59 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-09-12 13:59:59 +0000
commit1b5afda12fff58cf8fd820393a6ab13d1fc29501 (patch)
tree83e5abe54ac3e9f4ca41d740b6640f5c35e790eb /tools
parentd45a1dbe1f8142d9ad98ffe9a689888531dbe399 (diff)
downloadrockbox-1b5afda12fff58cf8fd820393a6ab13d1fc29501.tar.gz
rockbox-1b5afda12fff58cf8fd820393a6ab13d1fc29501.zip
Greg's
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2274 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rw-r--r--tools/loadrbf.c95
-rw-r--r--tools/writerbf.c107
2 files changed, 202 insertions, 0 deletions
diff --git a/tools/loadrbf.c b/tools/loadrbf.c
new file mode 100644
index 0000000000..769195ea99
--- /dev/null
+++ b/tools/loadrbf.c
@@ -0,0 +1,95 @@
1/*
2 * Load an rbf font, store in incore format and display - or -
3 * Read an incore font and display it.
4 *
5 * If FONT defined, just link in FONT and display it
6 * otherwise, load av[1] and display it
7 *
8 * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
9 */
10#include <stdio.h>
11
12/* this should go in a library...*/
13#define DEBUGF printf
14#include "../firmware/loadfont.c"
15
16#ifdef FONT
17extern MWCFONT FONT;
18PMWCFONT pf = &FONT;
19#endif
20
21/* printf display an incore font*/
22void
23dispfont(PMWCFONT pf)
24{
25 int i;
26
27 printf("Font: '%s' %dx%d ", pf->name, pf->maxwidth, pf->height);
28 printf("0x%02x-0x%02x (size %d)\n", pf->firstchar,
29 pf->firstchar+pf->size, pf->size);
30 printf("\tDefault char 0x%02x ", pf->defaultchar);
31 printf("(%s width)\n", pf->width? "proportional": "fixed");
32
33 for (i=0; i<pf->size; ++i) {
34 int width = pf->width ? pf->width[i] : pf->maxwidth;
35 int height = pf->height;
36 int x;
37 int bitcount = 0;
38 MWIMAGEBITS *bits = pf->bits + (pf->offset? pf->offset[i]: (height * i));
39 MWIMAGEBITS bitvalue;
40
41 printf("\nCharacter 0x%02x (width %d)\n", i+pf->firstchar, width);
42 printf("+");
43 for (x=0; x<width; ++x) printf("-");
44 printf("+\n");
45
46 x = 0;
47 while (height > 0) {
48 if (x == 0) printf("|");
49
50 if (bitcount <= 0) {
51 bitcount = MWIMAGE_BITSPERIMAGE;
52 bitvalue = *bits++;
53 }
54
55 printf( MWIMAGE_TESTBIT(bitvalue)? "*": " ");
56
57 bitvalue = MWIMAGE_SHIFTBIT(bitvalue);
58 --bitcount;
59 if (++x == width) {
60 printf("|\n");
61 --height;
62 x = 0;
63 bitcount = 0;
64 }
65 }
66 printf("+");
67 for (x=0; x<width; ++x) printf("-");
68 printf("+\n");
69 }
70}
71
72int
73main(int ac, char **av)
74{
75 PMWCFONT pf;
76 MWCFONT font;
77#ifdef FONT
78 /* if FONT defined, just display linked-in font*/
79 extern MWCFONT FONT;
80 pf = &FONT;
81#else
82 if (ac != 2) {
83 printf("usage: loadrbf font.rbf\n");
84 exit(1);
85 }
86
87 pf = rbf_load_font(av[1], &font);
88 if (!pf) {
89 printf("loadrbf: read error: %s\n", av[1]);
90 exit(1);
91 }
92#endif
93 dispfont(pf);
94 return 0;
95}
diff --git a/tools/writerbf.c b/tools/writerbf.c
new file mode 100644
index 0000000000..b3ba8649ac
--- /dev/null
+++ b/tools/writerbf.c
@@ -0,0 +1,107 @@
1/*
2 * writerbf - write an incore font in .rbf format.
3 * Must be compiled with -DFONT=font_name and linked
4 * with compiled in font.
5 *
6 * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
7 */
8#include <stdio.h>
9#include "../firmware/font.h"
10
11extern MWCFONT FONT;
12PMWCFONT pf = &FONT;
13
14static int
15WRITEBYTE(FILE *fp, unsigned char c)
16{
17 return putc(c, fp) != EOF;
18}
19
20static int
21WRITESHORT(FILE *fp, unsigned short s)
22{
23 putc(s, fp);
24 return putc(s>>8, fp) != EOF;
25}
26
27static int
28WRITELONG(FILE *fp, unsigned long l)
29{
30 putc(l, fp);
31 putc(l>>8, fp);
32 putc(l>>16, fp);
33 return putc(l>>24, fp) != EOF;
34}
35
36static int
37WRITESTR(FILE *fp, char *str, int count)
38{
39 return fwrite(str, 1, count, fp) == count;
40}
41
42static int
43WRITESTRPAD(FILE *fp, char *str, int totlen)
44{
45 int ret;
46
47 while (*str && totlen > 0)
48 if (*str) {
49 ret = putc(*str++, fp);
50 --totlen;
51 }
52 while (--totlen >= 0)
53 ret = putc(' ', fp);
54 return ret;
55}
56
57/* write font, < 0 return is error*/
58int
59rbf_write_font(PMWCFONT pf)
60{
61 FILE *ofp;
62 int i;
63 char name[256];
64
65 sprintf(name, "%s.fnt", pf->name);
66 ofp = fopen(name, "wb");
67 if (!ofp)
68 return -1;
69
70 /* write magic and version #*/
71 WRITESTR(ofp, VERSION, 4);
72
73 /* internal font name*/
74 WRITESTRPAD(ofp, pf->name, 64);
75
76 /* copyright - FIXME not converted with bdf2c*/
77 WRITESTRPAD(ofp, " ", 256);
78
79 /* font info*/
80 WRITESHORT(ofp, pf->maxwidth);
81 WRITESHORT(ofp, pf->height);
82 WRITESHORT(ofp, pf->ascent);
83 WRITELONG(ofp, pf->firstchar);
84 WRITELONG(ofp, pf->defaultchar);
85 WRITELONG(ofp, pf->size);
86
87 /* variable font data sizes*/
88 WRITELONG(ofp, pf->bits_size); /* # words of MWIMAGEBITS*/
89 WRITELONG(ofp, pf->offset? pf->size: 0); /* # longs of offset*/
90 WRITELONG(ofp, pf->width? pf->size: 0); /* # bytes of width*/
91
92 /* variable font data*/
93 for (i=0; i<pf->bits_size; ++i)
94 WRITESHORT(ofp, pf->bits[i]);
95 if (pf->offset)
96 for (i=0; i<pf->size; ++i)
97 WRITELONG(ofp, pf->offset[i]);
98 if (pf->width)
99 for (i=0; i<pf->size; ++i)
100 WRITEBYTE(ofp, pf->width[i]);
101}
102
103int
104main(int ac, char **av)
105{
106 rbf_write_font(pf);
107}