chiark / gitweb /
Add bdf normaliser (to cope with fontforge output directly, since bdftopcf | pcf2bdf...
[xfonts-traditional.git] / bdfnorm
1 #!/usr/bin/perl -w
2
3 use strict;
4 use POSIX;
5
6 our @fbbox;
7 our @cbbox;
8
9 our $numbytes;
10 our $zeroes;
11 our $botpad;
12
13 $|=1;
14
15 while (<>) {
16     if (m/^FONTBOUNDINGBOX\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)$/) {
17         die if @fbbox;
18         @fbbox = ($1,$2,$3,$4); # xsz ysz xoff yoff
19         # FONTBOUNDINGBOX 10 20 0 -4
20     } elsif (m/^BBX\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)$/) {
21         die unless @fbbox;
22         @cbbox = ($1,$2,$3,$4);
23         print "BBX @fbbox\n";
24         next;
25     } elsif (m/^BITMAP\b/) {
26         die unless @cbbox;
27         $numbytes = ceil($fbbox[0] / 8);
28         $zeroes = ('00' x $numbytes)."\n";
29         $botpad = $cbbox[3] - $fbbox[3];
30         my $toppad = $fbbox[1] - $cbbox[1] - $botpad;
31         print;
32         print $zeroes x $toppad;
33         next;
34     } elsif (m/^ENDCHAR\b/) {
35         die unless defined $zeroes;
36         print $zeroes x $botpad;
37         $zeroes = undef;
38     } elsif (defined $zeroes) {
39         chomp;
40         m/[^0-9A-F]/ and die "$& ?";
41 #       print "# $_\n";
42         s/./ unpack "B4", pack "H*", $& /ge;
43 #       print "# $_\n";
44         $_ = ("0" x ($cbbox[2] - $fbbox[2])) . $_;
45 #       print "# $_\n";
46         s/0+$//;
47 #       print "# $_\n";
48         $_ .= "0" x ($numbytes*8 - length);
49 #       print "# $_\n";
50         s/.{4}/ unpack "H", pack "B4", $& /ge;
51         $_ .= "\n";
52     }
53     print;
54 }