#!/usr/local/bin/perl

# http://czyborra.com/unifont/gif2bdf © 1998-11-08 roman@czyborra.com
# bundles the http://charts.unicode.org/Unicode.charts/Small.Glyphs/
# into a handier bitmap distribution format font

$[ = 1; $chars=$#ARGV; undef $/; 

for (@ARGV)
{
	$dec = hex ($hex) if ($hex) = /([0-9A-F]+)/;
	$_ = `giftopnm $_`;
	s/^P4\s(\d+)\s(\d+)\s/$wid=$1,$nib=$wid>>2,$ht=$2,''/e;
	$_ = unpack ("H*", $_);
	s/(.{$nib})/\n$1/g;
	$header ||= print "STARTFONT 2.1
FONT -Unicode-Charts-Medium-R-Normal--$ht-${ht}0-72-72-C-${wid}0-ISO10646-1
SIZE $ht 72 72
FONTBOUNDINGBOX $wid $ht 0 0
STARTPROPERTIES 4
COPYRIGHT http://www.unicode.org/unicode/copyright.html
DEFAULT_CHAR -1
FONT_ASCENT $ht
FONT_DESCENT 0
ENDPROPERTIES
CHARS $chars
";
	print "STARTCHAR U+$hex
ENCODING $dec
SWIDTH 1000 0
DWIDTH $wid 0
BBX $wid $ht 0 0
BITMAP$_
ENDCHAR
";

}

print "ENDFONT\n";
