############################################# ## Poor Man's PostScript Reference Guide ## ############################################# F file M mark S save object X, Y any element a, b arrays d dictionaries f boolean k packed array i, n integers m matrix p procedure r real numbers s, t strings x, y numbers : bottom of stack Stack manipulation ~~~~~~~~~~~~~~~~~~ pop X - discard top element exch X Y Y X exchange two elements dup X X X duplicate top element copy X1..Xn n X1..Xn X1..Xn duplicate top n elements index Xn..X0 n Xn..X0 Xn duplicate selected element roll X(n-1)..X0 n x X(x-1 mod n)..Xj roll n elements up x times clear : X... : clear whole stack count : X... : X... n count elements on stack mark - M push mark cleartomark M X... - discard to mark counttomark M X1..Xn M X1..Xn n count objects until mark Math ~~~~ add x y x+y div x y x/y idiv x y x/y integer division mod x y x%y modulo mul x y x*y sub x y x-y abs x |x| neg x -x ceiling x ceil(x) floor x floor(x) round x round(x) truncate x trunc(x) sqrt x r atan num den angle traditional atan2 cos angle r all angles are in degrees sin angle r exp base exponent r ln x r natural log log x r decimal log rand - i srand i - set random seed rrand - i get random seed Arrays ~~~~~~ array n a create empty array containing all nulls [ - M array construction start ] M X1..n a array construction end length a n get a i a[i] put a i X - a[i]=X getinterval a i n a[i..+n] get subarray putinterval a i b - replace subarray of a starting at i with b aload a a[0]..a[n-1] a push all array elements astore a[0]..a[n-1] a a pop all array elements copy a b b' copy elements of a to initial subarray of b => b' forall a p - execute p for each element of a Packed arrays ~~~~~~~~~~~~~ packedarray X0..Xn-1 n k construct packed array currentpacking - f return array packing mode setpacking f - set array packing mode (true = automatically pack executable arrays) - length, get, getinterval, aload, copy, forall are also available Dictionaries ~~~~~~~~~~~~ dict n d create new dictionary capable of holding n elements length d n number of pairs defined maxlength d n maximum number of pairs available begin d - push dict on dictionary stack end - - pop from dict stack def key value - associate key with value in current dict load key value search dict stack for key and return associated value store key value - replace topmost definiton of key known d key f is key in dict? where key d true find dictionary in which key is defined false copy d1 d2 d2 copy contents of d1 to d2 forall d p - execute p for each element of d errordict - d get error dictionary systemdict - d userdict - d currentdict - d countdictstack - n get number of dicts on the dict stack dictstack a a' copy dict stack to array Strings ~~~~~~~ string n s create string of length n - length, get, put, getinterval, putinterval, copy, forall as for arrays anchorsearch s t post match true determine if t is initial substring of s s false search s t post match pre true search of t in s string false token s post token true read token frm start of s false Relational, boolean and bitwise ops ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eq X Y b classical relations ne, ge, gt, le, lt <-- those defined for numbers and strings only and, not, or, xor both boolean and bitwise versions true - true false - false bitshift n i n' shift n i places to the left Control ~~~~~~~ exec X - execute arbitrary object if f p - execute p if f is true ifelse f p1 p2 - execute p1 if f is true or p2 if f is false for x0 x++ x<= p - execute p with values from x0 to x<= by steps of x++ repeat n p - execute p n times loop p - loop forever exit - - exit from innermost loop stop - - terminate 'stopped' context stopped X f execute X and return whether it exited (false) or stopped (true) countexecstack - n count elements on exec stack execstack a a' get exec stack contents quit - - terminate interpreter start - - execute at interpreter startup Type, attribute and conversion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type X name return name identifying X's type cvlit X X mark object as literal (i.e., not executable) cvx X X mark object as executable xcheck X f test executability executeonly X X reduce access to exec-only (array,packedarray,file,string only) noaccess X X disallow any access (array,packedarray,dict,file,string only) readonly X X reduce access to read-only (array,packedarray,dict,file,string only) rcheck X f test readability wcheck X f test writability cvi n/s i convert to int cvn s name convert to name cvr n/s r convert to real cvrs n radix s s' convert to string with radix cvs X s s' convert to string Files ~~~~~ file s t F open file s with access t closefile F - read F i true read single character false write F i - write single character readhexstring F s s' f writehexstring F s - readstring F s s' f writestring F s - readline F s s' f token F s true read token from file false bytesavaileble F n bytes available to read flush - - flush stdout flushfile F - flush given file output resetfile F - flush input status F f is file descriptor still valid? run s - execute contents of named file currentfile - F file currently being executed print s - print string to stdout = X - write text representation of X to stdout stack ... ... dump stack nondestructively (using = for each elt) == X - write syntactic representation of X to stdout pstack ... ... 'stack' using '==' prompt - - executed when ready for interactive input echo f - turn on/off echoing Virtual memory ~~~~~~~~~~~~~~ save - S create VM snapshot restore S - restore VM snapshot vmstatus - level used max report VM status Misc ~~~~ bind p p replace operator names in p by their definitions null - null push null object usertime - i user time in milliseconds version - s interpreter version Graphics state ~~~~~~~~~~~~~~ gstate - - save graphics state to gstate stack grestore - - restore graphics state grestoreall - - while gstack not empty do grestore initgraphics - - reset gstate parameters setlinewidth x - currentlinewidth - x setlinecap i - set shape of line ends for stroke (0=butt, 1=round, 2=square) currentlinecap - i setlinejoin i - set shape of corners for stroke (0=miter, 1=round, 2=bevel) currentlinejoin - i setmiterlimit x - set limit for mitering currentmiterlimit - x setdash a i - set dash pattern (array of b/w segment lengths and starting pixel offset) currentdash - a i setflat x - set digitization tolerance in pixels currentflat - x setgray x - set color to gray value (0=black ... 1=white) currentgray - x sethsbcolor h s b - set color in HSB model currenthsbcolor - h s b setrgbcolor r g b - set color in RGB model currentrgbcolor - r g b setscreen freq angle proc - set current halftone screen currentscreen - f a p settransfer p - set gray transfer function (for images) Coordinate systems ~~~~~~~~~~~~~~~~~~ matrix - m create identity matrix initmatrix - - set CTM to device default identmatrix m m fill matrix with identity transform defaultmatrix m m fill with default device matrix currentmatrix m m fill with CTM setmatrix m - replace CTM by m translate x y - translate user space by (x,y) x y m m translate given matrix scale x y - x y m m rotate angle - angle m m concat m - replace CTM with m * CTM concatmatrix m1 m2 m3 m3 m3=m1*m2 transform x y x' y' transform (x,y) by CTM x y m x' y' ... by m dtransform x y x' y' transform distance by CTM (i.e., without translation) x y m x' y' ... by m itransform x y x' y' inverse transform x y m x' y' idtransform x y x' y' inverse dtransform x y m x' y' invertmatrix m1 m2 m2 m2 = invert(m1) Path construction ~~~~~~~~~~~~~~~~~ newpath - - initialize current path to be empty currentpoint - x y moveto x y - rmoveto dx dy - lineto x y - rlineto dx dy - arc x y r ang1 ang2 - append counterclockwise arc arcn x y r ang1 ang2 - append clockwise arc arcto 1 y1 x2 y2 r xt1 yt1 xt2 yt2 append tangent arc curveto x1 y1 x2 y2 x3 y3 - append Bezier cubic section rcurveto ... curveto relative to current position closepath - - close current subpath (connect back to starting point) flattenpath - - replace curves by line segments reversepath - - reverse each subpath strokepath - - compute outline of stroked path charpath s f - append char outline to current path (false=for stroking, true=for filling) clippath - - set clipping path to current path pathbbox - llx lly urx ury return bounding box of current path (incl. control points of curves) pathforall move line curve close - call procedures for path segments initclip - - set clip path to device default clip - - clip current path by current clipping path eoclip - - clip using even-odd inside rule Painting ~~~~~~~~ erasepage - - paint current page white fill - - fill current path with current color eofill - - fill using even-odd inside rule stroke - - draw line along current path image width height bits-per-sample matrix proc draw image imagemask width height invert matrix proc draw mask (paint 1 pixels with current colors) Device setup and output ~~~~~~~~~~~~~~~~~~~~~~~ showpage - - output and reset current page copypage - - output and retain current page banddevice matrix w h proc - install band buffer device framedevice matrix w h proc - install frame buffer device nulldevice - - install no-output device renderbands p - enumerate bands for output to device Characters and fonts ~~~~~~~~~~~~~~~~~~~~ definefont key font - register font as a font dictionary findfont key font return font dict identified by key scalefont font x font' scale font by x to produce new font' makefont font m font' transform font by matrix to produce new font' setfont font - set font as current currentfont - font show s - print characters of s on page ashow x y s - add (x,y) to width of each char while showing s widthshow x y char s - add (x,y) to width of 'c' while showing s awidthshow x1 y1 char x2 y2 s - ashow combined with widthshow kshow p s - execute p between characters shown from s stringwidth s x y width of s in current font FontDirectory - d dictionary of font dictionaries StandardEncoding - a standard font encoding vector Font cache ~~~~~~~~~~ cachestatus - bsize bmax msize mmax csize cmax blimit return cache status and params setcachedevice wx wy llx lly urx ury - declare cached character metrics setcharwidth wx wy - declare uncached character metrics setcachelimit x - set max bytes in cached character setcacheparams M lower upper - set char cache parameters currentcacheparams - M lower upper Errors ~~~~~~ dictfull dictstackoverflow dictstackunderflow execstackoverflow handleerror called to handle error messages interrupt invalidaccess invalidexit invalidfileaccess invalidfont invalidrestore ioerror limitcheck nocurrentpoint rangecheck stackoverflow stackunderflow syntaxerror timeout typecheck undefined undefinedfilename undefinedresult unmatchedmark unregistered internal error VMerror