【发布时间】:2014-05-02 02:05:41
【问题描述】:
我正在运行我编写的一个非常简单的脚本,以获取 True Type 字体的“advance”。具体字体为New Times Roman。这就是我要回归的价值观,
{
"A" : 1479
"a" : 909,
"B" : 1366,
"b" : 1024
"C" : 1366,
"c" : 909,
"N" : 1479,
"n" : 1024,
"M" : 1821,
"m" : 1593,
"." : 512,
}
我使用的是 Perl 库 Font::TTF,你可以find the manual here。而且,这是我的脚本,
use strict;
use warnings;
use autodie;
use Font::TTF::Font;
my $f = Font::TTF::Font->open('/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf')
|| die $!;
my $json = JSON::XS->new->ascii->pretty->allow_nonref;
my @chars = ( '.', '-', 'a'...'z', 'A'...'Z', 0..9 );
my %db;
foreach my $char ( @chars ) {
my $ord = ord($char);
my $snum = $f->{'cmap'}->ms_lookup($ord);
$f->{'hmtx'}->read;
my $sadv = $f->{'hmtx'}{'advance'}[$snum];
$db{$char} = $sadv;
}
use JSON::XS qw(encode_json);
print $json->encode( \%db );
【问题讨论】:
标签: truetype