diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-09-20 08:07:51 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-09-20 08:07:51 +0000 |
commit | bed3d3f7e06c6582f9677ab6222cd89c84a9c8c7 (patch) | |
tree | 59ef1faa129f0813071d5e81b2e55b5d04886202 /tools | |
parent | eb5cc653dba373f2d2ce48f8efbc0b19a424971e (diff) | |
download | rockbox-bed3d3f7e06c6582f9677ab6222cd89c84a9c8c7.tar.gz rockbox-bed3d3f7e06c6582f9677ab6222cd89c84a9c8c7.zip |
New full ISO-8859-1 system font.
Added font loading from dir browser.
Changed default font location to /.rockbox/default.fnt.
Code-policed font code.
Removed old font tools.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2347 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/bdf2c | 217 | ||||
-rwxr-xr-x | tools/bdf2fnt | 39 | ||||
-rw-r--r-- | tools/convbdf.c | 287 | ||||
-rw-r--r-- | tools/loadrbf.c | 95 | ||||
-rw-r--r-- | tools/writerbf.c | 112 |
5 files changed, 142 insertions, 608 deletions
diff --git a/tools/bdf2c b/tools/bdf2c deleted file mode 100755 index 6832e5ce8f..0000000000 --- a/tools/bdf2c +++ /dev/null @@ -1,217 +0,0 @@ -#! /usr/bin/perl -w -# -# Convert BDF files to incore MWCFONT structure 'C' source -# Copyright (c) 2002 by Greg Haerr <greg@censoft.com> -# -# from The Microwindows Project (http://microwindows.org) -# -# modified 09/13/02 correct output when no DEFAULT_CHAR, allow numeric font name -# modified 09/12/02 added -limit <max_encode_hex_value> option -# modified on 09/10/02 by G Haerr -# - fixed DWIDTH 0 parsing -# - don't limit font size to 0x7e characters -# - changed offset data to unsigned long for large fonts -# - don't generate width table if fixed-width -# - added defaultchar to output -# - added bits_size member for loadable fonts -# modified on 3/26/00 by G Haerr added ascent field, fixed $IMAGE_BITS -# modified on 2/10/00 by K Harris to accept any size input character -# modified by G Haerr from bdftobogl for 16 bit MWIMAGEBITS -# originally from BOGL - Ben's Own Graphics Library <pfaffben@debian.org>. - -use POSIX; - -$name = (reverse split /\//, $0)[0]; -$limit_char = 65535; - -while (defined $ARGV[0]) { - my $arg = shift; - - if (($arg eq "-limit") && scalar(@ARGV) > 0) { - $limit_char = hex shift; - } elsif ($arg =~ "-.+") { - print "$name: unknown option '$arg'\n"; - exit 1; - } else { - unshift(@ARGV, $arg); - last; - } -} - -if ($#ARGV < 0) { - print "Usage: $name [-limit <max_encode_hex_value>] font.bdf > font.c\n"; - exit 1; -} - -$IMAGE_BITS = 16; -$IMAGE_NIBBLES = $IMAGE_BITS/4; -$IMAGE_MASK = 0xffff; - -$file = $ARGV[0]; - -$font = $file; -$font =~ s/\.bdf//; -$font =~ tr/a-zA-Z0-9_/_/cs; - -print "/* Generated by $name on ", substr(`date`, 0, -1), ". */\n"; -print "#include \"font.h\"\n\n"; - -open BDF, "<$file" || die; -while (<BDF>) { - chop; - $pixel_size = $1 if /^PIXEL_SIZE (\d+)$/; - $font_ascent = $1 if /^FONT_ASCENT (\d+)$/; - $font_descent = $1 if /^FONT_DESCENT (\d+)$/; - $font_name = $1 if /^FONT (.*)$/; - $default_char = $1 if /^DEFAULT_CHAR (\d+)$/; - ($fbbw, $fbbh, $fbbx, $fbby) = ($1, $2, $3, $4) if /^FONTBOUNDINGBOX (-?\d+) (-?\d+) (-?\d+) (-?\d+)/; - - last if /^CHARS /; -} - -$font_width = $fbbw - $fbbx; -undef $fbbw, undef $fbbh, undef $fbbx, undef $fbby; - -print "/* Font information:\n\n"; -print " name: $font_name\n"; -print " pixel size: $pixel_size\n" if defined $pixel_size; -print " ascent: $font_ascent\n"; -print " descent: $font_descent\n"; -print "*/\n\n"; - -print "/* Font character bitmap data. */\n"; -print "static MWIMAGEBITS _${font}_bits[] = {\n"; - -$ch_height = $font_ascent + $font_descent; -$ofs = 0; -$maxwidth = 0; -$firstchar = -1; -$lastchar = -1; -while (<BDF>) { - chop; - undef $encoding, undef $width, undef $bbx, undef $bby, undef $bbw, undef $bbh if /^STARTCHAR /; - $encoding = $1 if /^ENCODING (\d+)/; - last if defined $encoding && $encoding > $limit_char; - $width = $1 if /^DWIDTH (-?\d+)/; - $width = $font_width if defined $width && $width <= 0; - ($bbw, $bbh, $bbx, $bby) = ($1, $2, $3, $4) if /^BBX (-?\d+) (-?\d+) (-?\d+) (-?\d+)/; - - if (/^BITMAP$/) { - next if !defined $encoding; - $firstchar = $encoding if $firstchar < 0; - $lastchar = $encoding if $lastchar < $encoding; - $encoding_tab[$encoding] = $ofs; - $width -= $bbx, $bbx = 0 if $bbx < 0; - $width[$encoding] = $width; - $maxwidth = $width if $width > $maxwidth; - $ch_words = int (($width+$IMAGE_BITS-1)/$IMAGE_BITS); - $ch_bits = $ch_words*$IMAGE_BITS; - for (my $i = 0; $i < $ch_height; $i++) { - for (my $k = 0; $k < $ch_words; $k++) { - $bm[$i][$k] = 0; - } - } - for (my $i = 0; ; $i++) { - $_ = <BDF>; - chop; - last if /^ENDCHAR$/; - - @hexnibbles = split //,$_; - for (my $k=0; $k<$ch_words; $k++) { - $ndx = $k*$IMAGE_NIBBLES; - $padnibbles = @hexnibbles - $ndx; - last if $padnibbles <= 0; # if bbx pushes bits into next word - # and no more bits from bdf file - $padnibbles = 0 if $padnibbles >= $IMAGE_NIBBLES; - $value = hex join '',@hexnibbles[$ndx..($ndx+$IMAGE_NIBBLES-1-$padnibbles)]; - $value = $value << ($padnibbles*$IMAGE_NIBBLES); - $bm[$ch_height - $font_descent - $bby - $bbh + $i][$k] |= - $value >> ($bbx); - if ($bbx) { # handle overflow into next image_word - $bm[$ch_height - $font_descent - $bby - $bbh + $i][$k+1] = - ($value << ($IMAGE_BITS - $bbx)) & $IMAGE_MASK; - } - } - } - -### printf "\n/* Character %c (0x%02x):\n", $encoding, $encoding; - printf "\n/* Character (0x%02x):\n", $encoding; - print " bbw=$bbw, bbh=$bbh, bbx=$bbx, bby=$bby, width=$width\n"; - print " +", ("-" x $ch_bits), "+\n"; - for (my $i = 0; $i < $ch_height; $i++) { - print " |"; - for (my $k = 0; $k < $ch_words; $k++) { - for (my $j = $IMAGE_BITS - 1; $j >= 0; $j--) { - print $bm[$i][$k] & (1 << $j) ? "*" : " "; - } - } - print "|\n"; - } - print " +", ("-" x $ch_bits), "+ */\n"; - - for (my $i = 0; $i < $ch_height; $i++) { - for ($k=0; $k<$ch_words; $k++) { - $ofs++; - printf "0x%04x, ", $bm[$i][$k]; - } - printf "\n"; - } - } -} - -print "};\n\n"; - -##print STDERR "Maximum character width=$maxwidth\n"; - -$default_char = $firstchar if !defined $default_char; - -print "/* Character->glyph mapping. */\n"; -print "static unsigned long _${font}_offset[] = {\n"; -for (my $i = $firstchar; $i <= $lastchar; $i++) { - my $char = $i; - my $ofs = $encoding_tab[$i]; - $ofs = $encoding_tab[$default_char], $char = $default_char if !defined $ofs; -### printf " $ofs,\t/* %c (0x%02x) */\n", $char, $i; - printf " $ofs,\t/* (0x%02x) */\n", $i; -} -print "};\n\n"; - -$gen_width_table = 0; -for (my $i = $firstchar; $i <= $lastchar; $i++) { - my $char = $i; - my $width = $width[$i]; - $width = $width[$default_char] if !defined $encoding_tab[$i]; - $gen_width_table = 1 if $width != $maxwidth -} - -if ($gen_width_table) { - print "/* Character width data. */\n"; - print "static unsigned char _${font}_width[] = {\n"; - for (my $i = $firstchar; $i <= $lastchar; $i++) { - my $char = $i; - my $width = $width[$i]; - $width = $width[$default_char], $char = $default_char if !defined $encoding_tab[$i]; - ### printf " $width,\t/* %c (0x%02x) */\n", $char, $i; - printf " $width,\t/* (0x%02x) */\n", $i; - } - print "};\n\n"; -} - -$size = $lastchar - $firstchar + 1; - -print "/* Exported structure definition. */\n"; -print "MWCFONT font_${font} = {\n"; -print " \"$font\",\n"; -print " $maxwidth,\n"; -print " $ch_height,\n"; -print " $font_ascent,\n"; -print " $firstchar,\n"; -print " $size,\n"; -print " _${font}_bits,\n"; -print " _${font}_offset,\n"; -if ($gen_width_table) { - print " _${font}_width,\n"; -} else { print " 0, /* fixed width*/\n"; } -print " $default_char,\n"; -print " sizeof(_${font}_bits)/sizeof(MWIMAGEBITS),\n"; -print "};\n"; diff --git a/tools/bdf2fnt b/tools/bdf2fnt deleted file mode 100755 index 2793d11764..0000000000 --- a/tools/bdf2fnt +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# -# bdf2fnt - shell script to convert a BDF file to RBF format -# -# usage: bdf2fnt bdffile (don't use .bdf extension!) -# -# Example: bdf2fnt courB08 -# creates ./courB08.fnt and /tmp/courB08.c -# the .fnt file can be renamed /system.fnt for loading -# the .c file can be moved to firmware dir to compile-in font -# - -# convert from bdf to C source -./bdf2c $1.bdf > /tmp/$1.c - -# compile writerbf with linked C source font -gcc -DARCHOS_RECORDER -DFONT=font_$1 -I../firmware -I../firmware/common -o /tmp/writerbf writerbf.c /tmp/$1.c - -# run writerbf, will write linked incore font to .rbf format -/tmp/writerbf -rm /tmp/writerbf - -# load .rbf font and display it for test -gcc -DARCHOS_RECORDER -DMAX_FONT_SIZE=500000 -I../firmware/common -o /tmp/loadrbf loadrbf.c -/tmp/loadrbf $1.fnt > /tmp/$1.1 -rm /tmp/loadrbf - -# link .c font and diff with .fnt load for test -gcc -DARCHOS_RECORDER -DFONT=font_$1 -I../firmware -I../firmware/common -o /tmp/loadrbf loadrbf.c /tmp/$1.c -/tmp/loadrbf > /tmp/$1.2 -rm /tmp/loadrbf - -# -# we diff the output to ensure correctness -diff /tmp/$1.1 /tmp/$1.2 - -# clean up -rm /tmp/$1.1 /tmp/$1.2 -#rm /tmp/$1.c diff --git a/tools/convbdf.c b/tools/convbdf.c index c8e5837575..00db9ae61f 100644 --- a/tools/convbdf.c +++ b/tools/convbdf.c @@ -16,31 +16,31 @@ /* loadable font magic and version #*/ #define VERSION "RB11" -/* MWIMAGEBITS helper macros*/ -#define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/ -#define MWIMAGE_BYTES(x) (MWIMAGE_WORDS(x)*sizeof(MWIMAGEBITS)) -#define MWIMAGE_BITSPERIMAGE (sizeof(MWIMAGEBITS) * 8) -#define MWIMAGE_BITVALUE(n) ((MWIMAGEBITS) (((MWIMAGEBITS) 1) << (n))) -#define MWIMAGE_FIRSTBIT (MWIMAGE_BITVALUE(MWIMAGE_BITSPERIMAGE - 1)) -#define MWIMAGE_TESTBIT(m) ((m) & MWIMAGE_FIRSTBIT) -#define MWIMAGE_SHIFTBIT(m) ((MWIMAGEBITS) ((m) << 1)) +/* bitmap_t helper macros*/ +#define BITMAP_WORDS(x) (((x)+15)/16) /* image size in words*/ +#define BITMAP_BYTES(x) (BITMAP_WORDS(x)*sizeof(bitmap_t)) +#define BITMAP_BITSPERIMAGE (sizeof(bitmap_t) * 8) +#define BITMAP_BITVALUE(n) ((bitmap_t) (((bitmap_t) 1) << (n))) +#define BITMAP_FIRSTBIT (BITMAP_BITVALUE(BITMAP_BITSPERIMAGE - 1)) +#define BITMAP_TESTBIT(m) ((m) & BITMAP_FIRSTBIT) +#define BITMAP_SHIFTBIT(m) ((bitmap_t) ((m) << 1)) -typedef unsigned short MWIMAGEBITS; /* bitmap image unit size*/ +typedef unsigned short bitmap_t; /* bitmap image unit size*/ /* builtin C-based proportional/fixed font structure */ /* based on The Microwindows Project http://microwindows.org */ -typedef struct { +struct font { char * name; /* font name*/ int maxwidth; /* max width in pixels*/ int height; /* height in pixels*/ int ascent; /* ascent (baseline) height*/ int firstchar; /* first character in bitmap*/ int size; /* font size in glyphs*/ - MWIMAGEBITS * bits; /* 16-bit right-padded bitmap data*/ - unsigned long * offset; /* offsets into bitmap data*/ - unsigned char * width; /* character widths or NULL if fixed*/ + bitmap_t* bits; /* 16-bit right-padded bitmap data*/ + unsigned long* offset; /* offsets into bitmap data*/ + unsigned char* width; /* character widths or NULL if fixed*/ int defaultchar; /* default char (not glyph index)*/ - long bits_size; /* # words of MWIMAGEBITS bits*/ + long bits_size; /* # words of bitmap_t bits*/ /* unused by runtime system, read in by convbdf*/ char * facename; /* facename of font*/ @@ -48,7 +48,7 @@ typedef struct { int pixel_size; int descent; int fbbw, fbbh, fbbx, fbby; -} MWCFONT, *PMWCFONT; +}; /* END font.h*/ #define isprefix(buf,str) (!strncmp(buf, str, strlen(str))) @@ -64,19 +64,19 @@ int limit_char = 65535; int oflag = 0; char outfile[256]; -void usage(void); -void getopts(int *pac, char ***pav); -int convbdf(char *path); +void usage(void); +void getopts(int *pac, char ***pav); +int convbdf(char *path); -void free_font(PMWCFONT pf); -PMWCFONT bdf_read_font(char *path); -int bdf_read_header(FILE *fp, PMWCFONT pf); -int bdf_read_bitmaps(FILE *fp, PMWCFONT pf); -char * bdf_getline(FILE *fp, char *buf, int len); -MWIMAGEBITS bdf_hexval(unsigned char *buf, int ndx1, int ndx2); +void free_font(struct font* pf); +struct font* bdf_read_font(char *path); +int bdf_read_header(FILE *fp, struct font* pf); +int bdf_read_bitmaps(FILE *fp, struct font* pf); +char * bdf_getline(FILE *fp, char *buf, int len); +bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2); -int gen_c_source(PMWCFONT pf, char *path); -int gen_fnt_file(PMWCFONT pf, char *path); +int gen_c_source(struct font* pf, char *path); +int gen_fnt_file(struct font* pf, char *path); void usage(void) @@ -96,8 +96,7 @@ usage(void) } /* parse command line options*/ -void -getopts(int *pac, char ***pav) +void getopts(int *pac, char ***pav) { char *p; char **av; @@ -171,8 +170,7 @@ getopts(int *pac, char ***pav) } /* remove directory prefix and file suffix from full path*/ -char * -basename(char *path) +char *basename(char *path) { char *p, *b; static char base[256]; @@ -193,10 +191,9 @@ basename(char *path) return base; } -int -convbdf(char *path) +int convbdf(char *path) { - PMWCFONT pf; + struct font* pf; int ret = 0; pf = bdf_read_font(path); @@ -223,8 +220,7 @@ convbdf(char *path) return ret; } -int -main(int ac, char **av) +int main(int ac, char **av) { int ret = 0; @@ -251,8 +247,7 @@ main(int ac, char **av) } /* free font structure*/ -void -free_font(PMWCFONT pf) +void free_font(struct font* pf) { if (!pf) return; @@ -270,11 +265,10 @@ free_font(PMWCFONT pf) } /* build incore structure from .bdf file*/ -PMWCFONT -bdf_read_font(char *path) +struct font* bdf_read_font(char *path) { FILE *fp; - PMWCFONT pf; + struct font* pf; fp = fopen(path, "rb"); if (!fp) { @@ -282,7 +276,7 @@ bdf_read_font(char *path) return NULL; } - pf = (PMWCFONT)calloc(1, sizeof(MWCFONT)); + pf = (struct font*)calloc(1, sizeof(struct font)); if (!pf) goto errout; @@ -308,8 +302,7 @@ bdf_read_font(char *path) } /* read bdf font header information, return 0 on error*/ -int -bdf_read_header(FILE *fp, PMWCFONT pf) +int bdf_read_header(FILE *fp, struct font* pf) { int encoding; int nchars, maxwidth; @@ -391,7 +384,10 @@ bdf_read_header(FILE *fp, PMWCFONT pf) fprintf(stderr, "Error: bad 'ENCODING'\n"); return 0; } - if (encoding >= 0 && encoding <= limit_char && encoding >= start_char) { + if (encoding >= 0 && + encoding <= limit_char && + encoding >= start_char) { + if (firstchar > encoding) firstchar = encoding; if (lastchar < encoding) @@ -411,7 +407,9 @@ bdf_read_header(FILE *fp, PMWCFONT pf) pf->height = pf->ascent + pf->descent; /* calc default char*/ - if (pf->defaultchar < 0 || pf->defaultchar < firstchar) + if (pf->defaultchar < 0 || + pf->defaultchar < firstchar || + pf->defaultchar > limit_char ) pf->defaultchar = firstchar; /* calc font size (offset/width entries)*/ @@ -423,10 +421,10 @@ bdf_read_header(FILE *fp, PMWCFONT pf) maxwidth = pf->fbbw; /* initially use font maxwidth * height for bits allocation*/ - pf->bits_size = nchars * MWIMAGE_WORDS(maxwidth) * pf->height; + pf->bits_size = nchars * BITMAP_WORDS(maxwidth) * pf->height; /* allocate bits, offset, and width arrays*/ - pf->bits = (MWIMAGEBITS *)malloc(pf->bits_size * sizeof(MWIMAGEBITS) + EXTRA); + pf->bits = (bitmap_t *)malloc(pf->bits_size * sizeof(bitmap_t) + EXTRA); pf->offset = (unsigned long *)malloc(pf->size * sizeof(unsigned long)); pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char)); @@ -439,8 +437,7 @@ bdf_read_header(FILE *fp, PMWCFONT pf) } /* read bdf font bitmaps, return 0 on error*/ -int -bdf_read_bitmaps(FILE *fp, PMWCFONT pf) +int bdf_read_bitmaps(FILE *fp, struct font* pf) { long ofs = 0; int maxwidth = 0; @@ -494,7 +491,7 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf) continue; } if (strequal(buf, "BITMAP")) { - MWIMAGEBITS *ch_bitmap = pf->bits + ofs; + bitmap_t *ch_bitmap = pf->bits + ofs; int ch_words; if (encoding < 0) @@ -520,11 +517,11 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf) pf->width[encoding-pf->firstchar] = width; /* clear bitmap*/ - memset(ch_bitmap, 0, MWIMAGE_BYTES(width) * pf->height); + memset(ch_bitmap, 0, BITMAP_BYTES(width) * pf->height); - ch_words = MWIMAGE_WORDS(width); + ch_words = BITMAP_WORDS(width); #define BM(row,col) (*(ch_bitmap + ((row)*ch_words) + (col))) -#define MWIMAGE_NIBBLES (MWIMAGE_BITSPERIMAGE/4) +#define BITMAP_NIBBLES (BITMAP_BITSPERIMAGE/4) /* read bitmaps*/ for (i=0; ; ++i) { @@ -539,30 +536,30 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf) hexnibbles = strlen(buf); for (k=0; k<ch_words; ++k) { - int ndx = k * MWIMAGE_NIBBLES; + int ndx = k * BITMAP_NIBBLES; int padnibbles = hexnibbles - ndx; - MWIMAGEBITS value; + bitmap_t value; if (padnibbles <= 0) break; - if (padnibbles >= MWIMAGE_NIBBLES) + if (padnibbles >= BITMAP_NIBBLES) padnibbles = 0; value = bdf_hexval((unsigned char *)buf, - ndx, ndx+MWIMAGE_NIBBLES-1-padnibbles); - value <<= padnibbles * MWIMAGE_NIBBLES; + ndx, ndx+BITMAP_NIBBLES-1-padnibbles); + value <<= padnibbles * BITMAP_NIBBLES; BM(pf->height - pf->descent - bby - bbh + i, k) |= value >> bbx; /* handle overflow into next image word*/ if (bbx) { BM(pf->height - pf->descent - bby - bbh + i, k+1) = - value << (MWIMAGE_BITSPERIMAGE - bbx); + value << (BITMAP_BITSPERIMAGE - bbx); } } } - ofs += MWIMAGE_WORDS(width) * pf->height; + ofs += BITMAP_WORDS(width) * pf->height; continue; } @@ -590,7 +587,7 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf) encodetable = 1; break; } - l += MWIMAGE_WORDS(pf->width[i]) * pf->height; + l += BITMAP_WORDS(pf->width[i]) * pf->height; } if (!encodetable) { free(pf->offset); @@ -611,23 +608,25 @@ bdf_read_bitmaps(FILE *fp, PMWCFONT pf) /* reallocate bits array to actual bits used*/ if (ofs < pf->bits_size) { - pf->bits = realloc(pf->bits, ofs * sizeof(MWIMAGEBITS)); + pf->bits = realloc(pf->bits, ofs * sizeof(bitmap_t)); pf->bits_size = ofs; - } else if (ofs > pf->bits_size) { - fprintf(stderr, "Warning: DWIDTH spec > max FONTBOUNDINGBOX\n"); - if (ofs > pf->bits_size+EXTRA) { - fprintf(stderr, "Error: Not enough bits initially allocated\n"); - return 0; + } + else { + if (ofs > pf->bits_size) { + fprintf(stderr, "Warning: DWIDTH spec > max FONTBOUNDINGBOX\n"); + if (ofs > pf->bits_size+EXTRA) { + fprintf(stderr, "Error: Not enough bits initially allocated\n"); + return 0; + } + pf->bits_size = ofs; } - pf->bits_size = ofs; } return 1; } /* read the next non-comment line, returns buf or NULL if EOF*/ -char * -bdf_getline(FILE *fp, char *buf, int len) +char *bdf_getline(FILE *fp, char *buf, int len) { int c; char *b; @@ -653,36 +652,37 @@ bdf_getline(FILE *fp, char *buf, int len) } /* return hex value of portion of buffer*/ -MWIMAGEBITS -bdf_hexval(unsigned char *buf, int ndx1, int ndx2) +bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2) { - MWIMAGEBITS val = 0; + bitmap_t val = 0; int i, c; for (i=ndx1; i<=ndx2; ++i) { c = buf[i]; if (c >= '0' && c <= '9') c -= '0'; - else if (c >= 'A' && c <= 'F') - c = c - 'A' + 10; - else if (c >= 'a' && c <= 'f') - c = c - 'a' + 10; - else c = 0; + else + if (c >= 'A' && c <= 'F') + c = c - 'A' + 10; + else + if (c >= 'a' && c <= 'f') + c = c - 'a' + 10; + else + c = 0; val = (val << 4) | c; } return val; } /* generate C source from in-core font*/ -int -gen_c_source(PMWCFONT pf, char *path) +int gen_c_source(struct font* pf, char *path) { FILE *ofp; int i; int did_defaultchar = 0; int did_syncmsg = 0; time_t t = time(0); - MWIMAGEBITS *ofs = pf->bits; + bitmap_t *ofs = pf->bits; char buf[256]; char obuf[256]; char hdr1[] = { @@ -704,7 +704,7 @@ gen_c_source(PMWCFONT pf, char *path) "*/\n" "\n" "/* Font character bitmap data. */\n" - "static MWIMAGEBITS _%s_bits[] = {\n" + "static bitmap_t _font_bits[] = {\n" }; ofp = fopen(path, "w"); @@ -712,7 +712,6 @@ gen_c_source(PMWCFONT pf, char *path) fprintf(stderr, "Can't create %s\n", path); return 1; } - fprintf(stderr, "Generating %s\n", path); strcpy(buf, ctime(&t)); buf[strlen(buf)-1] = 0; @@ -727,8 +726,7 @@ gen_c_source(PMWCFONT pf, char *path) pf->firstchar+pf->size-1, pf->firstchar+pf->size-1, pf->defaultchar, pf->defaultchar, pf->width? "yes": "no", - pf->copyright? pf->copyright: "", - pf->name); + pf->copyright? pf->copyright: ""); /* generate bitmaps*/ for (i=0; i<pf->size; ++i) { @@ -736,15 +734,16 @@ gen_c_source(PMWCFONT pf, char *path) int bitcount = 0; int width = pf->width ? pf->width[i] : pf->maxwidth; int height = pf->height; - MWIMAGEBITS *bits = pf->bits + (pf->offset? pf->offset[i]: (height * i)); - MWIMAGEBITS bitvalue; + bitmap_t *bits = pf->bits + (pf->offset? pf->offset[i]: (height * i)); + bitmap_t bitvalue; /* * Generate bitmap bits only if not this index isn't * the default character in encode map, or the default * character hasn't been generated yet. */ - if (pf->offset && (pf->offset[i] == pf->offset[pf->defaultchar-pf->firstchar])) { + if (pf->offset && + (pf->offset[i] == pf->offset[pf->defaultchar-pf->firstchar])) { if (did_defaultchar) continue; did_defaultchar = 1; @@ -763,13 +762,13 @@ gen_c_source(PMWCFONT pf, char *path) if (x == 0) fprintf(ofp, " |"); if (bitcount <= 0) { - bitcount = MWIMAGE_BITSPERIMAGE; + bitcount = BITMAP_BITSPERIMAGE; bitvalue = *bits++; } - fprintf(ofp, MWIMAGE_TESTBIT(bitvalue)? "*": " "); + fprintf(ofp, BITMAP_TESTBIT(bitvalue)? "*": " "); - bitvalue = MWIMAGE_SHIFTBIT(bitvalue); + bitvalue = BITMAP_SHIFTBIT(bitvalue); --bitcount; if (++x == width) { fprintf(ofp, "|\n"); @@ -779,13 +778,15 @@ gen_c_source(PMWCFONT pf, char *path) } } fprintf(ofp, " +"); - for (x=0; x<width; ++x) fprintf(ofp, "-"); + for (x=0; x<width; ++x) + fprintf(ofp, "-"); fprintf(ofp, "+ */\n"); - } else + } + else fprintf(ofp, " */\n"); bits = pf->bits + (pf->offset? pf->offset[i]: (pf->height * i)); - for (x=MWIMAGE_WORDS(width)*pf->height; x>0; --x) { + for (x=BITMAP_WORDS(width)*pf->height; x>0; --x) { fprintf(ofp, "0x%04x,\n", *bits); if (!did_syncmsg && *bits++ != *ofs++) { fprintf(stderr, "Warning: found encoding values in non-sorted order (not an error).\n"); @@ -793,80 +794,79 @@ gen_c_source(PMWCFONT pf, char *path) } } } - fprintf(ofp, "};\n\n"); + fprintf(ofp, "};\n\n"); if (pf->offset) { /* output offset table*/ fprintf(ofp, "/* Character->glyph mapping. */\n" - "static unsigned long _%s_offset[] = {\n", - pf->name); + "static unsigned long _sysfont_offset[] = {\n"); for (i=0; i<pf->size; ++i) - fprintf(ofp, " %ld,\t/* (0x%02x) */\n", pf->offset[i], i+pf->firstchar); + fprintf(ofp, " %ld,\t/* (0x%02x) */\n", + pf->offset[i], i+pf->firstchar); fprintf(ofp, "};\n\n"); } /* output width table for proportional fonts*/ if (pf->width) { - fprintf(ofp, "/* Character width data. */\n" - "static unsigned char _%s_width[] = {\n", - pf->name); + fprintf(ofp, "/* Character width data. */\n" + "static unsigned char _sysfont_width[] = {\n"); for (i=0; i<pf->size; ++i) - fprintf(ofp, " %d,\t/* (0x%02x) */\n", pf->width[i], i+pf->firstchar); + fprintf(ofp, " %d,\t/* (0x%02x) */\n", + pf->width[i], i+pf->firstchar); fprintf(ofp, "};\n\n"); } - /* output MWCFONT struct*/ + /* output struct font struct*/ if (pf->offset) - sprintf(obuf, "_%s_offset,", pf->name); - else sprintf(obuf, "0, /* no encode table*/"); + sprintf(obuf, "_sysfont_offset,"); + else + sprintf(obuf, "0, /* no encode table*/"); + if (pf->width) - sprintf(buf, "_%s_width,", pf->name); - else sprintf(buf, "0, /* fixed width*/"); + sprintf(buf, "_sysfont_width,"); + else + sprintf(buf, "0, /* fixed width*/"); + fprintf(ofp, "/* Exported structure definition. */\n" - "MWCFONT font_%s = {\n" + "struct font sysfont = {\n" " \"%s\",\n" " %d,\n" " %d,\n" " %d,\n" " %d,\n" " %d,\n" - " _%s_bits,\n" + " _font_bits,\n" " %s\n" " %s\n" " %d,\n" - " sizeof(_%s_bits)/sizeof(MWIMAGEBITS),\n" + " sizeof(_font_bits)/sizeof(bitmap_t),\n" "};\n", - pf->name, pf->name, + pf->name, pf->maxwidth, pf->height, pf->ascent, pf->firstchar, pf->size, - pf->name, obuf, buf, - pf->defaultchar, - pf->name); + pf->defaultchar); return 0; } -static int -WRITEBYTE(FILE *fp, unsigned char c) +static int writebyte(FILE *fp, unsigned char c) { return putc(c, fp) != EOF; } -static int -WRITESHORT(FILE *fp, unsigned short s) +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) +static int writelong(FILE *fp, unsigned long l) { putc(l, fp); putc(l>>8, fp); @@ -874,30 +874,28 @@ WRITELONG(FILE *fp, unsigned long l) return putc(l>>24, fp) != EOF; } -static int -WRITESTR(FILE *fp, char *str, int count) +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) +static int writestrpad(FILE *fp, char *str, int totlen) { int ret; - while (str && *str && totlen > 0) + while (str && *str && totlen > 0) { if (*str) { ret = putc(*str++, fp); --totlen; } + } while (--totlen >= 0) ret = putc(' ', fp); return ret; } /* generate .fnt format file from in-core font*/ -int -gen_fnt_file(PMWCFONT pf, char *path) +int gen_fnt_file(struct font* pf, char *path) { FILE *ofp; int i; @@ -907,44 +905,43 @@ gen_fnt_file(PMWCFONT pf, char *path) fprintf(stderr, "Can't create %s\n", path); return 1; } - fprintf(stderr, "Generating %s\n", path); /* write magic and version #*/ - WRITESTR(ofp, VERSION, 4); + writestr(ofp, VERSION, 4); /* internal font name*/ - WRITESTRPAD(ofp, pf->name, 64); + writestrpad(ofp, pf->name, 64); /* copyright*/ - WRITESTRPAD(ofp, pf->copyright, 256); + writestrpad(ofp, pf->copyright, 256); /* font info*/ - WRITESHORT(ofp, pf->maxwidth); - WRITESHORT(ofp, pf->height); - WRITESHORT(ofp, pf->ascent); - WRITESHORT(ofp, 0); - WRITELONG(ofp, pf->firstchar); - WRITELONG(ofp, pf->defaultchar); - WRITELONG(ofp, pf->size); + writeshort(ofp, pf->maxwidth); + writeshort(ofp, pf->height); + writeshort(ofp, pf->ascent); + writeshort(ofp, 0); + 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*/ + writelong(ofp, pf->bits_size); /* # words of bitmap_t*/ + 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]); + writeshort(ofp, pf->bits[i]); if (ftell(ofp) & 2) - WRITESHORT(ofp, 0); /* pad to 32-bit boundary*/ + writeshort(ofp, 0); /* pad to 32-bit boundary*/ if (pf->offset) for (i=0; i<pf->size; ++i) - WRITELONG(ofp, pf->offset[i]); + writelong(ofp, pf->offset[i]); if (pf->width) for (i=0; i<pf->size; ++i) - WRITEBYTE(ofp, pf->width[i]); + writebyte(ofp, pf->width[i]); fclose(ofp); return 0; diff --git a/tools/loadrbf.c b/tools/loadrbf.c deleted file mode 100644 index 769195ea99..0000000000 --- a/tools/loadrbf.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 deleted file mode 100644 index 3bd55a7c80..0000000000 --- a/tools/writerbf.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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); - WRITESHORT(ofp, 0); - 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 (ftell(ofp) & 2) - WRITESHORT(ofp, 0); /* pad to 32-bit boundary*/ - - 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); -} |