VERSION

This document describes version 2.11 of PostScript::File::Metrics, released February 11, 2012 as part of PostScript-File version 2.20.

SYNOPSIS

  use PostScript::File;

  my $ps = PostScript::File->new(reencode => 'cp1252');

  my $metrics = $ps->get_metrics('Helvetica-iso', 9);

  my $upos = $metrics->underline_position;

  my $width = $metrics->width('Hello, World!');

  my @lines = $metrics->wrap( 72, # wrap it into 1 inch lines
    'This is a long string that will not fit on just one line of text.'
  );

DESCRIPTION

PostScript::File::Metrics provides a subset of the metrics available from Font::AFM. Its reason for existence is that it allows you to pre-compile the \s-1AFM\s0 files into Perl modules. This makes loading them more efficient, but more importantly, it means you don't have to install (or configure) Font::AFM. That's important because the locations and filenames of \s-1AFM\s0 files are not very standardized, which makes configuring Font::AFM quite difficult.

PostScript::File::Metrics includes pre-compiled metrics for the 13 standard PostScript fonts:

Courier Helvetica Times-Roman Courier-Bold Helvetica-Bold Times-Bold Courier-BoldOblique Helvetica-BoldOblique Times-BoldItalic Courier-Oblique Helvetica-Oblique Times-Italic Symbol

If you need metrics for a font not in that list, you'll need to have Font::AFM installed and configured. (You can modify examples/generate_metrics.pl to create additional pre-compiled modules, but you'll still have to get Font::AFM working on one system.)

ATTRIBUTES

