NAME

PostScript::Font - module to fetch data from PostScript fonts

SYNOPSIS

my $info = new PostScript::Font (filename, options);
print STDOUT ("Name = ", $info->FontName, "\n");

DESCRIPTION

This package reads PostScript font files and stores the information in memory.

Most font file formats that are in use are recognised, especially the Type 1 and Type 42 font formats. Other formats that usually parse okay are Type 5 and Type 3, although Type 3 can sometimes fail depending on how weird the font information is stored.

The input font file can be encoded in ASCII (so-called .pfa format), or binary (so-called .pfb format).

True Type fonts are understood as well, they are converted internally to Type 42 format. 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::Font::ttftot42 (or $PostScript::FontMetrics::ttftot42) to the name of the actual program. See also section "EXTERNAL PROGRAMS".

CONSTRUCTOR

new ( FILENAME [ , OPTIONS ] )

The constructor will read the file and parse its contents.

OPTIONS

error => [ 'die' | 'warn' | 'ignore' ]

How errors must be handled. Default is to call die(). In any case, new() returns a undefined result.

format => [ 'ascii' | 'pfa' | 'binary' | 'pfb' ]

The format in which the font data is stored. Default is 'ascii', suitable to be downloaded to a PostScript printer.

verbose => value

Prints verbose info if value is true.

trace => value

Prints tracing info if value is true.

INSTANCE METHODS

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_____.pfb'.

FontName

The name of the font, e.g. 'Times-Roman'.

FamilyName

The family name of the font, e.g. 'Times'.

Version

The version of the font, e.g. '001.007'.

ItalicAngle

The italicity of the font, e.g. 0 (normal upright fonts) or -16 (italic font).

isFixedPitch

Indicates if this font has fixed pitch.

Weight

This font weight.

FontType

The font type, e.g. '1' for a Type 1 PostScript font, or 't' for a True Type font.

True Type fonts will be converted to Type 42 internally, but still have 't' as FontType.

FontMatrix

The font matrix as a reference to an anonymous array with the 6 values. To find the font scale, use

int(1/$font->FontMatrix->[0])
DataFormat

The format in which the data is kept internally. See the format option.

FontData

The complete contents of the file, normalised to Unix-style line endings. It is in the format as returned by the dataformat method.

Encoding

This is either one of the strings 'StandardEncoding' or 'ISOLatin1Encoding', or a reference to an array that holds the encoding. In this case, the array will contain a glyph name (a string) for each element that is encoded.

NOTE: Getting the encoding information can fail if the way it was stored in the font is not recognized by the parser. This is most likely to happen with manually constructed fonts.

EncodingVector

Like encoding, but always returns a reference to the encoding array. In other words, the standard encodings are returned as arrays as well.

FontGlyphs

This returns a reference to an array holding all the names of the glyphs this font defines, in the order the definitions occur in the font data.

NOTE: Getting the glyphs information can fail if the way it was stored in the font is not recognized by the parser. This is most likely to happen with manually constructed fonts.

Extracting the glyphs can be slow. It can be speeded up by using the external program t1disasm. This program will be used automatically, if it can be found in the execution PATH. Alternatively, you can set the variable $PostScript::Font::t1disasm to point to the t1disasm program. This does not apply to type 42 fonts, since these fonts do not require disassembly to get at the glyph list.

CLASS METHODS

StandardEncoding

Returns a reference to an array that contains all the glyphs names for Adobe's Standard Encoding.

ISOLatin1Encoding

Returns a reference to an array that contains all the glyphs names for ISO-8859-1 (ISO Latin-1) encoding.

EXTERNAL PROGRAMS

Two external programs can be used by this package.

ttftot42 is required when True Type fonts must be handled. It is called as follows:

ttftot42 -fc filename

This invocation will write the Type 42 version of the True Type font to standard output.

ttftot42 can be found on http://ftp.giga.or.at/pub/nih/ttftot42

An alternative, but not encouraged, way to handle True Type fonts is by converting them to Type 1 fonts. An excellent converter, ttf2pt1, can be used for this. To use this program, create a fake ttftot42 script and set variable $PostScript::Font::ttftot42 to the name of this script. The script should contain something like this:

$!/bin/sh
shift	# get rid of '-fc' argument
exec ttf2pt1 -ef "$@" - 2>/dev/null

The redirection of error output to /dev/null is necessary. since the program is quite verbose. Unfortunately, error messages will disappear as well.

ttf2pt1 can be found on http://www.netspace.net.au/~mark/ttf2pt1

Note: the resultant Type1 font is not a real conversion, but a (very similar) imitation of the original True Type font. Small differences may be noticable depending on the font quality.

t1disasm can be used to speed up the fetching of the list of font glyphs from Type 1 fonts. It is called as follows:

t1disasm filename

This invocation will write the disassembled version of the Type 1 font to standard output. t1disasm is part of the t1utils package that can be found at http://www.lcdf.org/~eddietwo/type/ and several other places.

KNOWN BUGS

Invoking external programs (t1disasm, ttftot42) is guaranteed to work on Unix only.

SEE ALSO

http://www.adobe.com/supportservice/devrelations/PDFS/TN/T1_SPEC.PDF

The specification of the Type 1 font format.

http://www.adobe.com/supportservice/devrelations/PDFS/TN/5012.Type42_Spec.pdf

The specification of the Type 42 font format.

http://fonts.apple.com/TTRefMan/index.html

The True Type reference manual.

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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 737:

You forgot a '=back' before '=head1'