Laser Print DA
Volume Number: 2
Issue Number: 2
Column Tag: C Workshop
Laser Print DA for Postscript
By Mike Schuster, Software Engineer, MacTutor Contributing Editor
Mike Schuster wins $50 for the outstanding program of the month with this
feature article. Congratulations Mike!
Using a POSTSCRIPT Server on AppleTalk
Most Macintosh applications generate printed pages by issuing a sequence of
QuickDraw calls which are intercepted and translated into printer dependent commands
by Apple's Printing Manager. This technique has the advantage that an application
never needs to know what kind of printer the user has connected to the Macintosh. It
also allows the application to write to the screen and the printer with a single device
independent routine. On the other hand, it does not provide the application access to the
extensive page description capabilities nor the wide range of printer resolutions
available in modern electronic printing systems, such as those embodied in Adobe
Systems' POSTSCRIPT page description language, Apple's LaserWriterâ„¢ laser printer
and Linotype's Linotronicâ„¢ 100 typesetter. This is because Quickdraw is much more
limited in it's abilities than is POSTSCRIPT, and hence only a fraction of the capability
of a POSTSCRIPT machine is needed to interpret a set of Quickdraw commands.
In this article, I show how your application may overcome QuickDraw and the
Printing Manager limitations by communicating directly with a POSTSCRIPT server on
an AppleTalk network. In addition, I describe the implementation of Laser Print, a desk
accessory that con currently spools POSTSCRIPT programs you create with MacWrite,
Edit or Just Text, and sends them to the Apple LaserWriter or other POSTSCRIPT
compatibile printer. You can use this printing desk accessory to explore programming
your LaserWriter directly, using an example postscript file in this article. In future
issues of MacTutor, we will expand on postscript programming techniques with a
regular postscript column and this desk accessory will be invaluable as a way of
sending your programs over Appletalk to the LaserWriter. The Laser Print DA is
written in MegaMax C.
Deep Background by The Editor
[When a Macintosh Application prints, the text and graphics that it writes to a
quickdraw port to display on the screen are sent to a special quickdraw port used by the
printing manager. You print text and graphics by drawing into this port with
Quickdraw, just as if you were drawing on the screen. The Printing Manager changes
the pointers to the low-level drawing routines so that Quickdraw calls drive the
printer rather than the screen. In this way, MacWrite can display a what- you- see-
is- what- you- get screen version of your document with one set of routines and it can
go to either the screen or the printer thanks to the clever Printing Manager. The whole
point of the Print Manager and associated device drivers is to convert Macintosh
Quickdraw text and graphic descriptions into page bit maps that can be printed. This
design works very well with the Imagewriter.
Now comes the LaserWriter, after the Macintosh. This device is very different
from anything Apple has ever produced and one can only wonder who was the
mastermind behind it. It is so much more powerful than the Mac itself, one has to
wonder if it was an outside design. In some respects the LaserWriter is a high powered
Macintosh. Substitute POSTSCRIPT for Quickdraw. Substitute 0.5 Meg of ROM for 64K
ROM. Substitute 1.5 Meg of RAM for 128K RAM. Substitute a 12 Mhz 68000 for an 8
Mhz 68000. Connect the two with the Appletalk serial port. The problem for Apple was
how the lowly Macintosh could be made to talk to this very intelligent device with a
minimum of changes to the Mac itself.
The answer was since all Macintosh software writes to the screen (and hence the
printer via the Print Manager) via Quickdraw, those same routines could drive a
LaserWriter by converting Quickdraw descriptions into POSTSCRIPT. The purpose of
the Laser Prep file is to convert quickdraw commands to POSTSCRIPT. The Laser Prep
file is downloaded into the LaserWriter as a POSTSCRIPT application running within
the LaserWriter. Normal Macintosh applications present Quickdraw documents to the
Printing Manager, which invokes the LaserWriter device driver, downloads the Prep
File into the LaserWriter (Initializing Printer...) which in turn converts quickdraw to
POSTSCRIPT, which is interpreted by the built-in POSTSCRIPT interpreter within the
LaserWriter (the 0.5 Meg of ROM) and finally converted to a 300 dot per inch page bit
map (stored in the 1.5 Meg of RAM not taken up by Laser Prep, the POSTSCRIPT page
description, and fonts) and printed! This double conversion is one reason the
LaserWriter takes so long to print initially. It also explains why the LaserWriter often
runs out of memory with some applications like Pagemaker, which uses a larger Prep
file. In fact, the LaserWriter may be even more memory bound than the 512K
Macintosh, if you can believe that! So limited is memory space that the new Laser Fonts
from Adobe will probably require the new LaserWriter II to be useful, which is
supposed to have 2 meg of RAM. A conversion kit is rumored to be available for
upgrading current LaserWriters.
By sending a POSTSCRIPT file directly to the LaserWriter, you avoid having to
down load Laser Prep, eliminate quickdraw to POSTSCRIPT conversion, free up RAM in
the printer, and generally speed everything up. Plus, you avoid limitations of trying to
represent in Quickdraw a much more extensive capability of POSTSCRIPT. Commands
within the POSTSCRIPT file tell the printer that the file is to be interpreted and not
printed. The fact that Aldus Corp. felt the need to write their own Prep File shows the
limitations of trying to go from Quickdraw to POSTSCRIPT. Aldus needed some of the
capabilities of POSTSCRIPT that the Apple Prep file would not supply. The very thin
line in Pagemaker is one such feature that could not be represented without a new Prep
file. This is not a happy situation since now you have two companies supporting two
different prep file conventions. The smoothing algorithm of Apple is an example of how
the user is stuck when two companies support a competing low level routine. The Aldus
Prep file did not support smoothing until they had obtained a license from Apple.
Bill Bates of Knowledge Engineering saw all this conversion nonsense and
recognized that the only way to really tap into the power of the LaserWriter was
directly via POSTSCRIPT. His Just Text and LaserTool products create postscript files
directly in the traditional typesetting method. The advantage of this is POWER. Direct
control over every feature of POSTSCRIPT, with no Laser Prep quickdraw to
POSTSCRIPT conversion hassles to slow things down. This brings up an interesting
confrontation. Aldus follows the Macintosh guidelines using Quickdraw and converting to
POSTSCRIPT. Would it be possible to go the other way and create a program that would
interpret POSTSCRIPT into Quickdraw so that any POSTSCRIPT file could be displayed
on the screen as a 'soft' LaserWriter Preview? We leave to the developer to ponder the
implications of such a program.
POSTSCRIPT EXAMPLE
Figure 1 shows a drawing created on the LaserWriter by the POSTSCRIPT
program listing in figure 2. As you can see, neither MacWrite, Word or Pagemaker
could possibly create an image such as this, and yet for the LaserWriter, this is a snap!
POSTSCRIPT is a programming language very similar to Forth. It uses reverse polish
notation and a stack like Forth does. Arguments are pushed on the stack first, followed
by the command that executes them. This requires the programmer to think backwards
in some respects. Adobe Systems has just published two very good books on
POSTSCRIPT programming. They are a tutorial and a reference manual, both available
in Bookstores from Addison-Wesley. Look for a blue and red book under the title of
POSTSCRIPT. This example is taken from the tutorial book on page 98. The lines
beginning with %% are comments. The first line follows the Adobe specifications of %!
to tell the interpreter within the LaserWriter that what follows are POSTSCRIPT
commands to be executed rather than a bunch of text to be printed. This file can be
executed by typing it in as a text file with Edit or MacWrite and using the Laser Print
DA to down load it to the LaserWriter. After using postscript directly, I can see that
what is now needed is some way that artistic POSTSCRIPT programs can be "placed" in
page makeup programs like Pagemaker so that they can be edited and arranged with
other text and illustrations. Of course Just Text does this, but without the advantage of a
screen display representation of the final output. Well, enough of the introductions to
the world of POSTSCRIPT programming. Let's get on with solving the hole Apple left
us-- a utility to send POSTSCRIPT files directly to the LaserWriter. Our thanks to
Mike for this very important and timely article. -Ed.]
A POSTSCRIPT Server at Work
When connected to an AppleTalk network, the LaserWriter functions as a server
for the execution of POSTSCRIPT programs sent to it by applications running on client
Macintosh workstations. The LaserWriter begins service by listening for an AppleTalk
connection request from a client. It then executes the POSTSCRIPT program sent to it
over that connection. Any error messages or other output produced by the program,
other than the printed pages themselves, are transmitted back to the client over the
same connection. When the LaserWriter receives an end-of-file indication from the
client, it sends a matching end-of-file back to the client and terminates the execution of
the program. After receiving the matching end-of-file indication, the client closes the
connection and frees the server.
While the LaserWriter is busy servicing one connection, it refuses any
additional connection requests. This refusal causes the requesting clients to queue up
and wait for the server to become free. As soon as the current connection closes, the
server accepts the request from the client that has waited the longest period of time.
[This problem shows that a LaserWriter is really of no use to more than one person
without a File Server to manage this queue of documents. Otherwise, everyone on the
network sits around waiting for the printer to free up before he can get on with his
work. Which brings us to the next great hole in the Apple Office-- a file server that
spools files to the LaserWriter, allowing networked Macintosh computers to do
something else after clicking print in the File menu! -Ed]
The communication between the LaserWriter and its client workstations is
accomplished by means of the AppleTalk Printer Access Protocol (PAP). Apple
specified this protocol in its publications Inside LaserWriter, Inside AppleTalk and the
AppleTalk Manager chapter of Inside Macintosh. [See MacTutor, September 1985 for
more on AppleTalk programming. -Ed.]
%!PS-Adobe-1.0
%%Title: Postscript Example
%%DocumentFonts: (atend)
%%Creator: Edit
%%CreationDate: 12/27/85 6:21 PM
%%Pages: (atend)
%%BoundingBox: 0 0 612 792
%%EndComments
%% Document prolog now follows
grestoreall
initgraphics
/pageproc {} def
%%EndProlog
%% Postscript Example Program
%% See page 98 of Postscript Tutorial Manual
%% Procedures now follow
/Times-BoldItalic findfont
36 scalefont setfont
/oshow %stack:(string)
{true charpath stroke} def
/circleofMacTutor
{15 15 345
{gsave
rotate 0 0 moveto
(MacTutor) oshow
grestore
} for
} def
%% Main Program Segment
250 400 translate
.5 setlinewidth
circleofMacTutor
0 0 moveto
(MacTutor Journal) true charpath
gsave 1 setgray fill grestore
stroke showpage
%% End of example program