From 1b5afda12fff58cf8fd820393a6ab13d1fc29501 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 12 Sep 2002 13:59:59 +0000 Subject: Greg's git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2274 a1c6a512-1295-4272-9138-f99709370657 --- tools/loadrbf.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/writerbf.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 tools/loadrbf.c create mode 100644 tools/writerbf.c (limited to 'tools') 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 @@ +/* + * Load an rbf font, store in incore format and display - or - + * Read an incore font and display it. + * + * If FONT defined, just link in FONT and display it + * otherwise, load av[1] and display it + * + * Copyright (c) 2002 by Greg Haerr + */ +#include + +/* this should go in a library...*/ +#define DEBUGF printf +#include "../firmware/loadfont.c" + +#ifdef FONT +extern MWCFONT FONT; +PMWCFONT pf = &FONT; +#endif + +/* printf display an incore font*/ +void +dispfont(PMWCFONT pf) +{ + int i; + + printf("Font: '%s' %dx%d ", pf->name, pf->maxwidth, pf->height); + printf("0x%02x-0x%02x (size %d)\n", pf->firstchar, + pf->firstchar+pf->size, pf->size); + printf("\tDefault char 0x%02x ", pf->defaultchar); + printf("(%s width)\n", pf->width? "proportional": "fixed"); + + for (i=0; isize; ++i) { + int width = pf->width ? pf->width[i] : pf->maxwidth; + int height = pf->height; + int x; + int bitcount = 0; + MWIMAGEBITS *bits = pf->bits + (pf->offset? pf->offset[i]: (height * i)); + MWIMAGEBITS bitvalue; + + printf("\nCharacter 0x%02x (width %d)\n", i+pf->firstchar, width); + printf("+"); + for (x=0; x 0) { + if (x == 0) printf("|"); + + if (bitcount <= 0) { + bitcount = MWIMAGE_BITSPERIMAGE; + bitvalue = *bits++; + } + + printf( MWIMAGE_TESTBIT(bitvalue)? "*": " "); + + bitvalue = MWIMAGE_SHIFTBIT(bitvalue); + --bitcount; + if (++x == width) { + printf("|\n"); + --height; + x = 0; + bitcount = 0; + } + } + printf("+"); + for (x=0; x + */ +#include +#include "../firmware/font.h" + +extern MWCFONT FONT; +PMWCFONT pf = &FONT; + +static int +WRITEBYTE(FILE *fp, unsigned char c) +{ + return putc(c, fp) != EOF; +} + +static int +WRITESHORT(FILE *fp, unsigned short s) +{ + putc(s, fp); + return putc(s>>8, fp) != EOF; +} + +static int +WRITELONG(FILE *fp, unsigned long l) +{ + putc(l, fp); + putc(l>>8, fp); + putc(l>>16, fp); + return putc(l>>24, fp) != EOF; +} + +static int +WRITESTR(FILE *fp, char *str, int count) +{ + return fwrite(str, 1, count, fp) == count; +} + +static int +WRITESTRPAD(FILE *fp, char *str, int totlen) +{ + int ret; + + while (*str && totlen > 0) + if (*str) { + ret = putc(*str++, fp); + --totlen; + } + while (--totlen >= 0) + ret = putc(' ', fp); + return ret; +} + +/* write font, < 0 return is error*/ +int +rbf_write_font(PMWCFONT pf) +{ + FILE *ofp; + int i; + char name[256]; + + sprintf(name, "%s.fnt", pf->name); + ofp = fopen(name, "wb"); + if (!ofp) + return -1; + + /* write magic and version #*/ + WRITESTR(ofp, VERSION, 4); + + /* internal font name*/ + WRITESTRPAD(ofp, pf->name, 64); + + /* copyright - FIXME not converted with bdf2c*/ + WRITESTRPAD(ofp, " ", 256); + + /* font info*/ + WRITESHORT(ofp, pf->maxwidth); + WRITESHORT(ofp, pf->height); + WRITESHORT(ofp, pf->ascent); + WRITELONG(ofp, pf->firstchar); + WRITELONG(ofp, pf->defaultchar); + WRITELONG(ofp, pf->size); + + /* variable font data sizes*/ + WRITELONG(ofp, pf->bits_size); /* # words of MWIMAGEBITS*/ + WRITELONG(ofp, pf->offset? pf->size: 0); /* # longs of offset*/ + WRITELONG(ofp, pf->width? pf->size: 0); /* # bytes of width*/ + + /* variable font data*/ + for (i=0; ibits_size; ++i) + WRITESHORT(ofp, pf->bits[i]); + if (pf->offset) + for (i=0; isize; ++i) + WRITELONG(ofp, pf->offset[i]); + if (pf->width) + for (i=0; isize; ++i) + WRITEBYTE(ofp, pf->width[i]); +} + +int +main(int ac, char **av) +{ + rbf_write_font(pf); +} -- cgit v1.2.3