What unit is “advanced” stored in for True Type fonts table “hmtx”?

丶灬走出姿态 提交于 2019-12-24 21:33:14

问题


I am running a very simple script that I wrote to get the "advance" of True Type fonts. The font in specific is New Times Roman. This is the kind of values that I'm getting back,

{
   "A" : 1479
   "a" : 909,
   "B" : 1366,
   "b" : 1024
   "C" : 1366,
   "c" : 909,
   "N" : 1479,
   "n" : 1024,
   "M" : 1821,
   "m" : 1593,
   "." : 512,
}

I'm using the Perl library Font::TTF, you can find the manual here. And, here is my script,

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 );

回答1:


It's in "units-per-em" [1]. It is a grid of glyph design space with side of size defined in HEAD tag under "unitsPerEm". TrueType usually has it 2048, .otf with Postscript outlines 1000. So if you want to get anything useful, take the size of font, multiply by the advance and divide by unitsPerEm.

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



来源:https://stackoverflow.com/questions/22904518/what-unit-is-advanced-stored-in-for-true-type-fonts-table-hmtx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!