3 # Parse AFM metric files
6 @widths = ((undef)x256);
8 while ( $line = <STDIN> ) {
9 if ( $line =~ /^\s*FontName\s+(.*)\s*$/ ) {
11 } elsif ( $line =~ /^\s*StartCharMetrics\b/ ) {
13 } elsif ( $line =~ /^\s*EndCharMetrics\b/ ) {
15 } elsif ( $line =~ /^\s*StartKernPairs\b/ ) {
17 } elsif ( $line =~ /^\s*EndKernPairs\b/ ) {
19 } elsif ( $charmetrics ) {
20 @data = split(/\s*;\s*/, $line);
21 undef $charcode, $width, $name;
22 foreach $d ( @data ) {
23 @dd = split(/\s+/, $d);
24 if ( $dd[0] eq 'C' ) {
26 } elsif ( $dd[0] eq 'WX' ) {
28 } elsif ( $dd[0] eq 'N' ) {
32 if ( defined($charcode) && $charcode >= 0 && $charcode < 256 ) {
33 $charcodes{$name} = $charcode;
34 $widths[$charcode] = $width;
36 } elsif ( $kerndata ) {
37 @data = split(/\s+/, $line);
38 if ( $data[0] eq 'KPX' ) {
39 if ( defined($charcodes{$data[1]}) &&
40 defined($charcodes{$data[2]}) &&
42 $kernpairs{chr($charcodes{$data[1]}).
43 chr($charcodes{$data[2]})} = $data[3];
53 for ( $i = 0 ; $i < length($s) ; $i++ ) {
55 if ( $c lt ' ' || $c gt '~' ) {
56 $o .= sprintf("\\%03o", ord($c));
57 } elsif ( $c eq "\'" || $c eq "\"" || $c eq "\\" ) {
67 $psfont =~ s/[^A-Za-z0-9]/_/g;
69 print "%PS_${psfont} = (\n";
70 print " name => \'$fontname\',\n";
71 print " widths => [\n";
72 for ( $i = 0 ; $i < 256 ; $i += 8 ) {
74 for ( $j = 0 ; $j < 8 ; $j++ ) {
75 printf("%5d", $widths[$i+$j]);
76 print ',' if (($i+$j) < 255);
77 print ' ' if ($j < 7);
84 foreach $kp ( keys(%kernpairs) ) {
85 $ss = sprintf('%s => %d, ', qstr($kp), $kernpairs{$kp});
89 $lw = 4 + length($ss);