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) {
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');
+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" unless @rulespath;
+
+die "need a mode\n" unless $mode;
+
+$mode->();
+
+# 70 zcat /usr/share/fonts/X11/misc/6x13.pcf.gz |pcf2bdf >in.bdf
+# 71 ./utility <in.bdf >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