Postscript.pm - A class to build of postscript files using a procedural perl interface
use Postscript;
$ps = Postscript->newWithProperties($properties);
$ps->lineto(100, 140); # for example ... $ps->close();
Instantiate a Postscript object. $properties is a hash which which for which the key file indicates a path where to write the final Postscript file. Then issue arbitrary Postscript commands. Finally invoke the close method which writes a valid Postscript file including header and footer. Some more complex methods (like centered text) automatically add Postscript ``functions'' to the file which are included at most once. The following list documents the relevant implemented methods which for most the time correspond with a Postscript operator. Therefore more competent explenation of these methods can be saught for in various Postscript documentations.
newWithProperties($properties)
- initializes a new Postscript object. '$properties' is a dictionary (hash) that contains initialization options. 'path' denotes the destination path of the output file (defaults to '/tmp/postscript.ps'). If the extension is '.pdf', a pdf file is created. 'properties' specifies further properties in a dictionary used to modify the PS header. 'createPDF' is a boolean forcing a final conversion to pdf file format (this results in, both, a 'ps' and a 'pdf' file). 'backgroundDocument' specifies a pdf Document the pages of which are drawn on each sequential page being created before any further drawing is executed.
arc()
method, then the fill()
method
arcn($x, $y, $r, $strt, $stop) - issue the postscript operator 'arcn' (which draws the other way round than 'arc')
moveto($x, $y) - issue the postscript operator 'moveto'
rlineto($x, $y) - issue the postscript operator 'rlineto'
lineto($x, $y) - issue the postscript operator 'lineto'
line($x, $y, $x1, $y1) - issue the postscript operator 'line'
strokeline($x, $y, $x1, $y1) - issue the postscript operator 'line', then 'stroke'
setgray($gray)
- issue the postscript operator 'setgray'
setlinewidth($width)
- issue the postscript operator 'setlinewidth'
rect($x, $y, $w, $h) - issue the postscript operators 'moveto', 'lineto', 'closepath' as to produce a rectangle with lower left corner ($x, $y) and width $w, height $h.
rectstroke($x, $y, $w, $h) - issue rect(), then stroke()
rectfill($x, $y, $w, $h) - issue rect(), then fill()
stroke()
- issue the postscript operator 'stroke'
fill()
- issue the postscript operator 'fill'
gsave()
- issue the postscript operator 'gsave'
grestore()
- issue the postscript operator 'grestore'
clip()
- issue the postscript operator 'clip'
newpath()
- issue the postscript operator 'newpath'
closepath()
- issue the postscript operator 'closepath'
show($text)
- issue the postscript operator 'show'
centeredShow($text, $x, $y) - show the text $text centered by first calculating text width and then moving accordingly
ycenteredShow($text, $x, $y) - a corresponding method to ceneteredShow which, this time centers vertically by calculating the height of the text
showRyC($text, $x, $y) - show the text right aligned and centered vertically
showRotated($text, $x, $y, $angle) - show the text rotated by the angle $angle. The graphic context is saved before and restored after the operation
setfont($fontname, $size) - issue the postscript operators 'findfont' and 'setfont'.
setrgbcolor($c)
- issue the postscript operator 'setrgbcolor' when $c is a hash containing the keys r, g and b
rotate($a)
- issue the postscript operator 'rotate'
scale($sx, $sy) - issue the postscript operator 'scale'
translate($x, $y) - issue the postscript operator 'translate'
colorRect($c, $x, $y, $w, $h) - issue the methods newPath(), setrgbcolor(), rect() and fill()
setBlendedColorFromColorsAndFraction($c1, $c2, $f) - issue setrgbcolor() with a color lying $f-way between $c1 and $c2.
hblendedRect($c1, $c2, $x, $y, $w, $h, $stepSize) - draw a rectangle starting with color $c1 lefthand and ending in color $c2 righthand. $stepSize indicates how many points each interpolated rectangle is wide.
vblendedRect($c1, $c2, $x, $y, $w, $h, $stepSize) - draw a rectangle starting with color $c1 upside and ending in color $c2 downside. $stepSize indicates how many points each interpolated rectangle is high.
hshiningRect($c1, $c2, $f, $x, $y, $w, $h, $stepSize) - by the use of the method hblendedRect() hshiningRect first blends from color $c1 to color $c2 and then back to color $c1. Where within the specified rect the color $c2 is drawn is determind by $f giving a fraction relative to rectangle width
curve($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4) - issue the postscript operators 'moveto' (with arguments $x1 and $x2) and 'curveto' (with the rest of the arguments)
bubble($x, $y, $w, $h, $r) - draw a rect with rounded corners the radius of which is $r
tilePicturesInRect($pathes, $rect, $c) - arrange the picuters referred to by $pathes in $rect. $c configures the process. $c-{picRatio}> determines the relative aspect of the rects the pictures are drawn in (for portrait pictures 0.75 is a reasonable choice). $c-{doShowNames}> determines wether file names are to be printed. $c-{font}> configures the font to be used therewith. $c-{color}> controls the text color.