s PostScript command summary

PostScript command summary

Stack manipulation

exch
num1 num2 exch
num2 num1

pop
any pop
-

copy
any[0] ... any[n-1] n copy
any[0] ... any[n-1] any[0] ... any[n-1]
copy has array, sequence, dictionary, string forms

dup
any dup
any any

index
any[n] ... any[0] n index
any[n] ... any[0] any[n]

roll
any[n-1] ... any[0] n j roll
any[j-1 mod n] ... any[j mod n]
rolls to right (left if j negative)

clear
* any[1] ... any[n] clear
*
* means stack bottom

count
* any[1] ... any[n] count
* any[1] ... any[n] n
* means stack bottom

mark
- mark
mark

cleartomark
mark obj[1] ... obj[n] cleartomark
-

countomark
mark obj[1] ... obj[n] countomark
mark obj[1] ... obj[n] n

Arithmetic

add
num1 num2 add
num1 + num2

div
num1 num2 div
num1/num2

sub
num1 num2 sub
num1 - num2

idiv
int1 int2 idiv
(int) int1/int2

mul
num1 num2 mul
num1*num2

mod
int1 int2 mod
int1 mod int2

abs
num abs
abs(num)

neg
num neg
-num

ceiling
num1 ceiling
num2

floor
num1 floor
num2
returns the greatest integer value less than or equal to num1: 3.2 -> 3.0; -4.8 -> -5.0

round
num round
num
rounds to nearest integer

truncate
num truncate
num - fractional part

sqrt
num sqrt
sqrt(num)

atan
num den atan
arctan(num/den)
degrees

cos
deg cos
cos(deg)
degrees

sin
deg sin
sin(deg)
degrees

exp
base num exp
base^{num}

ln
num ln
log_{e} num

log
num log
log_{10} num

rand
- rand
int

srand
int srand
-
sets random number seed

rrand
- rrand
int
returns random number seed

Arrays

array
int array
array (of length int)
recall that an array is a pointer-plus-structure,

[
- [
mark

]
mark obj[0] ... obj[n-1] ]
array
array of these objects

length
array length
int

get
array index get
array[index]

put
array index any put
-
stores any as array[index]

getinterval
array index count getinterval
subarray
the subarray is array[index] ... array[index+count-1]

putinterval
array1 index array2 putinterval
-
replaces array1 with aray2 starting with [index]

aload
array aload
a[0] ... a[n-1] array
pushes the array onto the stack

astore
a[0] ... a[n-1] array astore
array
stores the elements into the array all in one shot

copy
array1 array2 copy
subarray2
copies array1 to initial subarray of array2

forall
array proc forall
-
executes proc for each element of array

dict
int dict
dict
creates dictionary of capacity int

length
dict length
int
returns number of key-value pairs in the dictionary

maxlength
dict maxlength
int
capactity of dict

begin
dict begin
-
push dict on dict stack

end
- end
-
pops dict stack

def
key value def
-
associates key & value in current dict

load
key load
value
searches dict stack for key and returns value

store
key value store
-
replaces topmost definition of key

get
dict key get
any
returns value in dict associated to key

put
dict key value put
-
associates key value into dict

known
dict key known
bool
tests whether key is in dict

where
key where
dict true OR false
finds dict in which key is defined

copy
dict1 dict2 copy
dict2
copies contents of dict1 to dict2

forall
dict proc forall
-
executes proc for each element of dict

errordict
- errordict
dict
push errordict on operand stack

systemdict
- systemdict
dict
push systemdict on operand stack

userdict
- userdict
dict
push userdict on operand stack

currentdict
- currentdict
dict
push currentdict on operand stack

countdictstack
- countdictstack
int
counts elements on dictstack

dictstack
array dictstack
subarray
copy dictstack into array

Strings

string
int string
string
creates string of length int

length
string length
int
returns length of string

get
string index get
int
returns string[index]

put
string index int put
-
assigns string[index] = int

getinterval
string index count getinterval
substring
returns {string[index] .. string[index + count - 1]}

putinterval
string1 index string2 putinterval
-
replaces string1[index] ... by string2

copy
string1 string2 copy
substring2
copies string1 to initial substring of string2

forall
string proc forall
-
executes proc for each element of string

anchorsearch
string seek anchorsearch
post match true OR string false
determines if seek is initial substring of string

search
string seek search
post match true OR string false
determines if seek is substring of string

token
string token
post token true OR false
read token from start of string

Bit and Boolean operations

eq
any1 any2 eq
bool
tests equal

