pswidth.ph 532 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/perl
  2. #
  3. # Get the width of a PostScript string in PostScript points (1/72")
  4. # given a set of font metrics and an encoding vector.
  5. #
  6. sub ps_width($$$) {
  7. my($str, $met, $encoding) = @_;
  8. my($w) = 0;
  9. my($i,$c,$p);
  10. $l = length($str);
  11. undef $p;
  12. for ( $i = 0 ; $i < $l ; $i++ ) {
  13. $c = substr($str,$i,1);
  14. $w += $$met{widths}{$encoding->[ord($c)]};
  15. # The standard PostScript "show" operator doesn't do kerning.
  16. # $w += $$met{kern}{$p.$c};
  17. $p = $c;
  18. }
  19. return $w / $met->{scale};
  20. }
  21. # OK
  22. 1;