Classic Computer Magazine Archive COMPUTE! ISSUE 95 / APRIL 1988 / PAGE 50

ST Outlook

Philip I. Nelson

Printing ST Pictures On A Laser Printer

With the current explosion of interest in desktop publishing, more and more laser printers are appearing in offices and even a few homes. Unlike a dot-matrix printer, which forms images by hitting an inked ribbon with wire pins, a laser printer uses the same graphics engine as a photocopier, offering vastly improved print quality. Laser printers are so good, in fact, that many professional publishers use them in place of conventional, and much more expensive, phototypesetting equipment.

This month's program shows how you can combine the ST's superb graphics capabilities with the high resolution of a laser printer. It works with the Apple LaserWriter, one of the most popular laser printers, and it lets you make a full-page printout of any monochrome DEGAS picture. Although it's written in GFA BASIC, the program is so simple that you shouldn't have much difficulty converting it to the language of your choice.

When you run the program, it asks for the name of the file you wish to convert. This must be a DEGAS-format monochrome (.PI3) picture file. Then the program creates a PostScript output file named POSTSCPT.OUT (PostScript is described below). The output file is hefty—over 96,000 bytes—so be sure that your disk has enough room before you begin, and be prepared to wait a few minutes if you're writing to a floppy disk. After POSTSCPT.OUT is created, you can rename it with any valid GEMDOS name.

The Laser Connection

To print the PostScript file, you need to send it to the laser printer. Communicating with a LaserWriter is straightforward, since it's a serial device, just like a modem. And the PostScript file is plain ASCII text, so you can send it to the printer with any telecommunications program that has upload capability.

Few people have a laser printer at home, but there are small-scale publishers popping out of the bushes all over the Western world, many of whom will print anything you like on a per-page basis. You supply the PostScript file and a small fee, and they provide the printout. Or, you might be lucky enough to know someone with a laser printer who doesn't mind making an occasional printout for a friend.

If you can't transmit the PostScript output file directly to a printer, you may need to copy the file to a non-ST disk. Most Apple Laser-Writers are connected to Apple Macintosh or IBM PC/compatible computers. In the latter case, you might be able to take advantage of the fact that an ST disk drive can read and write to 3½-inch disks that are formatted on a PC-compatible system. Another option is to use one of the new PC-compatible 5¼-inch drives that plugs directly into the ST.

Landscape Or Portrait Mode

As listed, the program prints the picture in landscape mode, or sideways on the paper, occupying all but a thin margin on all four sides. If you change 0 to 1 in the first nonremark line, the program prints in portrait, or normal, mode, placing the image upright and centered on the page. Landscape mode gives you a much larger printout, although it slightly alters the picture's proportions to fit it neatly on the page. (The ST's screen proportions don't quite match those of an 8½ × 11 paper.)

Speaking In PostScript

The program takes advantage of the fact that the LaserWriter speaks PostScript, a language built for page description, which is a fancy term for the business of putting words and images on paper. PostScript has much in common with other computer languages: It allows you to create loops, execute subprocedures, perform math, manipulate data structures like strings and arrays, and so on. But while most computer languages are general-purpose in nature, PostScript has a single, albeit complex, purpose: telling a high-resolution output device how to print a document. Thus, it has a wealth of special graphics- and typography-related functions in addition to the generic features that every language needs.

PostScript is a stack-oriented language similar to Forth or the languages used by some high-powered scientific calculators. If you're not familiar with Forth, the simplest way to describe its syntax is "backward." To explain, compare the BASIC statement PRINT 2 + 2 with the English statement "Put the hat on your head." In both cases the verb (or keyword, in BASIC) is followed by the objects (arguments) that it acts upon.

Backward Is Faster

PostScript, like Forth, reverses the familiar verb-object order of English. First come the objects, followed by the PostScript operator, or keyword, that tells what to do with them. Instead of "add 2 plus 2" (English) or PRINT 2 + 2 (BASIC), you have "2 2 add" (PostScript). In each case the result is 4, although the last form may take some getting used to.

The reward for tolerating this peculiar syntax is speed. Stack-oriented languages are easy for a computer to interpret, and hence they're very fast. Speed is essential for a printer, which most of us treat as a magical black box rather than a computer-based device that has to read and interpret a program just to print a document.

The PostScript Program

Although the output file is large, the PostScript program itself is very brief. Here's a view of the entire program:

< ... > def
20 600 translate
640 400 scale
640 400 1 [640 0 0 -400 0 0]{Bitmap} image

The first two program lines define a string named Bitmap. In place of the three dots, the real program would contain 32,000 hexadecimal numbers that represent the 32,000 picture bytes in a DEGAS file. This immense string gives the program the raw data that it needs to recreate the picture.

The third line tells the printer to move to position (20, 600) before forming an image, while the fourth tells it to scale the image up, using the same 640 × 400 proportions as the original ST screen.

The fifth program line actually creates the image. The first three numbers indicate that our image is a 640 × 400 bitmap in which each bit represents one dot. The array in square brackets makes up a transform matrix that maps our image into the PostScript coordinate system. Inside the curly braces is the name of the string that holds our bitmap data. The line ends with the image operator that acts upon all the preceding information.

The last line of the program consists of a showpage operator, which makes the printer print the page that the preceding statements describe. This version of the program prints in portrait mode. To switch to landscape mode, we start printing at the normal origin (position (0, 0), the lower-left corner of the upright page) and then rotate the image 90 degrees and scale it to fill most of the page.

If this example whets your interest in PostScript, try to get your hands on the PostScript Language Tutorial and Cookbook, written by Adobe Systems (the inventors of PostScript) and published by Addison-Wesley. It's chock-full of examples and does a good job of teaching a computer language at the elementary level without condescension. If you get serious about PostScript, the same publisher offers The PostScript Language Reference Manual, a comprehensive reference to the language.

PostScript Printer

For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" elsewhere in this issue.