chiark / gitweb /
filters
[xfonts-traditional] / utility
diff --git a/utility b/utility
index 41c9455a6f24c003a29d5cb463daf060057f26f2..bb9fd414f3f233195f832d4a20d623317c61d718 100755 (executable)
--- 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'));
+