|
 |
CS 3723/3721
Programming Languages
References & Access
|
|
Using Postscript on the
elk Systems:
Here is a sample postscipt file, stored using the filename
abc.ps:
Sample Postscript Program |
Output |
%!PS-Adobe-2.0
/Times-Bold findfont 200 scalefont setfont
100 300 moveto (ABC) show
showpage
|
|
You can create Postscipt files just using any editor.
The names of such files should always end with .ps.
If such files
are directly sent to a Postscipt printer, the printer will follow
the Postscript page description commands, rather than print it as
a text file. The printer uses the first line to decide
that this is a Postscript file. Otherwise you do not need
this first line. You can also convert the file to .pdf format as
illustrated below.
This conversion produces error messages
that can be very helpful in debugging.
Finally, you can put a link to either the
Postscipt file or the PDF file and open it through many browsers.
Convert to PDF, Produce Error Messages |
% vi abc.ps -- create the file with editor
% ps2pdf abc.ps abc.pdf -- convert to PDF,
-- produces error messages, 2nd arg optional
|
Open a link to this file as:
abc.ps , or as
abc.pdf
(The .ps file may not open on Windows machines.)
Here is a session working with two erroneous postscript programs.
- Misspelled Postscript operator or function:
This is by far the most common mistake, and is the main reason
you must always convert to PDF in order to get error messages.
- No starting point specified:
Postscript doesn't have a default starting position for items
placed on a page. You must always specify the "current point".
Misspelled Postscript Operator |
No Starting Point for Painting |
% cat abc.bad.ps
%!PS-Adobe-2.0
/Times-Bold findfont 200 scalefont setfont
100 300 movetto (ABC) show
showpage
% ps2pdf abc.bad.ps -- covert to PDF
Error: /undefined in movetto
Operand stack:
100 300
Execution stack:
(blah, blah, lots of stuff)
| % cat abc.bad2.ps
%!PS-Adobe-2.0
/Times-Bold findfont 200 scalefont setfont
(ABC) show
showpage
% ps2pdf abc.bad2.ps
Error: /nocurrentpoint in --show--
Operand stack:
(ABC)
Execution stack:
(blah, blah, lots of stuff)
|
Postscript Interactive
Development Environment:
Mr. John Whipple (a previous student) has
called attention to a "Very nice PostScript IDE/Debugger".
It is free to download and runs on all environments.
(I haven't tried it out yet.) Whipple:
"You can step through your program and see what's on
the stack. Very helpful!"
http://sourceforge.net/projects/wxghostscript/.
Postscript references
(recommended sources are in
red:
Basic Topics (from the Blue Book):
- Three types of graphics objects:
- Text: characters in many fonts, positioned and oriented in any way.
- Geometric figures: Drawn using powerful 2-dimensional graphics
operators, using lines, curves, filled regions, color.
- Images: anything that can be digitized.
(See Blue Book, pages 1-2.)
- The imaging model:
- Current page: can place anything anywhere, overwriting old stuff
- Current path: a set of connected lines and curves making a path,
often closed.
- Current clipping path: a closed path within which all drawing occurs.
(See Blue Book, pages 2-3.)
- Initial graphics: (See Blue Book, pages 3-4.)
- The Stack: used for all computations and operators. Postfix notation.
(See Blue Book, page 4, 7-15.)
- Coordinate systems:
x (horizontal) and y (vertical) coordinates,
with (0, 0) in the lower left corner.
Units are Postscipt points, where 1 point =
1/72 inch (in actual publishing, 1 point = 1/72.27 inch.)
(See Blue Book, Chapter 3, pages 17-25.)
- Variables and procedures: (It's getting harder now.)
(See Blue Book, Chapter 4, pages 27-33.)
- Text: (See Blue Book, Chapter 5, pages 35-46.)
- More graphics: (See Blue Book, Chapter 6, pages 47-60.)
- Conditionals and for loops: (See Blue Book, Section 7.1 and
first page of 7.2, pages 61-68.)
- Outline fonts: (See Blue Book, Section 9.4, pages 97-99.)
- Clipping: (See Blue Book, Section 10.1, pages 101-104.)
( Revision date: 2015-01-03.
Please use ISO 8601,
the International Standard Date and Time Notation.)
|