7 our $prefix="/usr/local";
8 our $package='xfonts-traditional';
9 our $sharedir="$prefix/share/$package";
10 our @fontsdirs=qw(/usr/share/fonts/X11 /usr/local/share/fonts/X11);
18 return unless $verbose;
19 print $reportfh @_,"\n" or die $!;
27 foreach my $path (@rulespath) {
28 my $script="$path/$key.rules";
29 $!=0; $@=''; my $f = do $script;
31 reportloaded("rules: loaded ",$script);
35 die "$! $? $script" unless $! == &ENOENT;
37 return $cache{$key}=undef;
40 sub processbdf ($$$) {
41 my ($inbdf,$outbdf,$what) = @_;
44 my ($w,$h,$xo,$yo,$y,$bitmap,$glyph);
47 if ($state eq 'bitmap' && $y==$h) {
51 my $key= sprintf "%s,%d,%d,%d,%d", $foundry,$w,$h,$xo,$yo;
52 my $rules= loadrules($key);
53 return (0,'no rules') if !$rules;
55 $modified += ($_ ne $glyph);
56 print $outbdf $_,"\n" or die $!
57 foreach split /\;/, $_; # /;
60 if ($state eq 'bitmap') {
61 m/^([0-9a-fA-F]+)\s+$/ or die $y;
62 length($1) == (($w+7 >> 3) << 1) or die "$1 $w";
67 if ($state eq 'idle' && m/^FOUNDRY\s+/) {
68 die if defined $foundry;
69 return (0,'foundry syntax') unless m/^FOUNDRY\s+\"(\w+)\"\s+/;
70 $foundry = $foundrymap{lc $1};
71 return (0,'no foundry') unless defined $foundry;
72 $_ = "FOUNDRY \"$foundry\"\n";
74 if ($state eq 'idle' && m/^FONT\s+/) {
76 return 0 unless m/^(FONT\s+)\-(\w+)\-/;
77 $font = $foundrymap{lc $2};
78 return (0,'no foundry') unless defined $font;
79 $_ = "FONT -$font-$'";
81 if ($state eq 'idle' && m/^STARTCHAR\s/) {
82 die unless defined $foundry;
83 die unless defined $font;
84 return (0,'foundry != font') unless $foundry eq $font;
88 if ($state eq 'startchar') {
89 if (m/^BBX\s+(\+?\d+)\s+(\+?\d+)\s+([-+]?\d+)\s+([-+]?\d+)\s+$/) {
90 ($w,$h,$xo,$yo) = ($1,$2,$3,$4);
93 die unless defined $w;
99 print $outbdf $_ or die $!;
101 die $! if $inbdf->error;
102 die $! if $outbdf->error or !$outbdf->flush;
103 die unless $state eq 'idle';
105 printf $reportfh "%s: %d glyphs changed\n", $what, $modified
108 printf $reportfh "%s: unchanged - no rules matched\n", $what
115 'R|rules-include=s@' => \@rulespath,
116 'share-dir=s' => \$sharedir,
117 'verbose|v+' => \$verbose,
120 sub define_mode ($$) {
121 my ($optname,$f) = @_;
122 push @options, $optname, sub {
123 die "only one mode may be specified\n" if defined $mode;
128 sub loadfoundries () {
129 foreach my $path (@rulespath) {
130 my $p = "$path/foundries";
131 my $f = new IO::File $p;
133 die "$p $!" unless $!==&ENOENT;
134 print $reportfh "foundries: none in $p\n" or die $! if $verbose;
140 m/^(\w+)\s+(\w+)$/ or die;
142 next if exists $foundrymap{$k};
145 $f->error and die $!;
146 reportloaded('foundries: loaded ',$p);
148 die "no foundry maps\n" unless %foundrymap;
151 our $stdin = new IO::File '<&STDIN' or die $!;
152 our $stdout = new IO::File '>&STDOUT' or die $!;
153 our $stderr = new IO::File '>&STDERR' or die $!;
156 define_mode('bdf-filter', sub {
157 die "no arguments allowed with --bdf-filter\n" if @ARGV;
160 my $r = processbdf($stdin,$stdout,'stdin');
162 print STDERR "stdin not processed: $r\n";
167 Getopt::Long::Configure(qw(bundling));
168 GetOptions(@options) or exit 127;
170 push @rulespath, "$sharedir/rules";
172 die "need a mode\n" unless $mode;
176 # 70 zcat /usr/share/fonts/X11/misc/6x13.pcf.gz |pcf2bdf >in.bdf
177 # 71 ./utility <in.bdf >out.bdf
178 # 83 bdftopcf out.bdf >out.pcf
180 # 85 cp out.pcf.gz /usr/share/fonts/X11/misc/
181 # really mkfontdir /usr/share/fonts/X11/misc/