chiark / gitweb /
10x20: Fix vertical metric (must have slipped in fontforge)
[xfonts-traditional.git] / bdfnorm
1 #!/usr/bin/perl -w
2
3 # BDF can represent glyphs as smaller bitmap rectangles with padding.
4 # But our approach to font editing works best if the glyphs are the
5 # full character cell.  Although most fonts do not use this feature
6 # (at least, as seen in pdf2bdf output), some do, and also output from
7 # fontforge does.  So this script pads each glyph to the font bounding
8 # box.
9
10 use strict;
11 use POSIX;
12
13 our @fbbox;
14 our @cbbox;
15
16 our $numbytes;
17 our $zeroes;
18 our $botpad;
19
20 $|=1;
21
22 while (<>) {
23     if (m/^FONTBOUNDINGBOX\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)$/) {
24         die if @fbbox;
25         @fbbox = ($1,$2,$3,$4); # xsz ysz xoff yoff
26         # FONTBOUNDINGBOX 10 20 0 -4
27     } elsif (m/^BBX\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)$/) {
28         die unless @fbbox;
29         @cbbox = ($1,$2,$3,$4);
30         print "BBX @fbbox\n";
31         next;
32     } elsif (m/^BITMAP\b/) {
33         die unless @cbbox;
34         $numbytes = ceil($fbbox[0] / 8);
35         $zeroes = ('00' x $numbytes)."\n";
36         $botpad = $cbbox[3] - $fbbox[3];
37         my $toppad = $fbbox[1] - $cbbox[1] - $botpad;
38         print;
39         print $zeroes x $toppad;
40         next;
41     } elsif (m/^ENDCHAR\b/) {
42         die unless defined $zeroes;
43         print $zeroes x $botpad;
44         $zeroes = undef;
45     } elsif (defined $zeroes) {
46         chomp;
47         m/[^0-9A-F]/ and die "$& ?";
48 #       print "# $_\n";
49         $_ = unpack "B*", pack "H*", $_;
50 #       print "# $_\n";
51         $_ = ("0" x ($cbbox[2] - $fbbox[2])) . $_;
52 #       print "# $_\n";
53         s/0+$//;
54 #       print "# $_\n";
55         $_ .= "0" x ($numbytes*8 - length);
56 #       print "# $_\n";
57         $_ = unpack "H*", pack "B*", $_;
58         $_ = uc $_;
59         $_ .= "\n";
60     }
61     print;
62 }