POSTSCRIPT: A Short Description
The information given here has been extracted from the following two books:
- PostScript Language Reference Manual, by Adobe Systems Inc.,
2nd ed., Reading, Massachusetts: Addison-Wesley Publ.
Co., 1990, 764p.
- PostScript Language Tutorial and Cookbook, by Adobe Systems Inc.,
Reading, Massachusetts: Addison-Wesley Publ. Co., 1985;
11th printing, 1988.
PostScript is a device-independent page description programming language.
A short summary of its characteristics is given here:
- PostScript files are text files: they may be edited with any text editor.
A PostScript file contains a program that describes how to print
one or more pages.
- Comments may be written after a percent sign (%).
Anything in a line after a % is ignored by PostScript.
Nevertheless some comments are significant:
- The first line must start with %!
- The following comments are usually taken into account by programs that deal with
PostScript files: %%Title, %%Creator, %%CreationDate,
%%DocumentFonts, %%BoundingBox,
%%Pages, %%Page, %%EndComments, %%EndProlog,
and %%Trailer.
- The %%BoundingBox comment is necessary to include an
encapsulated PostScript file in another document. The size of the bounding
box is given in default units (1/72 of an inch =
1/28.35 of a cm).
- The working memory in PostScript is a stack (data are stored as
books on a pile: last book placed on the stack is the first one that may
be picked-up). For example: 270 360 add will first
place two numbers on the stack, and the operator add will take these two
numbers out from the stack, perform a sum, and place the result on the stack.
- Drawing consists of creating a path (a set of lines, points, arcs,
text, etc) with the command newpath followed by path-creating commands
(for example: moveto and lineto). Once the
path has been composed it is painted with the command stroke.
Several paths are usually drawn on a page. Finally the command
showpage prints the current page.
- Dictionaries are tables of keys associated to their definitions.
The system dictionary contains the names of all PostScript operators
with their associated built-in actions. The user dictionary contains
the procedures and variables defined by a PostScript program by the def
operator: /ppcm 28.35 def will place the variable ppcm
(defined as 28.35) in the user dictionary.
- Procedures may be defined to perform any given printing task.
For example: /Ln {lineto} def will define the procedure
Ln, which may be used instead of lineto.
Then: 270 360 Ln would create a line in the current
path from the current point to the x and y coordinates present in
the stack (that is: x=270 and y=360).
Using procedures, parts of a page may be defined and then used to compose
the rest of the page, after translation, rotation, scaling, etc.
- Text is printed as follows. First a font must be selected
(findfont), scaled (scalefont),
and established as the current font (setfont).
For example: /Times-Roman findfont 15 scalefont
setfont. Strings of text are placed on the stack by
enclosing them in parenthesis, and they are printed on the current page
with the show operator. For example: 100 100 moveto
(Hello) show.
-
In a text string the backslash (\) character has a special
meaning:
|
\( |
|
left parenthesis |
|
\) |
|
right parenthesis |
|
\\ |
|
backslash |
|
\nnn |
|
character codes (octal) |
-
Octal character codes give different results depending on the
encoding and on the font family.
The PlotPS conversion program
uses the ISO Latin-1 encoding and both Roman and Symbol
fonts. Several accented letters and symbols are available as
character codes.
Two examples:
In the PostScript file: | In the print-out |
(t = 25\260C) show |
t = 25°C |
(Varf\366r \344r det s\345?) show |
Varför är det så? |
Additional details are given in the books listed above.
The PlotPS program used by
SPANA defines its own set of functions and
variables.