more PostScript info

Reference for Ghostscript operators

For some brief comments about Ghostscript object types, stacks, special characters, arrays, and operators grouped by theme, try Reference for Ghostscript entities.

Most of the basic Ghostscript operators are mentioned below. The following index will help you get around:

A, B, C, D, E, F, G, I, K, L, M, N, O, P, R, S, T, U, W, X.

The "USAGE" field for each operator listed indicates the objects at the top of the operand stack (last object listed is the topmost) which are used by the operator. The "RESULT" field indicates only the resulting objects at the top of the operand stack (last listed is the topmost), produced by the operator itself. An operator may have an effect on the graphics state or one of the other stacks as well, but these are not shown in the "RESULT" field. Also, any procedures which are executed as a result of this operator might produce other changes in the operand stack...

The following variable names indicate objects of the following types:

     i, j, n = integer
     x, y, z = any number; real or integer
     a, b, c = any type of object, sometimes numbered from 1 to n
           e = element of an array of length n, numbered from e0 to en-1
    STR, str = longer and shorter string
    ARY, ary = longer and shorter array
     proc    = procedure, in curly brackets (e.g., {lineto stroke})

[ ]

"[" (synonymous with "mark") marks the beginning of a sequence, and "]" completes the sequence, creating an array and leaving it on the operand stack

=

pops object from operand stack and sends its value (converted to text) to stdout

==

pops object from operand stack and sends it (converted to text) to stdout
(go to top, B)

abs


add


aload

pushes all elements of the array onto stack, followed by array itself

anchorsearch

if str matches initial substring of STR; (remainder) (match) true otherwise; STR false

and

and

logical conjunction

arc

appends counterclockwise circular arc to current path, possibly preceeded by straight segment: center (x,y), radius r, from theta = a1 to a2 (degrees)

arcn

just like arc, but in clockwise direction

arcto

appends circular arc to current path, possibly preceeded by a straight segment; radius r, with tangent lines from current point to (x1,y1) to (x2,y2). The returned values are the coordinates of the two tangent points

array

creates an n-length array of null objects

ashow

prints string, adding spaces (x,y) between characters

astore

determines the length of ary (say n), and then stores the top n stack objects into that array and leaves it on stack

atan


awidthshow

prints string, combining special effects of ashow and widthshow
(go to top, A, C)

begin

pushes given dictionary onto the dictionary stack (making it the current dictionary)

bitshift


bytesavailable

number of bytes available for reading. EOF=-1
(go to top, B, D)

ceiling


charpath

adds character path outlines of given string, without stroking them, to the current path

clear

pops all operands from stack

cleartomark