ne
any1 any2 ne
bool
tests not equal

ge
num1|string1 num2|string2 ge
bool
tests greater than or equal

gt
num1|string1 num2|string2 gt
bool

le
num1|string1 num2|string2 le
bool

lt
num1|string1 num2|string2 lt
bool

and
bool1|int1 bool2|int2 and
bool|int
logical|bitwise and

not
bool|int not
bool|int

or
bool1|int1 bool2|int2 or
bool|int

xor
bool1|int1 bool2|int2 xor
bool|int

true
- true
true

false
- false
false

bitshift
int1 shift bitshift
int2
positive is left

Flow control

exec
any exec
-
executes arbitrary object

if
bool proc if
-

ifelse
bool proc1 proc2 ifelse
-

for
j k l proc for
-
for i= j to l step k do proc

repeat
n proc repeat
-
does proc n times

loop
proc loop
-
do proc forever (include exit)

exit
- exit
-
exits innermost loop

stop
- stop
-
terminates stopped context (?)

stopped
any stopped
bool
establish context for catching stop

countexecstack
- countexecstack
int
count elements on execution stack

execstack
array execstack
subarray
copy execstack into array

quit
- quit
-
terminate interpreter

start
- start
-
executed automatically at interpreter startup

Types and conversions

type
any type
name

cvlit
any cvlit
any
makes object literal

cvx
any cvx
any
makes object executable

xcheck
any xcheck
bool
tests executable attributable

executeonly

noaccess

readonly

rcheck

wcheck

cvi
num/string cvi
int
converts to integer

cvn
string cvn
name
converts to name

cvr
num/string cvr
real
converts to real

cvrs
num radix string cvrs
substring

cvs
ob string cvs
substring
converts to string

Files

file
string1 string2 file
file
opens file string1 with access string2

closefile
file closefile
-

read
file read
int true OR false
reads one character from file

write
file int write
-

readhexstring
file string readhexstring
substring bool
reads hex from file into string

writehexstring
file string writehexstring
-
writes characters of string to file as hex

readstring
file string readstring
substring bool
reads from file into string

writestring
file string writestring
-
writes characters of string to file

readline
file string readline
substring bool
reads line from file into string

token
file token
token true OR false
reads token from file

bytesavailable
file bytesavailable
int
number of bytes available to read

flush
- flush
-
sends buffered data to standard output

flushfile
file flushfile
-
sends buffered data to file

resetfile
file resetfile
-
discard buffered characters

status
file status
bool
returns status of file

run
string run
-
executes contents of named file

currentfile
- currentfile
file

print
string print
-
writes characters of string to standard output

=
any =
=
writes text representation of any to stdout

stack
* any[1] ... any[n] stack
* any[1] ... any[n]
prints stack non-destructively

==
any ==
-
destructive display of top of stack

pstack
* obj[1] ... obj[n] pstack
* obj[1] ... obj[n]
non-destructive display of whole stack

prompt
- prompt
-
executed when ready for interactive input

echo
bool echo
-
turns on/off echoing

save
- save
save
create VM snapshot

restore
save restore
-
restore VM snapshot

vmstatus
- vmstatus
level used maximum
report VM status

Miscellaneous

bind

null

usertime

version

Graphics

gsave
- gsave
-
saves graphics state

grestore
- grestore
-
restores graphics state

grestoreall
- grestoreall
-
restore to bottommost graphics state

initgraphics
- initgraphics
-
reset graphics state parameters

setlinewidth
num setlinewidth
-
sets line width

currentlinewidth
- currentlinewidth
num
returns current line width

setlinecap
int setlinecap
-
sets shape of line ends (0=butt,1=round,2=square)

currentlinecap
- currentlinecap
int

setlinejoin
int setlinejoin
-
sets shape of corners for stroke (0=miter,1=round,2=bevel)

currentlinejoin
- currentlinejoin
int

setmiterlimit
num setmiterlimit
-
sets miter length limit

currentmiterlimit
- currentmiterlimit
num

setdash
array offset setdash
-
sets dash pattern for stroking

currentdash
- currentdash
array offset

setflat
num setflat
-
sets flatness tolerance

currentflat
- currentflat
num

setgray
num setgray
-
sets gray level for fill: 1.0 = white

currentgray
- currentgray
num

sethsbcolor
hue sat brt sethsbcolor
-
sets color given hue, saturation, brightness

currenthsbcolor
- currenthsbcolor
hue sat brt

