Return-Path: Received: from UCB-VAX.ARPA by SUMEX-AIM.ARPA with TCP; Mon 16 Sep 85 08:47:46-PDT Received: from ucbjade.Berkeley.Edu (ucbjade.ARPA) by UCB-VAX.ARPA (4.24/5.3) id AA24163; Sat, 14 Sep 85 15:41:19 pdt Received: from ucblapis.Berkeley.Edu (ucblapis.ARPA) by ucbjade.Berkeley.Edu (4.19/4.38.2) id AA03229; Sat, 14 Sep 85 15:44:36 pdt Received: by ucblapis.Berkeley.Edu (4.19/4.38.1) id AA01944; Sat, 14 Sep 85 15:44:43 pdt Date: Sat, 14 Sep 85 15:44:43 pdt From: oster%ucblapis.CC@Berkeley Message-Id: <8509142244.AA01944@ucblapis.Berkeley.Edu> To: info-mac@sumex-aim.ARPA Subject: Writing Print Managaers on the Macintosh Creating a Macintosh Printer Manager (All of this information was in Inside Mac, but much of it is omitted in the current version, and unless you've written print managers, the info is difficult to understand. Here it is in condensed form.) A Macintosh Print Manager is a file containing 68000 machine language procedures that are called by application programs. These procedures are expected to: 1.) modify fields in a 120 byte print record that the application looks in to find the resolution of the printer, the size of the paper, the number of copies, and the page range to print. 2. Provide a grafPort for the application to do its drawing on. This grafPort has special procedures in its QDProcs field that customize quickdraw appropriately for the printer. A Macintosh Printer Driver may print bitmaps and/or it may print characters and do carriage returns and line feeds. Access to the printer driver is controlled by the Print Manager, so you can provide what ever capabilities you want and still use existing application programs. Applications print by a.) Setup the page by calling PrintDefault or PrStylDialog. b.) define the job (quality, page range, and no. of copies) by calling PrJobDialog c.) call PrOpenDoc d.) for each page, "i" e.) call PrOpenPage f.) do their own code to draw page(i) g.) call PrClosePage h.) call PrCloseDoc i.) if the print manager has told it to, the application calls PrPicFile to playback any printer spool file to the printer. Your Print Manager gets control on every one of those Pr... calls. It can tell the user (by the dialogs) what capabilities are available, and it can pick and choose which quickdraw calls to interpret and which not. Examples: When the Imagewriter is spooling, it just uses the Picture mechanism of QuickDraw to buffer up a page of QuickDraw calls into a picture structure that it writes to disk. When the application is done drawing data it calls PrPicFile, which as defined in the file ImageWriter, allocates a bitmap representing a band of the page and calls DrawPicture. It sends the bitmap to the Printer Driver. Then it reallocates the bitmap to represent the next band of the page and calls drawPicture again. It repeats this until it has drawn the entire page. When it is not spooling, i.e. when it is in draft mode, the ImageWriter printer manager overrides most of the QDprocs, and interprets attempts to draw text by telling the printer driver to move to a particular spot on the paper and draw the characters in one of the printer's built in fonts. The print manager is where all the work happens. Very few things call the print driver directly. The shift-command-4 screen printing is all I can think of. Now, writing your own printer manager: The Choose Printer desk accessory looks for files on the startup Disk whose type is 'PRES', so you should create 'PRES' file to hold your printer code. Create a file whose type is 'PRES' and whose creator field is some 4 characters of your own, but for compatability with the rest of the universe, should be a mix of upper and lower case, not contflicting with anyone else's: 'Dave' for example. (all entirely lower case names and many upper case names are alreay in use or reserved by apple) Summary: A printer manager is a file with: Type: 'PRES' Creator: up to you: ('Dave' for example) containing resources: type id 'BNDL' 128 - so you manager will have an icon on the desktop 'ICN#' - so you manager will have an icon on the desktop 'FREF' - so you manager will have an icon on the desktop 'Dave' - (for example) ditto 'DRVR' $E000 - device manager for this printer 'PREC' $E000 - (optional) private storage for this printer 'PREC' $0000 - 120 byte default print record for this printer 'STR ' $E001 - default spool file name (like "Print File") 'DLOG' $E000 - Page Setup Dialog 'DITL' $E000 - Page Setup Dialog Item List 'DLOG' $E001 - Job Dialog 'DITL' $E001 - Job Dialog Item List Lastly, you will need 6 resources whose contents contain pure 68000 machine language. These are: 'PDEF' $0000 - Called to do draft printing 'PDEF' $0001 - Called to do spool printing (high and standard quality) 'PDEF' $0002 - (Optional) print method A 'PDEF' $0003 - (Optional) print method B Each of these 4 resources starts with the following code: BRA.W MyPrOpenDocProc BRA.W MyPrCloseDocProc BRA.W MyPrOpenPageProc BRA.W MyPrClosePagePrc ... the actual code This code is used as a jump table to actually dispatch to a particular procedure. 'PDEF' $0004 - The dialogs This resource starts with the following code: BRA.W MyPrintDefaultProc BRA.W MyPrStlDialogProc BRA.W MyPrJobDialogProc BRA.W MyPrStlInitProc BRA.W MyPrJobInitProc BRA.W MyPrDlgMainProc BRA.W MyPrValidateProc BRA.W MyPrJobMergeProc 'PDEF' $0005 - The printer spool file interpreter This resource starts with the code to do MyPrPicFileProc. All of the code obeys the pascal calling conventions: Registers A2-A6, D1-D7 must be preserved, parameters are on the stack, first parameter farthest from the top of stack, and the called routine must pop the parameters before it returns. The individual calling sequences of the Pr...procs are given in IM, so I won't repeat them here. Macintosh applications call the correct one of 'PDEF's 0-3 by looking in the .bjDocLoop field of the print record. The print record is set by the procedures MyPrStlDialog and MyPrJobDialog which the application calls to present the pageSetup and Printing dialogs, respectively, to the user, So the writer of the print manager has a lot of flexibility. I hope this inspires somebody to write some new print managers I would like to see one for the standard imagewriter that calls the standard manager to do most of the work, but gives me control over the margins. It would also be possible to write one manager that drove many different kinds of plotters and dot matrix printers. -- David Oster