our @rulespath=('.');
-our $state='begin';
-our ($w,$h,$xo,$yo,$y,$bitmap,$glyph);
-
-sub loadrules () {
+sub loadrules ($) {
+ my ($key) = @_;
our %cache;
- my $key= sprintf "%d,%d,%d,%d", $w,$h,$xo,$yo;
my $fc=$cache{$key};
return $fc if $fc;
foreach my $path (@rulespath) {
sub processbdf ($$) {
my ($inbdf,$outbdf) = @_;
+ my $state='idle';
+ my ($donefoundry,$donefont);
+ my ($w,$h,$xo,$yo,$y,$bitmap,$glyph);
while (<$inbdf>) {
if ($state eq 'bitmap' && $y==$h) {
- local ($_) = lc $glyph;
- my $rules= loadrules();
+ local ($_) = uc $glyph;
+ my $key= sprintf "%d,%d,%d,%d", $w,$h,$xo,$yo;
+ my $rules= loadrules($key);
return 0 if !$rules;
s/\;$//;
$rules->();
print $outbdf $_,"\n" or die $!
- foreach split /\;/ $_; # /;
+ foreach split /\;/, $_; # /;
$state='idle';
}
if ($state eq 'bitmap') {
m/^([0-9a-fA-F]+)\s+$/ or die $y;
length($1) == (($w+7 >> 3) << 1) or die "$1 $w";
$glyph .= "$1;";
+ $y++;
+ next;
}
- if ($state eq 'begin' && m/^FOUNDRY\s+/) {
- return 0 unless m/^FOUNDRY\s+\"[Mm]isc\"\s+/) {
+ if ($state eq 'idle' && m/^FOUNDRY\s+/) {
+ return 0 unless m/^FOUNDRY\s+\"[Mm]isc\"\s+/;
s/misc/Trad/i;
- $state='idle';
+ $donefoundry=1;
+ }
+ if ($state eq 'idle' && m/^FONT\s+/) {
+ return 0 unless s/^(FONT\s+)\-[Mm]isc\-/$1-Trad-/;
+ $donefont=1;
}
if ($state eq 'idle' && m/^STARTCHAR\s/) {
+ die unless $donefoundry;
+ die unless $donefont;
$state='startchar';
$w=undef;
}
$state='bitmap';
}
}
+ print $outbdf $_ or die $!;
}
die $! if $inbdf->error;
- die $! if $outbdf->error or $outbdf->flush;
+ die $! if $outbdf->error or !$outbdf->flush;
die unless $state eq 'idle';
}
-processbdf('STDIN','STDOUT');
+processbdf((new IO::File '<&STDIN'),
+ (new IO::File '>&STDOUT'));
+