summaryrefslogtreecommitdiff
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
parentd45a1dbe1f8142d9ad98ffe9a689888531dbe399 (diff)
Greg's
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2274 a1c6a512-1295-4272-9138-f99709370657
-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 @@
+/*
+ * 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 <greg@censoft.com>
+ */
+#include <stdio.h>
+
+/* 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; i<pf->size; ++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<width; ++x) printf("-");
+ printf("+\n");
+
+ x = 0;
+ while (height > 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<width; ++x) printf("-");
+ printf("+\n");
+ }
+}
+
+int
+main(int ac, char **av)
+{
+ PMWCFONT pf;
+ MWCFONT font;
+#ifdef FONT
+ /* if FONT defined, just display linked-in font*/
+ extern MWCFONT FONT;
+ pf = &FONT;
+#else
+ if (ac != 2) {
+ printf("usage: loadrbf font.rbf\n");
+ exit(1);
+ }
+
+ pf = rbf_load_font(av[1], &font);
+ if (!pf) {
+ printf("loadrbf: read error: %s\n", av[1]);
+ exit(1);
+ }
+#endif
+ dispfont(pf);
+ return 0;
+}
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 @@
+/*
+ * writerbf - write an incore font in .rbf format.
+ * Must be compiled with -DFONT=font_name and linked
+ * with compiled in font.
+ *
+ * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
+ */
+#include <stdio.h>
+#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; i<pf->bits_size; ++i)
+ WRITESHORT(ofp, pf->bits[i]);
+ if (pf->offset)
+ for (i=0; i<pf->size; ++i)
+ WRITELONG(ofp, pf->offset[i]);
+ if (pf->width)
+ for (i=0; i<pf->size; ++i)
+ WRITEBYTE(ofp, pf->width[i]);
+}
+
+int
+main(int ac, char **av)
+{
+ rbf_write_font(pf);
+}