X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=utility;h=c9a420e8dd838c21845860698e1fcb1fbb72c429;hb=db16069bc6dcc683d3def086de64df17c9fd8b9e;hp=41c9455a6f24c003a29d5cb463daf060057f26f2;hpb=18d2cc90c07991866e00f714d471981e570c8279;p=xfonts-traditional.git diff --git a/utility b/utility index 41c9455..c9a420e 100755 --- a/utility +++ b/utility @@ -2,15 +2,16 @@ use strict; use POSIX; use IO::File; +use Getopt::Long; -our @rulespath=('.'); +our $package='xfonts-traditional'; +our $sharedir="/usr/share/$package"; +our @rulespath; +our $mode; -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 +28,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 +76,47 @@ 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'); +our (@options)=( + 'R|rules-include=s@' => \@rulespath, + 'share-dir=s' => \$sharedir, + ); + +sub define_mode ($$) { + my ($optname,$f) = @_; + push @options, $optname, sub { + die "only one mode may be specified\n" if defined $mode; + $mode=$f; + }; +} + +define_mode('bdf-filter', sub { + die if @ARGV; + + processbdf((new IO::File '<&STDIN'), + (new IO::File '>&STDOUT')); +}); + +Getopt::Long::Configure(qw(bundling)); +GetOptions(@options) or exit 127; + +push @rulespath, "$sharedir/rules"; + +die "need a mode\n" unless $mode; + +$mode->(); + +# 70 zcat /usr/share/fonts/X11/misc/6x13.pcf.gz |pcf2bdf >in.bdf +# 71 ./utility out.bdf +# 83 bdftopcf out.bdf >out.pcf +# 84 gzip out.pcf +# 85 cp out.pcf.gz /usr/share/fonts/X11/misc/ +# really mkfontdir /usr/share/fonts/X11/misc/ +# xset fp rehash +# xfontsel