mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-10-10 00:25:06 -04:00
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:
@@ -52,6 +52,7 @@ sub parse_afm_file($$) {
|
|||||||
|
|
||||||
$fontdata->{file} = $fontfile;
|
$fontdata->{file} = $fontfile;
|
||||||
$fontdata->{type} = $filetype;
|
$fontdata->{type} = $filetype;
|
||||||
|
$fontdata->{scale} = 1000; # AFM metrics always have scale 1000
|
||||||
|
|
||||||
return undef unless (open(my $fh, '<', $filename.'.afm'));
|
return undef unless (open(my $fh, '<', $filename.'.afm'));
|
||||||
|
|
||||||
|
|||||||
10
doc/genps.pl
10
doc/genps.pl
@@ -359,12 +359,12 @@ sub ps_flow_lines($$$@) {
|
|||||||
} else {
|
} else {
|
||||||
my $ew = ps_width($$e[1], $fontset->{fonts}->[$$e[0]][1],
|
my $ew = ps_width($$e[1], $fontset->{fonts}->[$$e[0]][1],
|
||||||
\@NASMEncoding) *
|
\@NASMEncoding) *
|
||||||
($fontset->{fonts}->[$$e[0]][0]/1000);
|
($fontset->{fonts}->[$$e[0]][0]);
|
||||||
my $sp = $$e[1];
|
my $sp = $$e[1];
|
||||||
$sp =~ tr/[^ ]//d; # Delete nonspaces
|
$sp =~ tr/[^ ]//d; # Delete nonspaces
|
||||||
my $esw = ps_width($sp, $fontset->{fonts}->[$$e[0]][1],
|
my $esw = ps_width($sp, $fontset->{fonts}->[$$e[0]][1],
|
||||||
\@NASMEncoding) *
|
\@NASMEncoding) *
|
||||||
($fontset->{fonts}->[$$e[0]][0]/1000);
|
($fontset->{fonts}->[$$e[0]][0]);
|
||||||
|
|
||||||
if ( ($w+$ew) - $ps_space_squeeze*($sw+$esw) > $wid ) {
|
if ( ($w+$ew) - $ps_space_squeeze*($sw+$esw) > $wid ) {
|
||||||
# Begin new line
|
# Begin new line
|
||||||
@@ -423,13 +423,13 @@ sub ps_flow_lines($$$@) {
|
|||||||
my $xew = ps_width($$le[1],
|
my $xew = ps_width($$le[1],
|
||||||
$fontset->{fonts}->[$$le[0]][1],
|
$fontset->{fonts}->[$$le[0]][1],
|
||||||
\@NASMEncoding) *
|
\@NASMEncoding) *
|
||||||
($fontset->{fonts}->[$$le[0]][0]/1000);
|
($fontset->{fonts}->[$$le[0]][0]);
|
||||||
my $xsp = $$le[1];
|
my $xsp = $$le[1];
|
||||||
$xsp =~ tr/[^ ]//d; # Delete nonspaces
|
$xsp =~ tr/[^ ]//d; # Delete nonspaces
|
||||||
my $xsw = ps_width($xsp,
|
my $xsw = ps_width($xsp,
|
||||||
$fontset->{fonts}->[$$le[0]][1],
|
$fontset->{fonts}->[$$le[0]][1],
|
||||||
\@NASMEncoding) *
|
\@NASMEncoding) *
|
||||||
($fontset->{fonts}->[$$le[0]][0]/1000);
|
($fontset->{fonts}->[$$le[0]][0]);
|
||||||
$w += $xew; $sw += $xsw;
|
$w += $xew; $sw += $xsw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -738,7 +738,7 @@ sub ps_break_lines($$) {
|
|||||||
my $ntoc = substr($ptype,3,1)+0;
|
my $ntoc = substr($ptype,3,1)+0;
|
||||||
my $refwidth = ps_width($refname, $BodyFont{fonts}->[0][1],
|
my $refwidth = ps_width($refname, $BodyFont{fonts}->[0][1],
|
||||||
\@NASMEncoding) *
|
\@NASMEncoding) *
|
||||||
($BodyFont{fonts}->[0][0]/1000);
|
($BodyFont{fonts}->[0][0]);
|
||||||
|
|
||||||
@ls = ps_flow_lines($linewidth-$ntoc*$psconf{tocind}-
|
@ls = ps_flow_lines($linewidth-$ntoc*$psconf{tocind}-
|
||||||
$psconf{tocpnz}-$refwidth,
|
$psconf{tocpnz}-$refwidth,
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# Get the width of a PostScript string in font units
|
# Get the width of a PostScript string in PostScript points (1/72")
|
||||||
# (1000 font units == the font point height) given a set of
|
# given a set of font metrics and an encoding vector.
|
||||||
# font metrics and an encoding vector.
|
|
||||||
#
|
#
|
||||||
sub ps_width($$$) {
|
sub ps_width($$$) {
|
||||||
my($str, $met, $encoding) = @_;
|
my($str, $met, $encoding) = @_;
|
||||||
@@ -19,7 +18,7 @@ sub ps_width($$$) {
|
|||||||
$p = $c;
|
$p = $c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $w;
|
return $w / $met->{scale};
|
||||||
}
|
}
|
||||||
|
|
||||||
# OK
|
# OK
|
||||||
|
|||||||
@@ -26,15 +26,11 @@ sub parse_ttf_file($) {
|
|||||||
$fontdata->{type} = defined($f->{' CFF'}) ? 'otf' : 'ttf';
|
$fontdata->{type} = defined($f->{' CFF'}) ? 'otf' : 'ttf';
|
||||||
|
|
||||||
$f->{head}->read();
|
$f->{head}->read();
|
||||||
#printf "unitsPerEm: %d\n", $f->{head}{unitsPerEm};
|
$fontdata->{scale} = $f->{head}{unitsPerEm};
|
||||||
#printf "xMin yMin xMax yMax: %d %d %d %d\n",
|
|
||||||
#$f->{head}{xMin},
|
$f->{maxp}->read();
|
||||||
#$f->{head}{yMin},
|
|
||||||
#$f->{head}{xMin},
|
|
||||||
#$f->{head}{yMax};
|
|
||||||
#$f->{maxp}->read();
|
|
||||||
my $glyphs = $f->{maxp}{numGlyphs};
|
my $glyphs = $f->{maxp}{numGlyphs};
|
||||||
#printf "Total glyphs: %d\n", $glyphs;
|
|
||||||
$f->{cmap}->read();
|
$f->{cmap}->read();
|
||||||
$f->{hmtx}->read();
|
$f->{hmtx}->read();
|
||||||
$f->{name}->read();
|
$f->{name}->read();
|
||||||
|
|||||||
Reference in New Issue
Block a user