PostScript::FontMetrics

PostScript::FontMetrics is a Perl module to fetch data from Adobe Font Metrics file.
Download

PostScript::FontMetrics Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Johan Vromans, Squirrel Consultancy
  • Publisher web site:
  • http://search.cpan.org/~jv/PostScript-Font-1.10/lib/PostScript/Font.pm

PostScript::FontMetrics Tags


PostScript::FontMetrics Description

PostScript::FontMetrics is a Perl module to fetch data from Adobe Font Metrics file. PostScript::FontMetrics is a Perl 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");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. This requires Martin Hosken's Font::TTF package to be installed (available on CPAN).CONSTRUCTORnew ( FILENAME )The constructor will read the file and parse its contents.OPTIONSerror => 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.verbose => valuePrints verbose info if value is true.trace => valuePrints tracing info if value is true.debug => valuePrints debugging info if value is true. Implies 'trace' and 'verbose'.INSTANCE METHODSNote: 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.FileNameThe 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.MetricsDataThe complete contents of the file, normalised to Unix-style line endings.CharWidthDataReturns a reference to a hash with the character widths for each glyph.EncodingVectorReturns a reference to an array with the glyph names for each encoded character.CharBBoxDataReturns a reference to a hash with the bounding boxes (a 4-element array) for each glyph.KernDataReturns 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"}).setEncoding ( vector )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").stringwidth ( string )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 )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 )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: There are several straightforward ways to process this.By translating to a series of 'show' and 'rmoveto' operations: foreach ( @$typesetinfo ) { if ( /^(/ ) { print STDOUT ($_, " shown"); } else { printf STDOUT ("%.3f 0 rmoveton", ($_*$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 defthe following Perl code would suffice: print PS (" TJn");charReturns a one-character string that will render as the named glyph in the current encoding, or undef if this glyph is currently not encoded. Requirements: · Perl


PostScript::FontMetrics Related Software