October 90 - DRIVING TO PRINT: AN APPLE II GS PRINTER DRIVER
DRIVING TO PRINT: AN APPLE II GS PRINTER DRIVER
MATT DEATHERAGE
Do you have a printer that would print awesome text and graphics if only someone
would write a driver for it? Have you looked at the driver specifications and become
hopelessly confused? If you want to give your Apple II GS some expanded printing
capabilities, don't put this issue down until you've read this article!
In theory, printer drivers seem like a great solution. All you have to do is drop a
printer driver file in your Drivers folder, and all of a sudden you'll be able to create
dazzling text and graphics from whatever desktop application and on whatever kind of
printer you happen to use with your Apple IIGS. No more writing to printer
manufacturers or waiting for application upgrades to support your printer.
Unfortunately, the reality isn't quite as nifty as the theory. Even though Apple released
printer driver specifications in early 1988 (just before System Disk 3.2), only a
few third-party printer drivers have surfaced. The specifications are complex and
sometimes confusing, and they have not always been accurate. Most of all, printer
drivers are intrinsically complicated and difficult to develop. The driver has to do all
of the work in getting images printed, with no imaging help from the Print Manager.
This article explains the mysteries of the printer driver: what it does, how it does it,
and how to write one. To illustrate the concepts, we've provided a sample printer
driver called Picter. Picter takes the image to be printed and saves it to your boot disk
as a QuickDraw II picture file. Picter allows you to literally print a graphic document
to disk. Much of Picter's structure and code is directly applicable to any printer
driver. What's more, the dialog routines in Picter, which are very similar to those in
the new ImageWriter and ImageWriter LQ drivers released with System Software
5.0.3, will enable you to be consistent and stylish in your user interface. You will find
Picter in the IIgs Printer Driver folder on the Developer Essentials disc.
HOW PRINTING WORKS
Printing from a desktop application appears to be a black box. You make some Print
Manager calls and voila!-- there's a piece of paper with a printed image of what you
drew. The Print Manager uses some serious magic to turn your image into ink on
paper, but that's all hidden from the application.
So now that we know what we're getting into, let's briefly review how applications
print through the Print Manager.
WHAT THE APPLICATION SEES
In the Apple IIGS desktop environment, documents are kept in windows, which are
extended versions of the QuickDraw II drawing environment--the Grafport. The
features defined by theGrafport include where drawing will and will not occur, what
size pen will be used to draw lines and other objects, what method will be used to draw
them, what colors and patterns will be used with the objects drawn, what style, size,
font, and colors will be used for text drawing, and where the image resides in memory.
The model for printing is quite similar to drawing in a window. Instead of drawing into
a windowGrafport, your application draws into aprinting Grafport, which defines
the drawing environment for a single page. The clipping and visible regions
(theclipRgn and visRgn) are set to the rectangular area of the page, for example.
An application prints by drawing into a printingGrafport, which it obtains by opening
a printing document with the Print Manager callPrOpenDoc. The Print Manager
responds by returning a printingGrafport in which the material to be printed should
be drawn. The printingGrafportis initialized at the beginning of each new page
(signified byPrOpenPage). The application then draws the page, closes it
(withPrClosePage), and repeats this sequence until all pages have been printed. The
application then closes the document (withPrCloseDoc) and prints any images the
driver may have spooled withPrPicFile. The sequence of calls starting
withPrOpenDoc and ending withPrPicFile is referred to as theprint loop , since the
middle calls (PrOpenPage andPrClosePage) are repeated once for each page to be
printed. Note thatPrPicFile should always end the print loop.
HOW IT REALLY WORKS
If the Print Manager does all this for the application, as the Apple IIGS Toolbox