2002-05-15 05:59:59 +08:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
2017-04-11 06:21:04 +08:00
|
|
|
# Get the width of a PostScript string in PostScript points (1/72")
|
|
|
|
# given a set of font metrics and an encoding vector.
|
2002-05-15 05:59:59 +08:00
|
|
|
#
|
2002-05-16 05:00:30 +08:00
|
|
|
sub ps_width($$$) {
|
|
|
|
my($str, $met, $encoding) = @_;
|
2002-05-15 05:59:59 +08:00
|
|
|
my($w) = 0;
|
|
|
|
my($i,$c,$p);
|
|
|
|
|
|
|
|
$l = length($str);
|
|
|
|
undef $p;
|
|
|
|
for ( $i = 0 ; $i < $l ; $i++ ) {
|
|
|
|
$c = substr($str,$i,1);
|
2002-05-16 05:00:30 +08:00
|
|
|
$w += $$met{widths}{$encoding->[ord($c)]};
|
2002-05-15 05:59:59 +08:00
|
|
|
# The standard PostScript "show" operator doesn't do kerning.
|
|
|
|
# $w += $$met{kern}{$p.$c};
|
|
|
|
$p = $c;
|
|
|
|
}
|
|
|
|
|
2017-04-11 06:21:04 +08:00
|
|
|
return $w / $met->{scale};
|
2002-05-15 05:59:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# OK
|
|
|
|
1;
|