The PostScript::TextBlock Module

The TextBlock module is an object that may be used to construct a block of text in PostScript. It is meant to be a simple, abstract interface for generating PostScript code from Perl scripts or CGI scripts, as in the example in the previous section. Example 11-3 introduces the TextBlock module.

Example 11-3. Using the TextBlock module
use PostScript::TextBlock;
my $tb = new PostScript::TextBlock;
$tb->addText( text => "Hullabalo in Hoosick Falls.\n",
              font => 'CenturySchL-Ital',
              size => 24,
              leading => 26
            );
$tb->addText( text => "by Charba Gaspee.\n",
              font => 'URWGothicL-Demi',
              size => 12,
              leading => 14
            );
print 'There are '.$tb->numElements.' elements in this object.';
open OUT, '>psoutput.ps' or die "Couldn't open psoutput.ps: $!";
my ($code, $remainder) = $tb->Write(572, 752, 20, 772);
print OUT $code;

As you can see, the TextBlock module allows the web programmer to create printable documents without any knowledge of PostScript. The PostScript code generated by this script looks like this:

0 setgray 20 746 moveto
/CenturySchL-Ital findfont
24 scalefont setfont
(Hullabalo in Hoosick Falls.) show
0 setgray 20 732 moveto
/URWGothicL-Demi findfont
12 scalefont setfont
(by Charba Gaspee.) show

By itself, the TextBlock object can print only on a single page. In many cases, your project will require a multi-page PostScript document. The TextBlock::Write( ) method returns the code and a TextBlock representing the text that doesn’t fit in the region passed ...

Get Perl Graphics Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.