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
23 if (m/^FONTBOUNDINGBOX\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)\s+([-0-9]+)$/) {
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]+)$/) {
29 @cbbox = ($1,$2,$3,$4);
32 } elsif (m/^BITMAP\b/) {
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;
39 print $zeroes x $toppad;
41 } elsif (m/^ENDCHAR\b/) {
42 die unless defined $zeroes;
43 print $zeroes x $botpad;
45 } elsif (defined $zeroes) {
47 m/[^0-9A-F]/ and die "$& ?";
49 $_ = unpack "B*", pack "H*", $_;
51 $_ = ("0" x ($cbbox[2] - $fbbox[2])) . $_;
55 $_ .= "0" x ($numbytes*8 - length);
57 $_ = unpack "H*", pack "B*", $_;