PostScript::FontMetrics - module to fetch data from Adobe Font Metrics file |
PostScript::FontMetrics - module to fetch data from Adobe Font Metrics file
my $info = new PostScript::FontMetrics (filename, options); print STDOUT ("Name = ", $info->FontName, "\n"); print STDOUT ("Width of LAV = ", $info->kstringwidth("LAV", 10), "\n");
This package allows Adobe standard font metric files, so called
.afm
files, to be read and (partly) parsed.
True Type fonts are understood as well, their metrics are extracted. This requires Martin Hosken's Font::TTF package to be installed (available on CPAN).
How errors must be handled. Default is to call die().
In any case, new()
returns a undefined result.
Setting 'error' to 'ignore' may cause surprising results.
Note: Most of the info from the AFM file can be obtained by calling a method of the same name, e.g. FontName
and IsFixedPitch
.
Each of these methods can return undef
if the corresponding
information could not be found in the file.
new
method.
"StandardEncoding"
or "ISOLatin1Encoding"
).
Deprecated: When a pointsize argument is supplied, the resultant width is scaled to user space units. This assumes that the font maps 1000 character space units to one user space unit (which is generally the case).
Deprecated: When a pointsize argument is supplied, the resultant width is scaled to user space units. This assumes that the font maps 1000 character space units to one user space unit (which is generally the case).
If the extend argument is supplied, this amount of displacement is added to each space in the string.
For example, for a given font, the following call:
$typesetinfo = $metrics->kstring ("ILVATAB");
could return in $typesetinfo:
[ "(IL)", -97, "(V)", -121, "(A)", -92, "(T)", -80, "(AB)" ]
There are several straightforward ways to process this.
By translating to a series of 'show' and 'rmoveto' operations:
foreach ( @$typesetinfo ) { if ( /^\(/ ) { print STDOUT ($_, " show\n"); } else { printf STDOUT ("%.3f 0 rmoveto\n", ($_*$fontsize)/$fontscale); } }
Or, assuming the following definition in the PostScript preamble (48 is the font size):
/Fpt 48 1000 div def /TJ {{ dup type /stringtype eq { show } { Fpt mul 0 rmoveto } ifelse } forall } bind def
the following Perl code would suffice:
print PS ("[ @$typesetinfo ] TJ\n");
undef
if this glyph is currently not
encoded.
ttftot42 is required when True Type fonts must be handled. It is called as follows:
ttftot42 -ac filename
This invocation will write the metrics for the True Type font to standard output.
ttftot42 can be found on http://ftp.giga.or.at/pub/nih/ttftot42
Johan Vromans, Squirrel Consultancy <jvromans@squirrel.nl>
This program is Copyright 2000,1998 by Squirrel Consultancy. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the ``Artistic License'' which comes with Perl.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details.
PostScript::FontMetrics - module to fetch data from Adobe Font Metrics file |