2 ## --------------------------------------------------------------------------
4 ## Copyright 1996-2017 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 file, returns a reference to fontdata
38 sub parse_afm_file
($$) {
39 my($filename, $filetype) = @_;
48 my $charcode, $width, $name;
50 my $fontfile = $filename.'.'.$filetype;
51 return undef unless ( -f
$fontfile );
53 $fontdata->{file
} = $fontfile;
54 $fontdata->{type
} = $filetype;
55 $fontdata->{scale
} = 1000; # AFM metrics always have scale 1000
57 return undef unless (open(my $fh, '<', $filename.'.afm'));
59 while ( my $line = <$fh> ) {
60 if ( $line =~ /^\s*FontName\s+(.*)\s*$/i ) {
61 $fontdata->{'name'} = $1;
62 } elsif ( $line =~ /^\s*StartCharMetrics\b/i ) {
64 } elsif ( $line =~ /^\s*EndCharMetrics\b/i ) {
66 } elsif ( $line =~ /^\s*StartKernPairs\b/i ) {
68 } elsif ( $line =~ /^\s*EndKernPairs\b/i ) {
70 } elsif ( $charmetrics ) {
71 my @data = split(/\s*;\s*/, $line);
72 undef $charcode, $width, $name;
73 foreach my $d ( @data ) {
74 my @dd = split(/\s+/, $d);
75 if ( $dd[0] eq 'C' ) {
77 } elsif ( $dd[0] eq 'WX' ) {
79 } elsif ( $dd[0] eq 'W' ) {
81 } elsif ( $dd[0] eq 'N' ) {
85 if ( defined($name) && defined($width) ) {
86 $fontdata->{widths
}{$name} = $width;
88 } elsif ( $kerndata ) {
89 my($kpx, $a, $b, $adj) = split(/\s+/, $line);
90 if ( $kpx eq 'KPX' ) {
91 if (!exists($fontdata->{kern
}{$a})) {
92 $fontdata->{kern
}{$a} = {};
94 $fontdata->{kern
}{$a}{$b} = $adj;