NAME
PostScript::FontMetrics - module to fetch data from Adobe Font Metrics file
SYNOPSIS
my $info = new PostScript::FontMetrics (filename, options);
print STDOUT ("Name = ", $info->FontName, "\n");
print STDOUT ("Width of LAV = ", $info->kstringwidth("LAV", 10), "\n");
DESCRIPTION
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. Currently this requires an external program, ttftot42. This program will be used automatically if it can be located in the execution PATH
. Alternatively, you can set the variable $PostScript::FontMetrics::ttftot42
(or $PostScript::Font::ttftot42
) to the name of the actual program. See also "EXTERNAL PROGRAMS".
CONSTRUCTOR
OPTIONS
- error => [ 'die' | 'warn' | 'ignore' ]
-
How errors must be handled. Default is to call die(). In any case, new() returns a undefined result.
- verbose => value
-
Prints verbose info if value is true.
- trace => value
-
Prints tracing info if value is true.
- debug => value
-
Prints debugging info if value is true. Implies 'trace' and 'verbose'.
INSTANCE METHODS
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.
- FileName
-
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. - MetricsData
-
The complete contents of the file, normalised to Unix-style line endings.
- CharWidthData
-
Returns a reference to a hash with the character widths for each glyph.
- EncodingVector
-
Returns a reference to an array with the glyph names for each encoded character.
- CharBBoxData
-
Returns a reference to a hash with the bounding boxes (a 4-element array) for each glyph.
- KernData
-
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"}).
- stringwidth ( string [ , pointsize ] )
-
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).
- kstringwidth ( string [ , pointsize ] )
-
Returns the width of the string in character space units, taking kerning information into account.
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).
- kstring ( string [ , extent ] )
-
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");
EXTERNAL PROGRAMS
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
SEE ALSO
- http://www.adobe.com/supportservice/devrelations/PDFS/TN/5004.AFM_Spec.pdf
-
The specification of the Adobe font metrics file format.
AUTHOR
Johan Vromans, Squirrel Consultancy <jvromans@squirrel.nl>
COPYRIGHT and DISCLAIMER
This program is Copyright 1993,1999 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.