All attributes are read-only, except for \*(C`auto_hyphen\*(C' and \*(C`size\*(C', which can be set using the corresponding \*(C`set_\*(C' methods.

size

The current font size in points. This is not an attribute of the font, but of this Metrics object. The attributes that describe the font's dimensions are adjusted according to this value.

auto_hyphen

If true, the \*(C`width\*(C' and \*(C`wrap\*(C' methods will do hyphen-minus processing as described in \*(L"Hyphens and Minus Signs\*(R" in PostScript::File, but only if the encoding is \*(C`cp1252\*(C' or \*(C`iso-8859-1\*(C'.

full_name

Unique, human-readable name for an individual font, for instance \*(L"Times Roman\*(R".

family

Human-readable name for a group of fonts that are stylistic variants of a single design. All fonts that are members of such a group should have exactly the same \*(C`family\*(C'. Example of a family name is \*(L"Times\*(R".

weight

Human-readable name for the weight, or \*(L"boldness\*(R", attribute of a font. Examples are \*(C`Roman\*(C', \*(C`Bold\*(C', \*(C`Medium\*(C'.

italic_angle

Angle in degrees counterclockwise from the vertical of the dominant vertical strokes of the font. (This is normally <= 0.)

fixed_pitch

1 if the font is a fixed-pitch (monospaced) font. 0 otherwise.

font_bbox

An arrayref of four numbers giving the lower-left x, lower-left y, upper-right x, and upper-right y of the font bounding box. The font bounding box is the smallest rectangle enclosing the shape that would result if all the characters of the font were placed with their origins coincident at (0,0), and then painted. You must not modify the returned arrayref.

cap_height

Usually the y-value of the top of the capital H. Some fonts, like Symbol, may not define this attribute.

x_height

Typically the y-value of the top of the lowercase x. Some fonts, like Symbol, may not define this attribute.

ascender

Typically the y-value of the top of the lowercase d. Some fonts, like Symbol, may not define this attribute.

descender

Typically the y-value of the bottom of the lowercase p. Some fonts, like Symbol, may not define this attribute.

underline_position

Recommended distance from the baseline for positioning underline strokes. This number is the y coordinate of the center of the stroke.

underline_thickness

Recommended stroke width for underlining.

version

Version number of the font.

METHODS

new

$metrics = PostScript::File::Metrics->new($font, [$size, [$encoding]])

You would normally use \*(L"get_metrics\*(R" in PostScript::File to construct a Metrics object (because it can get the $encoding from the document), but it is possible to construct one directly.

$size is the font size in points, and defaults to 1000.

$encoding is the character encoding used by \*(L"width\*(R" and \*(L"wrap\*(R". Valid choices are \*(C`std\*(C', \*(C`sym\*(C', \*(C`cp1252\*(C', and \*(C`iso-8859-1\*(C'. The default is \*(C`std\*(C', meaning PostScript's StandardEncoding (unless the $font is Symbol, which uses \*(C`sym\*(C', meaning PostScript's SymbolEncoding). Neither \*(C`std\*(C' nor \*(C`sym\*(C' does any character set translation.

The \*(C`auto_hyphen\*(C' attribute is always set to true when character translation is enabled.

set_auto_hyphen( translate )

If translate is a true value, then \*(C`width\*(C' and \*(C`wrap\*(C' will do automatic hyphen-minus translation as described in \*(L"Hyphens and Minus Signs\*(R" in PostScript::File.

set_size

$metrics->set_size($new_size)

This method sets the font size (in points). This influences the attributes that concern dimensions and the string width calculations. It returns the Metrics object, so you can chain to the next method.

set_wrap_chars

$metrics->set_wrap_chars($new_chars)

This method (introduced in version 2.11) sets the characters after which a word can be wrapped. A line can wrap after any character in $new_chars, which should not include whitespace. Whitespace is always a valid breakpoint. If $new_chars is omitted or \*(C`undef\*(C', restores the default wrap characters, which means \*(C`-/\*(C' and (if using cp1252) both en and em dashes. It returns the Metrics object, so you can chain to the next method.

width

$width = $metrics->width($string, [$already_encoded])

This calculates the width of $string (in points) when displayed in this font at the current size. If $string has the \s-1UTF8\s0 flag set, it is translated into the font's encoding. Otherwise, the $string is expected to be in the correct character set already. $string should not contain newlines.

If optional parameter $already_encoded is true, then $string is assumed to be already encoded in the document's character set. This also prevents any hyphen-minus processing.

wrap

@lines = $metrics->wrap($width, $text, [\%param])

This wraps $text into lines of no more than $width points. If $text contains newlines, they will also cause line breaks. If $text has the \s-1UTF8\s0 flag set, it is translated into the font's encoding. Otherwise, the $text is expected to be in the correct character set already.

If the \*(C`auto_hyphen\*(C' attribute is true, then any HYPHEN-MINUS (U+002D) characters in $text will be converted to either \s-1HYPHEN\s0 (U+2010) or \s-1MINUS\s0 \s-1SIGN\s0 (U+2212) in the returned strings.

The characters after which a line can wrap (other than space and tab, which are always valid line breaks) can be set with the \*(C`set_wrap_chars\*(C' method. In addition, $text may contain \s-1ZERO\s0 \s-1WIDTH\s0 \s-1SPACE\s0 (U+200B) characters to indicate potential line breaks. All \s-1ZWSP\s0 characters and CRs will be removed from the returned strings. $text may also contain NO-BREAK \s-1SPACE\s0 (U+00A0) characters, which indicate whitespace without a potential line break.

The optional \*(C`\%param\*(C' (introduced in version 2.11) allows additional control over the wrapping. It may contain the following keys:

chars

This overrides the line-breaking characters normally set by the \*(C`set_wrap_chars\*(C' method. The value has the same meaning as for \*(C`set_wrap_chars\*(C'.

maxlines

The maximum number of lines to return. The final line will contain all the remaining text, even if that exceeds $width or contains newline characters.

quiet

If true, do not warn about words that are too wide to fit in the specified $width.

warnings

If present, must be an arrayref. Warning messages about words that are too wide to fit in the specified $width will be pushed onto the array. You should also pass \*(C`quiet => 1\*(C' if you don't want the warnings printed to \s-1STDERR\s0.

CONFIGURATION AND ENVIRONMENT

PostScript::File::Metrics requires no configuration files or environment variables.

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

AUTHOR

Christopher J. Madsen \*(C`<perl AT cjmweb.net>\*(C'

Please report any bugs or feature requests to \*(C`<bug-PostScript-File AT rt.cpan.org>\*(C' or through the web interface at http://rt.cpan.org/Public/Bug/Report.html?Queue=PostScript-File <http://rt.cpan.org/Public/Bug/Report.html?Queue=PostScript-File>.

You can follow or contribute to PostScript-File's development at http://github.com/madsen/postscript-file <http://github.com/madsen/postscript-file>.

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Christopher J. Madsen.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTY

\s-1BECAUSE\s0 \s-1THIS\s0 \s-1SOFTWARE\s0 \s-1IS\s0 \s-1LICENSED\s0 \s-1FREE\s0 \s-1OF\s0 \s-1CHARGE\s0, \s-1THERE\s0 \s-1IS\s0 \s-1NO\s0 \s-1WARRANTY\s0 \s-1FOR\s0 \s-1THE\s0 \s-1SOFTWARE\s0, \s-1TO\s0 \s-1THE\s0 \s-1EXTENT\s0 \s-1PERMITTED\s0 \s-1BY\s0 \s-1APPLICABLE\s0 \s-1LAW\s0. \s-1EXCEPT\s0 \s-1WHEN\s0 \s-1OTHERWISE\s0 \s-1STATED\s0 \s-1IN\s0 \s-1WRITING\s0 \s-1THE\s0 \s-1COPYRIGHT\s0 \s-1HOLDERS\s0 \s-1AND/OR\s0 \s-1OTHER\s0 \s-1PARTIES\s0 \s-1PROVIDE\s0 \s-1THE\s0 \s-1SOFTWARE\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R" \s-1WITHOUT\s0 \s-1WARRANTY\s0 \s-1OF\s0 \s-1ANY\s0 \s-1KIND\s0, \s-1EITHER\s0 \s-1EXPRESSED\s0 \s-1OR\s0 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