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.
.afm
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).
The constructor will read the file and parse its contents.
DEPRECATED. Please use 'eval { ... }' to intercept errors.
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.
Prints verbose info if value is true.
Prints tracing info if value is true.
Prints debugging info if value is true. Implies 'trace' and 'verbose'.
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.
FontName
IsFixedPitch
Each of these methods can return undef if the corresponding information could not be found in the file.
undef
The name of the file, e.g. 'tir_____.afm'. This is not derived from the metrics data, but the name of the file as passed to the new method.
new
The complete contents of the file, normalised to Unix-style line endings.
Returns a reference to a hash with the character widths for each glyph.
Returns a reference to an array with the glyph names for each encoded character.
Returns a reference to a hash with the bounding boxes (a 4-element array) for each glyph.
Returns a reference to a hash with the kerning data for glyph pairs. It is indexed by two glyph names (two strings separated by a comma, e.g. $kd->{"A","B"}).
Sets the current encoding vector. The argument must be a reference to an array of exactly 256 elements, or the name of a pre-defined encoding ("StandardEncoding" or "ISOLatin1Encoding").
"StandardEncoding"
"ISOLatin1Encoding"
Returns the width of the string, in character space units.
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).
Returns the width of the string in character space units, taking kerning information into account.
Returns an array reference (in scalar context) or an array (in array context) with substrings of the given string, interspersed with kerning info. The kerning info is the amount of movement needed for the correct kerning, in character space (which is usually 1000 times a PostScript point). The substrings are ready for printing: non-ASCII characters have been encoded and parentheses are put around them.
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");
Returns a one-character string that will render as the named glyph in the current encoding, or 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
The specification of the Adobe font metrics file format.
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.
To install PostScript::Font, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PostScript::Font
CPAN shell
perl -MCPAN -e shell install PostScript::Font
For more information on module installation, please visit the detailed CPAN module installation guide.