diff --git a/tools/bdf2c.pl b/tools/bdf2c.pl new file mode 100755 index 0000000..e9fb653 --- /dev/null +++ b/tools/bdf2c.pl @@ -0,0 +1,126 @@ +#!/usr/bin/perl +use warnings; + +$|=1; + +my %chars; + +while (<>){ +chomp; +/^ENDCHAR/ && do { + warn "Char $cchar has strange height?\n" if ($#char+1 != $height); + for (1..$offy){ + push @char,("0"x$width); + }; + for (@char){ + $_=("0"x$offx).$_; + }; + $inchar=0; +# print "Char: $cchar:\n",join("\n",@char),"\n"; + $chars{$cchar}=[@char]; + @char=(); +}; +if($inchar){ +# print "_: $_\n"; print "H: ",pack("H*",$_),"\n"; + $x=unpack("B*",pack("H*",$_)); + $x=substr($x,0,$width); + push @char,$x; +# print $x,"\n"; + next; +}; +/^BITMAP/ && do {$inchar=1;}; + +/^PIXEL_SIZE (.*)/ && do { $size=$1;$size+=0;}; +/^ENCODING (.*)/ && do {$cchar=$1}; +/^BBX (\d+) (\d+) (\d+) ([-\d]+)/ && do {$width=$1;$height=$2;$offx=$3;$offy=$4+$fontd;}; +/^FONT_ASCENT (.*)/ && do {$fonta=$1}; +/^FONT_DESCENT (\d+)/ && do {$fontd=$1;$byte=int(($fonta+$fontd-1)/8)+1;print "This will be a $byte byte font\n";}; +/^DWIDTH (\d+) (\d+)/ && do {$width=$1;die "H-offset?" if $2!=0}; +/^FACE_NAME "(.*)"/ && do {$font=$1;}; +} + +# Beautify Font Name. +$font.=" ${size}pt"; + +$fonts=$font; +$fonts=~s/ //g; +$fonts=~s/Bitstream//; +$fonts=~s/Sans//; + +$file=$fonts; +$file=~s/pt$//; +$file=~y/A-Z/a-z/; + +# Fine. Now write it back out... + +open (F,">",$file.".c")||die; +select(F); + +print <",$file.".h")||die; +select(F); +print <