DEFINITIONS: TYPES etc.
|
(signed) integers
127 -65 +14 0 9999
reals
3.14 -2. 0.0 -.55 47.2e10 3E-3
radix numbers
8#1727 ( = 1727 base 8)
16#F07E ( = F07E base 16)
The base must be in [2...36], and digits in [0...(base-1)],
where the 36 possible digits are 0...9A...Z
Characters can be expressed as integers 8#000...8#377
% ( ) < > [ ] / { }
THE STACKSThere are four distinct stacks which represent the state of a Ghostscript program;
Fonts are special dictionaries with their own directory, added using "definefont" and read with "findfont". |
Arrays are 1-dimensional collections of objects, and an array can contain elements of all different types. Arrays are indexed from 0; an array of length n has indices from 0 to (n-1). Since [square brackets] delimit arrays in Ghostscript notation, an array of length n can be represented as [e0 e1 e2 ... en-1]. The element ei-1 may be referred to as the "ith" element in the references below. (So the 1st element is e0, and the 2nd element is e1. Get used to it.)Procedures are actually "executable arrays", and strings are arrays whose elements are all characters (that is, integers in the range 0 to 255).
Operators, by category | ||
|---|---|---|
In the "usage" examples which follow, the following operands are
assumed to be of the indicated type:i, j, n = integer x, y, z = any number, real or integer a, b, c = any type of object e = element of an array STR, str = longer and shorter string ARY, ary = longer and shorter array | ||
pushes all elements of the array onto stack, followed by array itself
binary bitwise and (à la C)
prints string, combining special effects of ashow and widthshow
number of bytes available for reading. EOF=-1
adds character path outlines of given string, without stroking them, to the current path
counts operands, pushes number onto stack
bitwise complement
bitwise inclusive-or
returns a pseudorandom integer n < 2^31. Don't rely on this random-number-generator being of high quality...
returns the current seed for the random-number-generator, which can be used later with srand
makes n the seed value for the random-number-generator
y is the same type as x, but with the fraction part dropped
bitwise exclusive-or
alters the coordinate axes (CTM) by stretching the x-axis by factor sx and that of the y-axis by factor sy
rotates coordinate axes (CTM) by z degrees
translates coordinate axes (CTM) by (x,y)
replaces value of given matrix with one in which the coordinate system is scale by z degrees
replaces value of given matrix with one in which the coordinate system is rotated by z degrees
replaces value of given matrix with one in which the coordinate system is translated by (x,y)
updates CTM (current transformation matrix) with matrix X CTM
replaces value of matr3 with matr1 X matr2
replaces value of matrix with CTM
replaces value of matrix with the default transformaton matrix of current device, and pushes it onto stack
transforms coordinates (x,y) using CTM
transforms coordinates (x,y) using matrix
transforms coordinates (x,y) using the inverse of CTM
transforms coordinates (x,y) using the inverse of matrix
transforms distance vector (x,y) using CTM
transforms distance vector (x,y) using matrix
transforms distance vector (x,y) using the inverse of CTM
transforms distance vector (x,y) using the inverse of matrix
sets matr to [1 0 0 1 0 0]
sets the CTM to the default matrix
returns mtrx2, which now is the inverse of mtrx1
creates an identity matrix
replaces CTM with given matrix. Don't use this
empties current path, undefines current point
coordinates of current graphics point
appends counterclockwise circular arc to current path, possibly preceeded by straight segment: center (x,y), radius r, from theta = a1 to a2 (in degrees)
just like arc, but in clockwise direction
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
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
appends a straight line segment from previous current point to new current point (x,y)
starts a new subpath at point (x,y)
like curveto, but the 3 x-y pairs are relative to current point (x0,y0)
like lineto, but the x-y coordinate pair is a measurement relative to the current point (x0,y0), not absolute coordinates
like moveto, but the x-y coordinate pair is a measurement relative to the current point (x0,y0), not absolute coordinates
closes current path, appending a straight segment which connects the current point to starting point
adds character path outlines of given string, without stroking them, to the current path
produces new (smaller) clipping path, by intersecting current clipping path with interior of current path
sets current path to current clipping path
produces new (smaller) clipping path, by intersecting current clipping path with interior of current path, using the even-odd rule to determine the latter
replaces current path with the path where all "curveto" portions are replaced with equivalent "lineto" segments
replaces current clip path with default clip path (edges of page!)
returns the bounding box of the current path in current coordinate system; the x-y values of the lower-left and upper-right corners
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
replaces current path with same path in reverse order
replaces the current path with the outline of the shape that would result from using "stroke"
overpaints the interior of the current path
paints a line on the current path, using the current color, linewidth, dash pattern and other parameters
overpaints the interior of the current path, using the even-odd rule to determine "interior"
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.
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")
true if equal, otherwise false
logical negation
bitwise complement
logical negation of eq
logical negation
bitwise complement
numerical or lexical "greater than or equals"
numerical or lexical "greater than"
numerical or lexical "less than or equals"
numerical or lexical "less than"
logical disjunction
bitwise inclusive-or
binary bitwise and; i && j
logical conjunction
logical disjunction
bitwise exclusive-or
creates a string of n characters, all ASCII 0
replaces 1st n characters of STR with str, where length of str = n <= length of STR
interprets string, converts to an integer
interprets string and converts it to a real number
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.
converts to string: produces text representation of a and returns that string, overwriting initial substring of STR
executes proc on each character (integer 0-255) of str in turn
gets the (i+1)th character of str
gets the substring of length n, starting with (i+1)th character
number of characters in string
replaces (i+1)th character of str with ASCII character n
overwrites STR, starting at the (i+1)th character, with smaller string str
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
if str matches initial substring of STR; (remainder) (match) true otherwise; STR false
returns "true" is str contains anything besides white space (also returns pieces of original string). Otherwise, false.
sends current page to be printed, and starts a new, blank page
pushes a copy of the current graphics state onto the graphics-state stack.
pops the top element from the graphics-state stack and makes that the current graphics state
takes a "snapshot" of all virtual memory (values of all element of composite objects) and also duplicates current graphics state onto the graphics stack
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
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
resets values in graphics state to their default: initmatrix newpath initclip 1 setlinewidth 0 setlinecap 0 setlinejoin [] 0 setdash 0 setgray 10 setmiterlimit
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.
sets the flatness parameter to positive number x. This parameter controls how accurately curves are rendered into straight line segments
sets the current color parameter to a gray shade, where black = 0 <= x <= 1 = white.
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
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
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
sets the line width parameter to x>=0; line width 0 produces the thinnest possible device-resolution line
sets the miter limit parameter to x>=1, which limits the length of sharp corner miters
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.
sets the current halftone screen definition
sets the function which converts "user gray" values (0-1) into "device gray" values (0-1)
current miter limit value
current dash array and offset
current flatness parameterrr currenttransfer
current brightness value (0-1)
current color, HSB components
current line cap pameter
current line join parameter
current line width value
current color, RGB components
current halftone screen parameters
current graphics transfer function
pushes given dictionary onto the dictionary stack (making it the current dictionary)
copies all n elements of dict1 into length-zero dict2 (of maxlength >= n)
counts number of dictionaries currently on the dictionary stack; pushes number on stack
copies current dictionary onto operand stack
(re)defines key with value, in the current dictionary
creates new empty dictionary with maximum capacity n
copies all n elements of the dictionary stack into ARY, and returns the length-n subarray
pops the current dictionary off the dictionary stack
dictionary of basic Ghostscript operators
dictionary of global operators
dictionary of error handlers
global dictionary of fonts
executes proc on each key-value pair of dict, in some order
returns the value associated with key
whether key is an entry in dict
the number of defined key-value pairs
puts the value associated with key onto the stack, but does not execute it
returns maximum capacity of dictionary
associates key with value a in dictionary
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
(returns false if key is not found.)
returns type name of a
converts to integer (truncates)
interprets string, converts to an integer
converts to "literal" (not executable)
Converts to a name object, e.g. (abc) cvn ---> /abc Is executable if string was: (abc) cvx cvn ---> abc
converts to real value
interprets string and converts it to a real number
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.
converts to string: produces text representation of a and returns that string, overwriting initial substring of STR
converts to executable: makes top stack object executable, not literal
reduces access attribute of object (string or array) to "execute only" and not readable
tests "readability" of object a, which is an array, string, file or dictionary
reduces access attribute of object (array, string, file or dictionary) to "read-only"
tests "writeability" of object a, which is an array, string, file or dictionary
tests "executability" of object a
terminates execution of innermost enclosing loop (for, loop, repeat, forall)
executes proc repeatedly, each time providing a numerical operand, starting with x1 and stepping toward x2 in increments of dx
executes proc for each element of ary in turn
executes proc on each character (integer 0-255) of str in turn
executes proc on each key-value pair of dict, in some order
executes proc if bool=true
executes proc1 if bool=true, otherwise executes proc2
execute procedure repeatedly until the operator "exit" is encountered.
executes procedure n times
counts number of object on the execution stack; pushes number on stack
pushes operand onto execution stack, executing it immediately
creates array of all n elements of the execution stack, overwriting initial substring of ARY
prints string, starting at the current point and using the current font specifications
calculates the change in the current point which would occur using "show", but doesn't actually draw the string
prints string, adding spaces (x,y) between characters
prints string, adding space (x,y) after each occurence of the given character
prints string, combining special effects of ashow and widthshow
prints the characters of string one at a time, executing proc on consecutive pairs of characters at each step ("kernshow")
obtains font dictionary of given name
scales font by linear factor y
applies matrix to font
establishes font to be used by "show"
returns current font dictionary
registers font as a font dictionary of given name (key)
global dictionary of fonts
pops n, then duplicates top n operands
duplicates top element of stack
exchanges top 2 elements of stack
same as "[", marking the initial bound of an array
pops all operands from stack
pops all operands from stack until it reaches a "mark" (or `['), and pops the mark also
counts operands, pushes number onto stack
counts operands since most recent mark, and pushes this number onto the stack
replaces j with a copy of stack element aj, the (j+1)th-topmost element of the remaining stack
discards top element of stack
pops n and i, then performs a circular shift on the top n operands by the amount i (positive or negative)
"[" (synonymous with "mark") marks the beginning of a sequence, and "]" completes the sequence, creating an array and leaving it on the operand stack
pushes all elements of the array onto stack, followed by array itself
creates an n-length array of null objects
determines the length of ary (say n), and then stores the top n stack objects into that array and leaves it on stack
replaces 1st n elements of ARY with those of ary: length of ary = n <= length of ARY
executes proc for each element of ary in turn
returns the (i+1)th element of ary
returns a subarray of j elements starting with ei (the (i+1)th element of str)
returns the number of elements in array
/Arr [1 2 3 4 5 6] def
Arr 1 (X) put
Arr ---> [1 (X) 3 4 5 6]
replaces (i+1)th element of ary with a
replaces elements of ARY with those of ary, starting with the (i+1)th element
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
number of bytes available for reading. EOF=-1
closes the file
returns current file object -- usually "stdin"
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)
delivers any buffered characters
delivers any buffered characters to writefile, or discards remaining characters from readfile
writes to standard output
writes prompt (interactive operation)
writes text version of each stack element to stdout, but doesn't change the stack
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"
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"
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
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
executes contents of file represented by str
writes text version of each stack element to stdout, but doesn't change the stack
whether named file is still valid (open)
appends a single character to output file. char is an integer between 0 and 255
writes string to file as hex digits
writes string to file