doc: fix fonts where the scale (unitsPerEm) is not 1000

AFM metrics always have 1000 font units to a scaled PostScript point,
but TTF/OTF doesn't have to.  The easiest way (and the one which
best avoids unnecessary rounding) is to store the scale in the
metrics, and change pswidth.ph to return the width in PostScript
points instead of font units.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2017-04-10 15:21:04 -07:00
parent a959e3085d
commit ceabd83dcf
4 changed files with 13 additions and 17 deletions

View File

@ -52,6 +52,7 @@ sub parse_afm_file($$) {
$fontdata->{file} = $fontfile;
$fontdata->{type} = $filetype;
$fontdata->{scale} = 1000; # AFM metrics always have scale 1000
return undef unless (open(my $fh, '<', $filename.'.afm'));

View File

@ -359,12 +359,12 @@ sub ps_flow_lines($$$@) {
} else {
my $ew = ps_width($$e[1], $fontset->{fonts}->[$$e[0]][1],
\@NASMEncoding) *
($fontset->{fonts}->[$$e[0]][0]/1000);
($fontset->{fonts}->[$$e[0]][0]);
my $sp = $$e[1];
$sp =~ tr/[^ ]//d; # Delete nonspaces
my $esw = ps_width($sp, $fontset->{fonts}->[$$e[0]][1],
\@NASMEncoding) *
($fontset->{fonts}->[$$e[0]][0]/1000);
($fontset->{fonts}->[$$e[0]][0]);
if ( ($w+$ew) - $ps_space_squeeze*($sw+$esw) > $wid ) {
# Begin new line
@ -423,13 +423,13 @@ sub ps_flow_lines($$$@) {
my $xew = ps_width($$le[1],
$fontset->{fonts}->[$$le[0]][1],
\@NASMEncoding) *
($fontset->{fonts}->[$$le[0]][0]/1000);
($fontset->{fonts}->[$$le[0]][0]);
my $xsp = $$le[1];
$xsp =~ tr/[^ ]//d; # Delete nonspaces
my $xsw = ps_width($xsp,
$fontset->{fonts}->[$$le[0]][1],
\@NASMEncoding) *
($fontset->{fonts}->[$$le[0]][0]/1000);
($fontset->{fonts}->[$$le[0]][0]);
$w += $xew; $sw += $xsw;
}
}
@ -738,7 +738,7 @@ sub ps_break_lines($$) {
my $ntoc = substr($ptype,3,1)+0;
my $refwidth = ps_width($refname, $BodyFont{fonts}->[0][1],
\@NASMEncoding) *
($BodyFont{fonts}->[0][0]/1000);
($BodyFont{fonts}->[0][0]);
@ls = ps_flow_lines($linewidth-$ntoc*$psconf{tocind}-
$psconf{tocpnz}-$refwidth,

View File

@ -1,8 +1,7 @@
#!/usr/bin/perl
#
# Get the width of a PostScript string in font units
# (1000 font units == the font point height) given a set of
# font metrics and an encoding vector.
# Get the width of a PostScript string in PostScript points (1/72")
# given a set of font metrics and an encoding vector.
#
sub ps_width($$$) {
my($str, $met, $encoding) = @_;
@ -19,7 +18,7 @@ sub ps_width($$$) {
$p = $c;
}
return $w;
return $w / $met->{scale};
}
# OK

View File

@ -26,15 +26,11 @@ sub parse_ttf_file($) {
$fontdata->{type} = defined($f->{' CFF'}) ? 'otf' : 'ttf';
$f->{head}->read();
#printf "unitsPerEm: %d\n", $f->{head}{unitsPerEm};
#printf "xMin yMin xMax yMax: %d %d %d %d\n",
#$f->{head}{xMin},
#$f->{head}{yMin},
#$f->{head}{xMin},
#$f->{head}{yMax};
#$f->{maxp}->read();
$fontdata->{scale} = $f->{head}{unitsPerEm};
$f->{maxp}->read();
my $glyphs = $f->{maxp}{numGlyphs};
#printf "Total glyphs: %d\n", $glyphs;
$f->{cmap}->read();
$f->{hmtx}->read();
$f->{name}->read();