【问题标题】:What unit is "advanced" stored in for True Type fonts table "hmtx"?True Type 字体表“hmtx”的“高级”存储在什么单位?
【发布时间】: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


    【解决方案1】:

    它的单位是“units-per-em”[1]。它是一个字形设计空间网格,其边的大小在“unitsPerEm”下的 HEAD 标记中定义。 TrueType 通常有 2048,.otf 和 Postscript 轮廓 1000。所以如果你想得到任何有用的东西,取字体的大小,乘以 Advance 并除以 unitsPerEm。

    [1]http://en.wikipedia.org/wiki/Em_(typography)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-19
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多