2 ## --------------------------------------------------------------------------
4 ## Copyright 1996-2016 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following
10 ## conditions are met:
12 ## * Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## * Redistributions in binary form must reproduce the above
15 ## copyright notice, this list of conditions and the following
16 ## disclaimer in the documentation and/or other materials provided
17 ## with the distribution.
19 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ## --------------------------------------------------------------------------
36 # Parse AFM metric files
39 @widths = ((undef)x256
);
41 while ( $line = <STDIN
> ) {
42 if ( $line =~ /^\s*FontName\s+(.*)\s*$/ ) {
44 } elsif ( $line =~ /^\s*StartCharMetrics\b/ ) {
46 } elsif ( $line =~ /^\s*EndCharMetrics\b/ ) {
48 } elsif ( $line =~ /^\s*StartKernPairs\b/ ) {
50 } elsif ( $line =~ /^\s*EndKernPairs\b/ ) {
52 } elsif ( $charmetrics ) {
53 @data = split(/\s*;\s*/, $line);
54 undef $charcode, $width, $name;
55 foreach $d ( @data ) {
56 @dd = split(/\s+/, $d);
57 if ( $dd[0] eq 'C' ) {
59 } elsif ( $dd[0] eq 'WX' ) {
61 } elsif ( $dd[0] eq 'W' ) {
63 } elsif ( $dd[0] eq 'N' ) {
67 if ( defined($name) && defined($width) ) {
68 $charwidth{$name} = $width;
70 } elsif ( $kerndata ) {
71 my($kpx, $a, $b, $adj) = split(/\s+/, $line);
72 if ( $kpx eq 'KPX' ) {
73 $kernpairs{$a} = {} unless defined($kernpairs{$a});
74 $kernpairs{$a}{$b} = $adj;
83 for ( $i = 0 ; $i < length($s) ; $i++ ) {
85 if ( $c lt ' ' || $c gt '~' ) {
86 $o .= sprintf("\\%03o", ord($c));
87 } elsif ( $c eq "\'" || $c eq "\"" || $c eq "\\" ) {
97 $psfont =~ s/[^A-Za-z0-9]/_/g;
99 print "%PS_${psfont} = (\n";
100 print " name => \'$fontname\',\n";
101 print " widths => {";
103 foreach $cc ( sort(keys(%charwidth)) ) {
104 $ss = sprintf(' %s => %d,', qstr
($cc), $charwidth{$cc});
108 $lw = 4 + length($ss);
115 foreach $ka ( sort(keys(%kernpairs)) ) {
116 printf '%s %s => {', $lt, qstr
($ka);
118 foreach $kb ( sort(keys(%{$kernpairs{$ka}})) ) {
119 $ss = sprintf(' %s => %d,', qstr
($kb), $kernpairs{$ka}{$kb});
123 $lw = 6 + length($ss);