From 4ee8efe0d8f73cfbb557cb38a6ef809e8d55dd2b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 7 Jan 2012 16:37:51 +0000 Subject: [PATCH] filters --- utility | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/utility b/utility index 41c9455..bb9fd41 100755 --- a/utility +++ b/utility @@ -5,12 +5,9 @@ use IO::File; 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) { @@ -27,28 +24,40 @@ sub loadrules () { 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; } @@ -63,10 +72,13 @@ sub processbdf ($$) { $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')); + -- 2.11.0