setrgbcolor
red green blue setrgbcolor
-
sets color given red, green, blue

currentrgbcolor
- currentrgbcolor
red green blue

setscreen
freq angle proc setscreen
-
sets halftone screen

currentscreen
- currentscreen
freq angle proc

settransfer
proc settransfer
-
sets gray transfer function

currenttransfer
- currenttransfer
proc

Matrices

matrix
- matrix
matrix
creates identity matrix

initmatrix
- initmatrix
-
sets CTM to device default

identmatrix
matrix identmatrix
matrix
sets to identity

defaultmatrix
matrix defaultmatrix
matrix
fills matrix with device default matrix

currentmatrix
matrix currentmatrix
matrix
fills matrix with current CTM

setmatrix
matrix setmatrix
-
replace CTM by matrix

translate
tx ty translate
-
translates origin

translate
tx ty matrix translate
matrix
defines translation by (tx, ty)

scale
sx sy scale
-
scales user space

scale
sx sy matrix scale
matrix
defines scaqling by (sx, sy)

rotate
angle rotate
-
rotates user space

rotate
angle matrix rotate
matrix
define rotation by angle degrees

concat
matrix concat
-
CTM = matrix*CTM

concatmatrix
matrix1 matrix2 matrix3 concatmatrix
matrix3
matrix3 = matrix1*matrix2

transform
x y transform
x' y'
CTM*(x, y) - row or column vectors?

transform
x y matrix transform
x' y'
matrix*(x, y)

dtransform
dx dy dtransform
dx' dy'

dtransform
dx dy matrix dtransform
dx' dy'

itransform
x y itransform
x' y'
inverse transform by CTM

itransform
x y matrix itransform
x' y'
inverse transform

idtransform
dx dy idtransform
dx' dy'

idtransform
dx dy matrix idtransform
dx' dy'

invertmatrix
matrix1 matrix2 invertmatrix
matrix2
matrix2 = inverse of matrix1

Paths

newpath
- newpath
-
clears current path

currentpoint
- currentpoint
x y
returns current point

moveto
x y moveto
-
absolute move: changes current point

rmoveto
x y rmoveto
-
relative move: changes current point

lineto
x y lineto
-
puts line from current point to (x, y)

rlineto
x y rlineto
-
line from current point to current point + (x, y)

arc
centerx centery radius angle1 angle2 arc
-
counter-clockwise

arcn
centerx centery radius angle1 angle2 arcn
-
clockwise

arcto

curveto

rcurveto

closepath
- closepath
-
closes the current path with a straight line to the last moveto location

flattenpath

reversepath

strokepath

charpath
string bool charpath
-
add character outlines of string to current path

clippath
- clippath
-
set current path to clipping path

pathbbox
- pathbbox
llx lly urx ury
returns bounding box of current path

pathforall
move line curve close pathforall
-
enumerate current path

initclip
- initclip
-
set clip path to device default

clip
- clip
-
sets new clipping path

eoclip
- eoclip
-
clip using even-odd rule

erasepage
- erasepage
-
sets current page white

fill
- fill
-
fills current path with current color

eofill
- eofill
-
fill using even-odd rule

stroke
- stroke
-
paints the current path with the current color and line width

image
width height bits/sample matrix proc image
-
render sampled image onto current page

imagemask
width height invert matrix proc imagemask
-
renders mask onto current page

Set up

showpage
- showpage
-
transfers current page to output device

copypage

banddevice

framedevice

nulldevice

renderbands

Fonts

definefont

findfont
key findfont
fontdict
pushes the font dictionary on the stack; error handling unpredictable

scalefont
fontdict int scalefont
fontdict
scales the font from 1 to n

makefont

setfont
fontdict setfont
-
sets current font

currentfont
- currentfont
fontdict

show
string show
-
prints string at current location in current font

ashow

widthshow

awidthshow

kshow
proc string kshow
-
execute proc between showing characters in string

stringwidth
string stringwidth
intx inty
returns location if string were printed

FontDirectory

StandardEncoding

Font caches

cachestatus

setcachedevice

setcharwidth

setcachelimit

Errors

dictfull

dictstackoverflow

dictstackunderflow

execstackoverflow

handleerror

interrupt

invalidaccess

invalidexit

invalidfileaccess

invalidfont

invalidrestore

ioerror

limitcheck

nocurrentpoint

rangecheck

stackoverflow

stackunderflow

syntaxerror

timeout

typecheck

undefined

undefinedfilename

undefinedresult

unmatchedmark

unregistered

VMerror