8 use Font
::TTF
::PSNames
;
13 sub parse_ttf_file
($) {
21 my $f = Font
::TTF
::Font
->open($filename);
23 return undef if (!defined($f));
25 $fontdata->{file
} = $filename;
26 $fontdata->{type
} = defined($f->{' CFF'}) ?
'otf' : 'ttf';
29 $fontdata->{scale
} = $f->{head
}{unitsPerEm
};
32 my $glyphs = $f->{maxp
}{numGlyphs
};
37 $fontdata->{name
} = $f->{name
}->find_name(6); # PostScript name
40 my $psmap = $f->{post
}->{VAL
};
41 $psmap = [] if (!defined($psmap));
42 #printf "Glyphs with PostScript names: %d\n", scalar(@$psmap);
44 # Can be done as an array of arrays in case of multiple unicodes to
46 my @unimap = $f->{cmap
}->reverse();
48 for (my $i = 0; $i < $glyphs; $i++) {
49 my $width = $f->{hmtx
}->{advance
}[$i];
50 my $psname = $psmap->[$i];
51 if (!defined($psname)) {
52 $psname = Font
::TTF
::PSNames
::lookup
($unimap[$i]);
54 next if (!defined($psname) || ($psname eq '.notdef'));
55 $fontdata->{widths
}{$psname} = $f->{hmtx
}->{advance
}[$i];