Antigrav Toolkit Notebook
by Randy Winchester
Inside PostScript
Last month's article discussed how to connect to a laser printer with a modem. This month I'll show you how to save geoLaser output as a PostScript program. We'll go inside a PostScript program to see how new functions can be accomplished - features not now available from GEOS.
Snarfing a PostScript File
First, an update. Berkeley Softworks has released geoPublaser, a laser printer application for use with geoPublish. It includes some nice functions such as bitmap smoothing, a reduction and enlargement feature, multiple copies, and can produce "thumbnails" - miniatures of each page of your document on one page. In most other respects, it looks and operates just like geoLaser, except the screen is blanked when operating at 1200 bps.
To get started, we'll need two computers; one must be a C=64 or C=128. Both computers will have to be equipped with 1200 bps modems. If both computers are in the same room, you can use a "null modem" cable. This is simply a cable that connects between the user ports of the two computers and simulates a modem connection. For software, in addition to GEOS, we'll need geoLaser, geoPubLaser, or the LaserWriter printer driver; a geoWrite, geoPaint, or geoPublish document; and your favorite telecommunications software. I highly recommend the public domain CBTERM. After using it for several years, I've found it to be more reliable than most other terminal programs, including many commercial ones.
Get the terminal software running on the two computers. Use the following settings: Baud Rate = 1200, Data Bits = 8, Parity = none, Handshake = none, Echo = off. Depending on your circumstances, you might have two computers in the same room connected with a null modem cable, or you might ring up a friend who also has a computer and modem. The computer you send the PostScript program to doesn't even have to be a Commodore. Almost any computer with decent terminal software will do the trick.
Once a telecommunciations link has been established, open the capture buffer on the receiving computer. Boot GEOS on the sending computer and run geoLaser, geoPubLaser, or print a document using the LaserWriter printer driver. The output will go through the modem to the receiving computer's capture buffer. When the file is done printing, close the capture buffer and save it as a SEQuential file. The SEQuential file will be a complete PostScript program which can be edited, modified, copied onto other disks, and even printed without the use of GEOS.
Why PostScript?
PostScript is a page description language developed by Adobe Systems. It very quickly became the standard for use in laser printers. In comparison with other programming languages, PostScript is versatile and powerful, much more powerful than BASIC. Not only can PostScript programs be used to print bar graphs or pie charts, they can also do the calculations to generate them given the raw data. For now, we'll stick to using it for graphics and text. If you are interested in some of the more exotic uses of PostScript, there are some excellent books on the subject of PostScript programming, such as the PostScript Language Reference Manual by Adobe Systems.
PostScript programs can be produced on almost any computer using almost any word processor or text editor which saves it's output in SEQuential files. PostScript most resembles the Forth programming language. If you are at all familiar with Forth, you'll have little trouble adapting to PostScript. They both share the same syntax and many of the same features.
Once you have saved a few PostScript programs from GEOS, I suggest you print them and look them over. We'll carefully examine some specimens in the remainder of this article.
A Commented PostScript Listing
As the first example, let's take a look at the output from a geoPaint document made with the LaserWriter printer driver. This text has been reformatted in order to make it more readable.
/picString 640 string def
The / character begins a definition. This defines the variable picString as a string 640 bytes long. Values precede operators in PostScript. It may seem awkward to say 640 string instead of string 640 but it's really more efficient that way. The word def ends a definition.
/imageBuffer { gsave 640 8
scale
640 8 1 [640 0 0 -8 0 8]
{currentfile picString
readhexstring pop} image grestore } def
This defines a routine named imageBuffer, which handles the printing of bitmap graphics. It reads the bitmap data one line at a time. The command gsave places the current representation of the graphic image in temporary storage while new information is being processed. 640 8 scale enlarges the bitmap 640 times in the horizontal direction and 8 times in the vertical direction, necessary because of the higher resolution of laser printers. 640 bytes of bitmap data are then read from the currentfile into the variable picString using the readhexstring command. The data is "painted" on the page by the image operator. The previous graphic image is then recalled using grestore.
/moveDown { 0 -8 translate } def
The moveDown procedure is used to create what would be a linefeed on a dot matrix printer. The word translate is responsible for setting the position of the drawing area, something like moving the drawing window in geoPaint. PostScript uses an X and Y axis to define coordinates. The lower left corner of the page is point 0,0. As you move to the upper right corner, the values increase. A PostScript page is 612 points wide by 792 points high. There are 72 points per inch - known as a printer's point. The values 0,-8 for moveDown position the laser printer drawing window down by 8 points.
72 75 div 72 75 div scale
This line scales the bitmap from the 75 pixel per inch representation used by GEOS to the 72 point per inch scale used by laser printers. The div operator takes two values (which precede it) and performs division. This line has the effect of reducing the page slightly, by 96% (72 divided by 75). This is one part of a PostScript program that can easily be modified. Replace the line with .25 .25 scale, and you'll get a minature copy of your artwork. If you use 1 .25 scale, you'll get a normal width picture that is compressed vertically. Values much larger than 1.1 will print an expanded image off the edge of the page.
0.25 75 mul 10.75 75 mul translate
This time the translate command is used in direct mode to move the starting position to the upper left corner of the page. The word mul multiplies the two (preceding) values. The first values, 0.25 75, set the left margin at one-quarter inch. The second two values, 10.75 75, set the top margin at 10.75 inches. Remember that PostScript starts measuring from the lower left corner of the page. These two values can be changed to start printing at any location on the page.
moveDown
Executes moveDown, defined above.
ImageBuffer
FF01C1C1C1C1C1C1C1C1C1C3838383838383838383838
838383838838
% ( . . . etc., 640 bytes, 1280 characters total)
The imageBuffer procedure reads in 640 bytes of bitmap data (represented by hexadecimal digits) and converts it to an image in the laser printer. This is followed by:
moveDown % go to the next
line
imageBuffer % followed by 640 more bytes of data
moveDown
% next line
repeated until the entire picture is drawn inside the laser printer. The % character is used to precede remarks in PostScript code, the equivalent of the REM statement in BASIC. GEOS doesn't include remarks in any of their PostScript output. I've added them to make the listings easier to read.
When the last line of the picture has been drawn,
showpage
paints the picture on a sheet of paper and pushes it out of the printer. That's all there is to it!
Now a partial look at the output from geoLaser:
72 75 div dup scale
Scales the final output in the same way that the geoPaint file above was scaled. The word dup takes the top value and duplicates it. 72 divided by 75 equals .96. Since the scale command requires two values, dup makes a second copy of the value .96.
Next, several variables are defined, followed by the definition of PS, a very complex procedure for printing text. This definition is more than 4 pages long (and that's without comments!). PS takes care of all the grunt work of positioning and printing text and graphics.
Here's the definition of the table used to hold the font names. These are the names used in PostScript to represent the fonts and font styles. The GEOS equivalents are LW_Roma for Times-Roman, LW_Cal for Helvetica, LW_Greek for Symbol, and LW_ Barrows for Courier. Also, Oblique is the same as italic in GEOS.
/fonts
[/Times-Roman/Times-Bold/Times-Italic
/Times-BoldItalic/Helvetica/Helvetica-Bold
/Helvetica-Oblique/Helvetica-BoldOblique
/Times-Roman/Times-Bold/Times-Italic
/Times-BoldItalic/Helvetica/Helvetica-Bold
/Helvetica-Oblique/Helvetica-BoldOblique
/Symbol/Symbol/Symbol/Symbol/Courier
/Courier-Bold/Courier-Oblique
/Courier-BoldOblique
] def
Now we'll examine how the text portion is constructed.
2314 0 (Here's the missing
link . . .) 1 0 346 100 33 PS
2392 0 (Randy's geoDisk) 1 0 210 199
68 PS
These two lines of text are printed by the PS procedure. Notice that strings in PostScript are enclosed by parentheses. The PS procedure takes 7 numbers and a string and figures out where to print the string and which fonts and styles to use.
The last two lines of the program,
copypage
erasepage
take care of getting the output on the page and out of the printer. The copypage command prints a page. The erasepage command is equivalent to the BASIC NEW command. It clears the laser printer's memory.
Printing PostScript Programs
Now that you've captured and modified a PostScript program, you'll also need to send it to the laser printer in order to print it. If you're using a C=64 or 128, the same RS-232 hookup is used as you would when printing from geoLaser. Use your terminal program with the same parameters listed earlier in this article for receiving a file from geoLaser.
Load the PostScript program into the terminal program's buffer. Now simply transmit the buffer to the laser printer. Some terminal software offers ASCII or Block transmission protocol. Both ASCII and Block are the transmission of text files directly from the disk. If your software includes this feature, give it a try. It's the way I do most of my work. I've found it to be much easier than first loading the buffer.
Yet another method of getting your PostScript programs printed involves connecting a modem to the laser printer. See last month's article for some handy hints on using a modem with a laser printer.
If you've uploaded your program to another computer with access to a laser printer, keep in mind that the procedure for connecting and printing will be similar to hooking up the C=. If in doubt, look it up in the manual.
I you are attempting to print from a computer on a networked system (that is, the laser printer and computers are all connected together), you might be able to get away with a command as simple as: print filename, or lpr filename. You might have to ask the system operator if that doesn't work. If you get a printed listing of your PostScript program instead of the intended output the program is supposed to produce, then you'll have to add the line: %!postscript to the beginning of your PostScript file. Omitting the line will result in a PostScript program listing being printed.
That's all for now. Try some the examples in this article. Experiment with the PostScript program by modifying the values for scale and translate. As practice, take a PostScript program output from a full-page-sized GEOS document, scale it to one-quarter size, and print it on the four corners of a single page. All of the commands necessary to do it have been discussed in this article. I'll give the solution next month along with more unusual tricks you can accomplish by modifying PostScript programs.
I enjoy your mail. If you have any questions or comments, please write.
Randy Winchester
P.O.
Box 426074
Cambridge, MA 02142