pops all operands from stack until it reaches a "mark" (or `['), and pops the mark also

clip

produces new (smaller) clipping path, by intersecting current clipping path with interior of current path

clippath

sets current path to current clipping path

closefile

closes the file

closepath

closes current path, appending a straight segment which connects the current point to starting point

concat

updates CTM (current transformation matrix) with matrix X CTM

concatmatrix

replaces value of matr3 with matr1 X matr2

copy

pops n, then duplicates top n operands

copy

replaces first n elements of ARY with those of ary: length of ary = n <= length of ARY

copy

replaces first n characters of STR with str, where length of str = n <= length of STR

copy

copies all n elements of dict1 into length-zero dict2 (of maxlength >= n)

cos


count

counts operands, pushes number onto stack

countdictstack

counts number of dictionaries currently on the dictionary stack; pushes number on stack

countexecstack

counts number of object on the execution stack; pushes number on stack

counttomark

counts operands since most recent mark, and pushes this number onto the stack

currentdash

current dash array and offset

currentdict

copies current dictionary onto operand stack

currentfile

returns current file object -- usually "stdin"

currentflat

current flatness parameter

currentfont

returns current font dictionary

currentgray

current brightness value (0-1)

currenthsbcolor

current color, HSB components

currentlinecap

current line cap pameter

currentlinejoin

current line join parameter

currentlinewidth

current line width value

currentmatrix

replaces value of matrix with CTM

currentmiterlimit

current miter limit value

currentpoint

coordinates of current graphics point

currentrgbcolor

current color, RGB components

currentscreen

current halftone screen parameters

currenttransfer

current graphics transfer function

curveto

appends Bezier cubic section, from current point (x0,y0) to point (x3,y3), onto the current path; (x3,y3) becomes the new current point. This curve follows equation
x = (1-t)^3 x0 + 3t(1-t)^2 x1 + 3t^2(1-t) x2 + t^3 x3
y = (1-t)^3 y0 + 3t(1-t)^2 y1 + 3t^2(1-t) y2 + t^3 y3
for parameter t, 0<=t<=1

cvi

converts to integer (truncates)

cvi

interprets string, converts to an integer

cvlit

converts to "literal" (not executable)

cvn

Converts to a name object, e.g. (abc) cvn ---> /abc Is executable if string was: (abc) cvx cvn ---> abc

cvr

converts to real value

cvr

interprets string and converts it to a real number

cvrs

Represents an integer (the integer part of non-negative value x) with radix j (1<j<36) and converts the representation to a string, returning the string and using it to overwrite initial substring of STR.

cvs

converts to string: produces text representation of a and returns that string, overwriting initial substring of STR

cvx

converts to executable: makes top stack object executable, not literal
(go to top, C, E)

def

(re)defines key with value

defaultmatrix

replaces value of matrix with the default transformaton matrix of current device, and pushes it onto stack

definefont

registers font as a font dictionary of given name (key)

dict

creates new empty dictionary with maximum capacity n

dictstack

copies all n elements of the dictionary stack into ARY, and returns the length-n subarray

div


dtransform

transforms distance vector (x,y) using CTM

dtransform

transforms distance vector (x,y) using matrix

dup

duplicates top element of stack
(go to top, D, F)

end

pops the current dictionary off the dictionary stack

eoclip

produces new (smaller) clipping path, by intersecting current clipping path with interior of current path, using the even-odd rule to determine the latter

eofill

overpaints the interior of the current path, using the even-odd rule to determine "interior"

eq

true if equal, otherwise false

errordict

dictionary of error handlers

exch

exchanges top 2 elements of stack

exec

pushes operand onto execution stack, executing it immediately

execstack

creates array of all n elements of the execution stack, overwriting initial substring of ARY

executeonly

reduces access attribute of object (string or array) to "execute only" and not readable

exit

terminates execution of innermost enclosing loop (for, loop, repeat, forall)

exp

(go to top, E, G)

false


file

creates file object, for use by read or write or the previous 2 commands. str2 must be (r) or (w) for "read" or "write", and str1 is the file identifier, e.g. (%stdin)

fill

overpaints the interior of the current path

findfont

obtains font dictionary of given name

flattenpath

replaces current path with the path where all "curveto" portions are replaced with equivalent "lineto" segments

floor


flush

delivers any buffered characters

flushfile

delivers any buffered characters to writefile, or discards remaining characters from readfile

FontDirectory

global dictionary of fonts

for

executes proc repeatedly, each time providing a numerical operand, starting with x1 and stepping toward x2 in increments of dx

forall

executes proc for each element of ary in turn

forall

executes proc on each character (integer 0-255) of str in turn

forall

executes proc on each key-value pair of dict, in some order
(go to top, F, I)

ge

numerical or lexical "greater than or equals"

get

returns the (i+1)th element of ary

get

gets the (i+1)th character of str

get

returns the value associated with key

getinterval

gets the substring of length n, starting with (i+1)th character

getinterval

returns a subarray of j elements starting with ei (the (i+1)th element of str)

grestore

pops the top element from the graphics-state stack and makes that the current graphics state

grestoreall

pops all graphics states more recent than the one preserved by the most recent "save" command (not gsave!) or the bottommost graphics state. Makes it the current graphics state

gsave

pushes a copy of the current graphics state onto the graphics-state stack.

gt

numerical or lexical "greater than"
(go to top, G, K)

identmatrix

sets matr to [1 0 0 1 0 0]

idiv


idtransform

transforms distance vector (x,y) using the inverse of CTM

idtransform

transforms distance vector (x,y) using the inverse of matrix

if

executes proc if bool=true

ifelse

executes proc1 if bool=true, otherwise executes proc2

image

paints a rectangular bitmap image, executing proc repeatedly to obtain the image data as characters. W,H are the width and height of the image samle array, bps (bits per sample), either 1,2,4 or 8, indicates how the samples are packed into the character data. matrix indicates how to scale and position the image relative to a unit square at the current point.

imagemask

like "image", but uses image only as a 1-bps mask to control where to paint the current color. Instead of "bps", the 3rd parameter bool indicates whether to paint on the 1-bits ("true") or 0-bits ("false")

index

replaces j with a copy of stack element aj, the (j+1)th-topmost element of the remaining stack

initclip

replaces current clip path with default clip path (edges of page!)

initgraphics

resets values in graphics state to their default: initmatrix newpath initclip 1 setlinewidth 0 setlinecap 0 setlinejoin [] 0 setdash 0 setgray 10 setmiterlimit

initmatrix

sets the CTM to the default matrix

invertmatrix

returns mtrx2, which now is the inverse of mtrx1

itransform

transforms coordinates (x,y) using the inverse of CTM

itransform

transforms coordinates (x,y) using the inverse of matrix
(go to top, I, L)

known

whether key is an entry in dict

kshow

prints the characters of string one at a time, executing proc on consecutive pairs of characters at each step ("kernshow")
(go to top, K, M)

le

numerical or lexical "less than or equals"

length

number of characters in string

length

returns the number of elements in array

length

the number of defined key-value pairs

lineto

appends a straight line segment from previous current point to new current point (x,y)

ln


load

puts the value associated with key onto the stack, but does not execute it

log


loop

execute procedure repeatedly until the operator "exit" is encountered.

lt

numerical or lexical "less than"
(go to top, L, N)

makefont

applies matrix to font

mark

same as "[", marking the initial bound of an array

matrix

creates an identity matrix

maxlength

returns maximum capacity of dictionary

mod


moveto

starts a new subpath at point (x,y)

mul

(go to top, M, O)

ne

logical negation of eq

neg


newpath

empties current path, undefines current point

not

logical negation

not

bitwise complement
(go to top, N, P)

or

logical disjunction

or

bitwise inclusive-or
(go to top, O, R)

pathbbox

returns the bounding box of the current path in current coordinate system; the x-y values of the lower-left and upper-right corners

pathforall

executes a procedure on each of the elements of the current path, in order; proc1 on all the "moveto" elements, proc2 on all the "lineto" elements, proc3 on the "curveto" elements, and proc4 on the "closepath" elements

pop

discards top element of stack

print

writes to standard output

prompt

writes prompt (interactive operation)

pstack

writes text version of each stack element to stdout, but doesn't change the stack

put

replaces (i+1)th character of str with ASCII character n

put

replaces (i+1)th element of ary with a

put

associates key with value a in dictionary

putinterval

overwrites STR, starting at the (i+1)th character, with smaller string str

putinterval

replaces elements of ARY with those of ary, starting with the (i+1)th element
(go to top, P, S)

rand

returns a pseudorandom integer n < 2^31. Don't rely on this random-number-generator being of high quality...

rcheck

tests "readability" of object a, which is an array, string, file or dictionary

rcurveto

like curveto, but the 3 x-y pairs are relative to current point (x0,y0)

read

reads the next character from input file and pushes it (as an integer, 0-255) onto stack with "true" -- unless at end of file, in which case it returns only "false"

readhexstring

reads hex-pair characters (0-9A-Fa-f) from file to overwrite STR, ignoring any non-hex characters except End-of-file. Returns successfully-read string and either "false" (if EOF was encountered) or "true"

readline

reads a line of characters from file (terminated by \n), uses them to overwrite the initials characters of STR, and returns the line (as a string) and "true". ("False" if EOF was encountered before EOL). String STR must be long enough to accommodate line

readonly

reduces access attribute of object (array, string, file or dictionary) to "read-only"

readstring

read characters from file into STR until STR is full or EOF. Returns read portion (as a string) and either "true" or "false", depending on whether EOF was encountered. ALL characters are read literally, including newline

repeat

executes procedure n times

restore

restores all values and graphics state to what they were when the most recent "save" was called; more recent graphics states and values are discarded and the virtual memory released

reversepath

replaces current path with same path in reverse order

rlineto

like lineto, but the x-y coordinate pair is a measurement relative to the current point (x0,y0), not absolute coordinates

rmoveto

like moveto, but the x-y coordinate pair is a measurement relative to the current point (x0,y0), not absolute coordinates

roll

pops n and i, then performs a circular shift on the top n operands by the amount i (positive or negative)

rotate

rotates coordinate axes (CTM) by z degrees

rotate

replaces value of given matrix with one in which the coordinate system is rotated by z degrees

round


rrand

returns the current seed for the random-number-generator, which can be used later with srand

run

executes contents of file represented by str
(go to top, R, T)

save

takes a "snapshot" of all virtual memory (values of all element of composite objects) and also duplicates current graphics state onto the graphics stack

scale

alters the coordinate axes (CTM) by stretching the x-axis by factor sx and that of the y-axis by factor sy

scale

replaces value of given matrix with one in which the coordinate system is scale by z degrees

scalefont

scales font by linear factor y

search

looks for a substring of STR which matches str, and returns strZ str strA true if successful: strA is the portion of STR which preceeds the match, and strZ is the portion which follows it. If there is no match, then instead this command returns STR false

setdash

sets the dash pattern: ary contains the cyclic on-off distances of the dashes, which begin after an offset of x units from the current point. The array must consist of zero or more positive numbers. The command [] 0 setdash turns off dashing, making lines solid.

setflat

sets the flatness parameter to positive number x. This parameter controls how accurately curves are rendered into straight line segments

setfont

establishes font to be used by "show"

setgray

sets the current color parameter to a gray shade, where black = 0 <= x <= 1 = white.

sethsbcolor

sets the current color parameter according to hue, saturation and brightness values, which must each lie between 0 and 1. For bright colors use y=z=1. Hue (x) values: 0=red, 0.33=green, 0.67=blue

setlinecap

sets the line cap parameter: i=0: line ends are squared off at the endpoint i=1: line ends are rounded off i=2: line ends are given a projecting square cap

setlinejoin

set the line join parameter: i=0: corners are given a miter join (possibly beveled) i=1: corners are given a round join i=2: corners are given a bevel join

setlinewidth

sets the line width parameter to x>=0; line width 0 produces the thinnest possible device-resolution line

setmatrix

replaces CTM with given matrix. Don't use this

setmiterlimit

sets the miter limit parameter to x>=1, which limits the length of sharp corner miters

setrgbcolor

sets the current color parameter according to red, green, blue values, which must each lie between 0 and 1. Red = 1 0 0. Yellow = 1 1 0. Orange = 1 0.65 0.

setscreen

sets the current halftone screen definition

settransfer

sets the function which converts "user gray" values (0-1) into "device gray" values (0-1)

show

prints string, starting at the current point and using the current font specifications

showpage

sends current page to be printed, and starts a new, blank page

sin


sqrt


srand

makes n the seed value for the random-number-generator

stack

writes text version of each stack element to stdout, but doesn't change the stack

status

whether named file is still valid (open)

store

redefines key-value pair in the topmost dictionary where key can be found, or defines a new key-value pair in the current dictionary if no such key exists in any dictionary on the stack

string

creates a string of n characters, all ASCII 0

stringwidth

calculates the change in the current point which would occur using "show", but doesn't actually draw the string

stroke

paints a line on the current path, using the current color, linewidth, dash pattern and other parameters

strokepath

replaces the current path with the outline of the shape that would result from using "stroke"

sub


systemdict

dictionary of basic Ghostscript operators
(go to top, S, U)

token

returns "true" is str contains anything besides white space (also returns pieces of original string). Otherwise, false.

transform

transforms coordinates (x,y) using CTM

transform

transforms coordinates (x,y) using matrix

translate

translates coordinate axes (CTM) by (x,y)

translate

replaces value of given matrix with one in which the coordinate system is translated by (x,y)

true


truncate

y is the same type as x, but with the fraction part dropped

type

returns type name of a
(go to top, T, W)

userdict

dictionary of global operators
(go to top, U, X)

wcheck

tests "writeability" of object a, which is an array, string, file or dictionary

where

(returns false if key is not found.)

widthshow

prints string, adding space (x,y) after each occurence of the given character

write

appends a single character to output file. char is an integer between 0 and 255

writehexstring

writes string to file as hex digits

writestring

writes string to file
(go to top, W)

xcheck

tests "executability" of object a

xor

logical disjunction

xor

bitwise exclusive-or

(go to top)