adelton

Font::TFM

Read information from TeX font metric files

Synopsis

use Font::TFM;  
my $cmr = new Font::TFM name => 'cmr10'
        or die "Error reading font: $Font::TFM::errstr\n";
print 'Designsize: ', $cmr->designsize(), "\n";
print $cmr->width('A'), ', ', $cmr->kern('Wo'), "\n";

should print

Designsize: 10
491521.25, -54613.75

Description

To read the information from TFM (TeX font metrics) file, you first create the object of Font::TFM class in memory. You do this by calling method Font::TFM::new with font name and other parameters and it creates a new TFM object in memory, loading all the necessary information from the .tfm file.

The parameters are passed to Font::TFM::new in a form of a hash:

name

Name of the font, for example cmr10. The file with the font is searched for in the directories specified by the global variable $Font::TFM::TEXFONTSDIR or by a path parameter.

file

Alternatively, instead of name, you can specify full path to the font file, for example /usr/lib/tex/fonts/cmr10.tfm. You have to specify complete path, including the suffix if the file has any.

scale

If you want to load the font information at different size than the design size, use this parameter, setting scale. The default is of course 1.

at

If you want to load the font information at different size than the design size, use this parameter, size in points (pt). Using at overrides scale.

path

Colon separated value list of directories that fill be searched if you specify the font by name. By default, global value $Font::TFM::TEXFONTSDIR is used.

usels

Value 1 tells Font::TFM::new to use pregenerated listings of directory contents, this is the default. The name of the file with the listing is in global variable $Font::TFM::LSFILENAME and defaults to ls-R.

To switch this behaviour off, use value 0 or 'no' for parameter usels, or set global variable $Font::TFM::TEXFONTSUSELS to 0.

multiply

Dimensions reported by the object that you receive from Font::TFM::new are multiplied by value of $Font::TFM::MULTIPLY * actual size. Value of $Font::TFM::MULTIPLY defaults to 65536 and you can change it by this parameter when loading individual fonts. of the font. Value 65536 is nice because the dimensions can be used directly when writing the .dvi file.

If the file is not found (or there is some other problem), new returns undef and sets error message to $Font::TFM::errstr.

Examples:

$cmr10 = new Font::TFM 'cmr10';
$cmr10 = new Font::TFM 'name' => 'cmr10';
$cmr10 = new Font::TFM 'file' => './dir/cmr10.tfm';
$cmr12_14 = new Font::TFM 'name' => 'cmr12', at => 14
        or die 'Error loading font cmr12 at 14 pt: '
                . $Font::TFM::errstr;

For backward compatibility, you can use Font::TFM::new with just one parameter, the font name, or with two parameters, the font name and the scale of the size, instead of the hash of parameters and values. For backward compatibility, you can use Font::TFM::new_at with two parameters, font name and point size of the font.

After the file was loaded, you can use the following methods of the object to query information about the font's properties and about the characters, etc.

designsize, fontsize

Returns the design size and the actual size of the font in pt.

$cmr->designsize;       returns 10
$cmr->fontsize;                 10
$cmr10_12->fontsize;            12
coding_scheme

Returns the coding scheme of the font.

$cmr->coding_scheme;    returns TeX text
width, height, depth, italic

Returns the requested dimension for a specified character of the font.

$cmr->height("A")               447828.75
$cmr10_12->height("A")          537394.5
$cmr->italic("I")               0
$cmr10_12->italic("f")          61167.75
kern, lig, ligpassover

For a two-letter string returns kern between them, ligature formed and number of characters to pass over after the ligature, respectivelly.

$cmr->lig("fi")                 \014
$cmr->lig("ff")                 \013
$cmr->lig("\013i")              \016
$cmr10_12->kern("AV")           -87381.75
expand

One string parameter undergoes ligature expansion and then kernings are inserted. Returns array containing of string, kern, string, ...

$cmr->expand("AV--fix")         "A", -72818.125, "V{\014x"
word_dimensions

Returns the width, height and depth of a word. Does the lig/kern expansion, so the result is the real space it will take on output.

$cmr->word_dimensions("AV--fix")
                                1947881.875, 455111.25, 0
$cmr->word_dimensions("pm")     910225, 282168.75, 127431.25
word_width, word_height, word_depth

Calls word_dimensions and returns appropriate element. No caching is done, so it is better to call word_dimensions yourself if you will need more than one dimension of one word.

param

Returns parameter of the font, indexed from 1.

slant, x_height, em_width, quad
space, space_stretch, space_shrink, extra_space

Returns the parameter of the font, by name.

$cmr->slant()                   0
$cmsl10->slant()                0.166671752929688
$cmr->x_height()                282168.75
$cmr->height("x")               282168.75
$cmr->em_width()                655361.875
$cmr->quad()                    655361.875

$cmr->space()                   218453.75
$cmr->space_stretch()           109226.875
$cmtt10->space()                344061.25
$cmtt10->space_stretch()        0
Additional parameters for math fonts

When the coding scheme of the font is TeX math symbols, there are additional parameters num1 to num2, denom1 and denom2, sup1 to sup3, sub1 and sub2, supdrop and subdrop, delim1 and delim2, and axis_height available.

When the coding scheme is TeX math extension, there are additional parameters default_rule_thickness and big_op_spacing1 through big_op_spacing5.

name

Returns the name of the font.

Variable $Font::TFM::DEBUG may be set to 1 to get the processing messages on the standard error output.

The module is subclassable. You can define you own module that would provide alternate way of finding and opening the file. Just make new module and define your own method open_tfm in it.

Version

1.01

Available from

http://www.adelton.com/perl/Font-TFM/

Author

(c) 1996--2011 Jan Pazdziora.

All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Contact the author at jpx dash perl at adelton dot com.

See also

TFtoPL for description of the TFM format, TeX::DVI(3), TeX::DVI::Parse(3).