So, What is PostScript?

Overview   Languge concepts   Languge reference   Postscript Fonts   Home

Overview

PostScript is a programming language optimized for printing graphics and text .
In the jargon of the day, it is a page description language. It was introduced by Adobe in 1985 and first appeared in the Apple LaserWriter. The main purpose of PostScript was to provide a convenient language in which to describe images in a device independent manner. Device independence means that the image is described without reference to any specific device features (e.g. printer resolution) so that the same description could be used on any PostScript printer without modification.
The language itself, which is typically interpreted, is stack-based . A program pushes arguments to an operator onto a stack and then invokes the operator.
Typically, the operator will have some result which is left at the top of the stack. As an example, let us
say we want to multiply 12 and 134. We would use the following PostScript code:

12 134 mul

The first two words '12' and '134' push the numbers 12 and 134 onto the stack. 'mul' invokes the multiply
operator which pops two values off the stack, multiplies them, and then pushes the result back onto the
stack. The resulting value can be left there to be used by another operator later in the program.


Language Concepts

PostScript is a programming language, with the follwing concepts :

Comment
A comment in PostScript is any text preceded by a '%'. The special comment '%!' as the first two
characters of a PostScript program is seen as a tag marking the file as PostScript code by many
systems (including Unix's lpr command). It is a good idea to start every PostScript document with
a '%!'... doing so will ensure that every spooler and printer the document may encounter will
recognize it as PostScript code.

Stack
As explained in the previous paragraph.

Dictionary
A dictionary is a collection of name-value pairs. All named variables are stored in dictionaries.
Also, all available operators are stored in dictionaries along with their code. The dictionary stack is
a stack of all currently open dictionaries. When a program refers to some key, the interpreter
wanders down the stack looking for the first instance of that key in a dictionary.

Name
A name is any sequence of characters that can not be interpreted as a number.
If a name is preceded by a slash, PostScript will place the name on the stack as an operand. If the
name has no slash, the interpreter will look up its value in the dictionary stack. If the value is a
procedure object, the procedure will be evaluated. If the value is not a procedure, the value will
be pushed onto the operand stack.

Number
PostScript supports integers and reals.

Array
Arrays in PostScript are like arrays in any other language. Arrays may contain objects of different
type, and they are written as a list of objects surrounded by brackets. For instance, [12 /Foo 5] is a
three element array containing the number 12, the name Foo, and the number 5.

Procedure
A procedure is your way of defining new operators. A procedure is an array that is executable and
is written with braces rather than brackets. For example, a procedure to square the top element on
the stack might be written as: {dup mul}. We can define this procedure to be the square operator
with: /square {dup mul} def.

Text
Printing text on a page is simple, all you have to do is:

The show operator is the basic operator for printing strings of text. It takes a string and prints it out in
the current font and with the lower left corner at the current point. After the text has been printed, the
current point is at the lower right of the string.

Languge reference   Postscript Fonts   Home