There are lots of tutorials and reference information online. They seem to come and go (mostly go), so I decided to write my own:
What I like to do is to type some postscript into a file and use ghostview to look at the output:
gv test.psThis works pretty well, once you realize that ghostview may not be showing you the entire page. The thing to do is to fiddle with it's unique page scrolling dingus or change the viewing scale.
Next thing is to try sending something to a printer. I innocently try:
lpr test.psAnd get a nice listing of my program, but not what I wanted. Looking at some postscript files laying around on my system, I notice that they all begin with:
%!PS-Adobe-3.0Indeed, this does the trick. Rumor has it that just starting the file with %! would be sufficient. Having this magic shebang line makes my printing system actually render the postscript rather than printing the program as ascii text on the printer.
The next frontier is finding out what the addressible range is on my printer given an 8.5 by 11 inch sheet of paper. I suppose this is documented somewhere, but my bet is that I may as well just use trial and error and learn a bit of postscript in the process. A useful fact is that postscript works in its own system of units of which there are 72 per inch. This is what most of the world calls a "point", but the postscript literature seems very careful not to refer to them as such. For good old U.S. letter sized paper, 8.5 inches is 612 postscript units (0-611) and 11 inches is 792 units (0-791).
I wrote a program that generates graph paper (I didn't set out to generate graph paper, but that is what it amounts to). And graph paper in postscript units of all things! It has divisions of 5, 25, and 100 postscript units. Now it is fairly easy to print this out and see what part of the 8.5 by 11 inch sheet we can actually print on. On my HP Color Laserjet 4600dn, it looks like I can get to:
2 2 addTo draw a line you do:
100 100 moveto 244 244 lineto stroke showpageTo draw a circle of radius 144 centered at 200,200 you do:
newpath 200 200 144 0 360 arc closepath stroke showpageTo set the line width, you do:
0.25 setlinewidthTo define something with a value you do:
/dingus 17 defTo define a procedure you do:
/mything { add mul } defHere is a postscript idiom that some find confusing:
200 /var exch defWhat this does is to create a variable named "var" and put the value on the stack (here 200) into it. What is going on at the time the exch gets executed is that the stack holds two things - "200" and "/var". We need to flip these around so that when the def executes, it does "/var 200 def" for us.
0 10 100 {xxxxxxx} forAnother way is to use loop and exit.
As you might expect with a stack intensive language, postscript does support recursion.
Now, what fonts do I have available? Apparently there are 35 "standard" postscript
fonts, and most printers have them built in.
Many printers have additional fonts and/or can
have additional fonts loaded into
them.
Some printers have only 13 of the 35 listed below, these are the Courier, Times, Helvetica
(but not the Helvetica-Narrow) and the Symbol.
Here is a list of the 35 standard fonts:
The standard fonts are called "Type 1 fonts". This is a deep subject that I have yet to probe into.
I wrote a program to demonstrate the 13 basic fonts.
I also wrote a program to demonstrate the other 22 standard fonts.
My browser renders the above links via some viewer, which is useful, but not exactly what I had in mind. If you actually want to look at the postscript, you will have to do something clever, or just save the file to your disk and use some editor to look at it.
%!PS-Adobe-3.0 EPSF-3.0 /Times-Roman findfont 10 scalefont setfont (pickle) stringwidth pop == quitAnd I feed it to ghostscript via:
gs -q -dNODISPLAY size.psThis works nicely. Also note that it can be quite handy to just run "gs" instead of "gv". The "gv" command is just a front end to gs anyway, and gs will give you interactive postscript with a prompt.
Tom's Computer Info / [email protected]