The magazine of the Melbourne PC User Group
PostScript -
For the bookshelf
Major Keary |
|
PostScript derives from work done at Xerox PARC in the late 1970s and early
1980s; commercial development was taken over by Adobe Systems and now PostScript
is firmly established. It is widely used for the production and transfer of
documents for the print industry, and has given us the PDF format.
For many computer users PostScript is a black art, the secrets of which are
known to only a privileged few. PostScript is both a page description language
and a programming language. PostScript files are created and stored in "pure"
ASCII, which means the original 7-bit standard set out in ANSI X3.4-1968; files
contain only those ninety-three characters that are represented on the keyboard:
a-z, A-Z, 0-9, space, and the punctuation marks and other symbols for which
there are keys. PostScript files are platform-independent and particularly
robust for transmission over poor communication connections. They can also be
very large files, but compress well. |
 |
Creating PostScript files is easy. Just use a PostScript printer driver (you
don't need a physical printer) and print-to-file from any application that
provides a print function (word processor, DTP, graphics, and so on). There is
plenty of software-some free-that will convert a PostScript file to PDF. Even
printing on non-PostScript printers can be achieved with software emulation,
such as provided by
GhostScript. GSView, which runs under GhostScript, is a GUI implementation and
can be used to print or display PostScript and EPS files, and will convert a
PostScript file to EPS.
EPS stands for "encapsulated PostScript". EPS files contain a "bounding box"
that specifies a rectangle that contains the image, text, or a combination of
both; these files can be "placed" by DTP applications (as well as modern word
processors and many other applications). Open an EPS file with a text editor and
you will see something like
%%BoundingBox: 153 153 459 560
somewhere near the
top of the file. Not all PostScript files can be converted to EPS, but there is
not room here to discuss the format in detail.
Why would anyone want to hand craft a PostScript file? It helps users understand
the format and can make it easier to detect the source of output problems,
something-from personal experience-easier said than done. There are a number of
routines that one can create with short PostScript files, but which are not easy
to achieve otherwise.
For those who want an introduction to writing PostScript programs or PostScript
files, or just want to learn about it, there is a dearth of literature in print.
There have been some good books, but they are out of print. You may find
something in the secondhand bookshops, but be warned that searching for
"postscript" on book vendor sites can throw up a lot of extraneous data.
As far as I am aware the only introductory title presently in print is Adobe's
PostScript Language Tutorial and Cookbook. Published in 1985, it is presently in
its 26th printing-a remarkable record for a computer-related title. The
PostScript language, if nothing else, is stable.
Regardless of enhancements to the language, this text is still fully relevant to
fundamental programming. The book is in two parts: a tutorial that explains
programming basics, and a cookbook that demonstrates a range of solutions to
particular problems.
For example, suppose you want to create an outline font; the cookbook section
contains a PostScript program (including how to re-encode a character set) that
will convert an existing 'filled' Type 1 font into an outline font. Want to make
a small caps font? It is not simply a matter of going down two points, as most
DTP applications do. Typographically correct small caps requires a change in
weight as well as size. The book provides a routine to create proper small cap
fonts. There are a number of other font manipulation programs-such as setting
fractions-that should be of special interest, and value, to anyone involved in
typographic design. There is also a program for setting vertical text.
A number of graphics routines are also included. They provide excellent
templates for creating particular effects and logos. There is also a program for
creating a poster composed of several A4 sheets that can be joined together.
For those who want to know how it all works, the tutorial section explains the
PostScript stack and arithmetic, the PostScript coordinate system, graphics,
loops, arrays, clipping, and how to draw lines and filled shapes. The meaning
and use of mysterious operators (such as mul, pstack, translate, grestore, and
pop) are well explained with examples. Anyone with a general interest in
learning about programming should find the tutorial quite helpful for its clear
descriptions of how the most commonly used operators work.
One does not have to be a programming expert to make use of PostScript,
especially for a limited repertoire of routines, such as font manipulation or
the creation of simple graphics. For those who want a solution to a particular
problem this book may be all they need. Those who want to master PostScript will
find it a valuable introduction.
Adobe Systems: PostScript Language Tutorial and Cookbook
ISBN 0-201-10179-3
Published by Addison-Wesley,
243 pp., RRP $57.95 incl. GST |
 |
The definitive resource, of course, is Adobe's PostScript Language Reference
Manual. It is complete, but assumes the reader is already familiar with
PostScript programming.
This is an image created by the accompanying program:
|
|
 |
|
|
/inch {72 mul} def
/wedge
{newpath
0 0 moveto
1 0 translate
15 rotate
0 15 sin translate
0 0 15 sin -90 90 arc
closepath
} def
gsave
3.75 inch 7.25 inch translate
1 inch 1 inch scale
wedge 0.02 setlinewidth
stroke
grestore
gsave
4.25 inch 4.25 inch translate
1.75 inch 1.75 inch scale
0.02 setlinewidth
1 1 12
{12 div setgray
gsave
wedge
gsave fill grestore
0 setgray stroke
grestore
30 rotate
} for
grestore
showpage |
The file is in two parts, procedures and the program. The first ten lines set up
two definitions:
"/inch {72 mul} def"
is a common method of translating inches
into 1/72-inch units used by PostScript's coordinate system; the other defines
the wedge shape used to make up the image.
The rest of the file is procedural; in a surprisingly small space it tells
PostScript how and where to place the wedges, and the fill for each one. Once a
user gets the hang of the way in which this routine (one of many in the cookbook
section) is organised, other designs can be created. By using GSView one can see
the result of any change without the hassles of printing.
The Tutorial and Cookbook won't turn you into a PostScript expert, but it will
show you how to do some useful things. As an introduction to further study of
PostScript it is highly recommended.
Reprinted from the April 2003 issue of PC Update, the magazine of Melbourne PC
User Group, Australia
|