Getting
Started With Postscript
To get started with Postscript some tools are required. For this tutorial, GhostScript will be used as the postscript interpreter. GSview will also be used which is a nice viewer that works on top of GhostScript. GhostScript could do everything that is done in the tutorial without GSview but GSview is very handy and quicker than learning all the GhostScript specific features. GhostScript & GSview Install GhostScript can be obtained from http://www.cs.wisc.edu/~ghost/ as well as GSview. Downloading either the AFPL or GNU version of GhostScript. There are downloads for Macintosh, Windows, and Linux/Unix. Grab both GhostScript and GSview and run the installers. The default location is fine. When running GhostScript alone, it works as a command line Postscript interpreter. Next in this tutorial a discussion on postscript basics will go over basic usage of GhostScript. PostScript BasicsPostscript is a language that was designed by Adobe and was intended for printing graphics. Postscript can be used to describe graphics with device independence. This allows any postscript printer to print the same thing. Postscript can be written by hand to make graphics or to describe a page for print. But normally postscript is written by a program that converts what the user puts on the page. In this tutorial and the tutorials to follow we will be writing our programs by hand and getting to know the language features. Hello World! Every good tutorial on programming has a Hello World example. Okay so maybe not all of them but we will do one just for fun. Type the following into a file called hello.ps: %!PS-Adobe-3.0 If you have installed GSview properly then all you have to do is save this file and open it in GSview. Then you will se the page that you created. We are not going to discuss this program much but the basics used in the program will be covered. Means of Combination: PS Stack:
Basic stack operations - These are just some of the basic stack operations that will be used. There are others that can be really hand to manipulating data on the stack that will be discussed later.
Primitive Elements:
Problem: we will be evaluating 6 + (3 / 8). How many ways can you write this and achieve the right answer? Means of Abstraction: Postscript supports creating procedures which as we all know will
make a program more readable and will shorten the amount of code we
have to write. To make procedure the name starts with a / and then
any name like /foo to name the procedure foo. The in curly braces
the procedure is written and finally the word def it put at the end.
Here is an example of a competed procedure: /inch {72 mul} def This procedure will add the number 72 to the stack and then multiply. This is a commonly used procedure since there is 72 points in postscript in an inch. This is how we use this function: 5 inch
More Stack Operators: There are more stack operators than those discussed above. These operators provide for more manipulation of the stack and can be really handy.
Problems:
***Note: Experiment with the stack until you feel comfortable with it. The stack is used everywhere so it is very important that you understand the stack and the basic operations that can be done. |
||||||||||||||||||||||||
The
PostScript Tutorial Concieved and Created by Dann Ormond & Will Munn.
Inspired by Mike Grady PhD. Website Design by NiftySites.com. |