home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / tech / print_dr.txt < prev    next >
Internet Message Format  |  1985-09-17  |  7KB

  1. Return-Path: <oster%ucblapis.CC@Berkeley>
  2. Received: from UCB-VAX.ARPA by SUMEX-AIM.ARPA with TCP; Mon 16 Sep 85 08:47:46-PDT
  3. 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
  4. 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
  5. Received: by ucblapis.Berkeley.Edu (4.19/4.38.1) id AA01944; Sat, 14 Sep 85 15:44:43 pdt
  6. Date: Sat, 14 Sep 85 15:44:43 pdt
  7. From: oster%ucblapis.CC@Berkeley
  8. Message-Id: <8509142244.AA01944@ucblapis.Berkeley.Edu>
  9. To: info-mac@sumex-aim.ARPA
  10. Subject: Writing Print Managaers on the Macintosh
  11.  
  12. Creating a Macintosh Printer Manager
  13.  
  14. (All of this information was in Inside Mac, but much of it is omitted in
  15. the current version, and unless you've written print managers, the info is
  16. difficult to understand.  Here it is in condensed form.)
  17.  
  18. A Macintosh Print Manager is a file containing 68000 machine language
  19. procedures that are called by application programs.  These procedures are
  20. expected to:
  21.  
  22. 1.)  modify fields in a 120 byte print record that the application looks in
  23. to find the resolution of the printer, the size of the paper, the number of
  24. copies, and the page range to print.
  25.  
  26. 2.  Provide a grafPort for the application to do its drawing on.  This
  27. grafPort has special procedures in its QDProcs field that customize
  28. quickdraw appropriately for the printer.
  29.  
  30. A Macintosh Printer Driver may print bitmaps and/or it may print characters
  31. and do carriage returns and line feeds.  Access to the printer driver is
  32. controlled by the Print Manager, so you can provide what ever capabilities
  33. you want and still use existing application programs.
  34.  
  35. Applications print by 
  36. a.)  Setup the page by calling PrintDefault or PrStylDialog.
  37. b.)  define the job (quality, page range, and no. of copies) by calling
  38.      PrJobDialog
  39. c.)  call PrOpenDoc 
  40. d.)  for each page, "i"
  41. e.)    call PrOpenPage
  42. f.)    do their own code to draw page(i)
  43. g.)    call PrClosePage
  44. h.)  call PrCloseDoc
  45. i.)  if the print manager has told it to, the application calls PrPicFile to
  46.      playback any printer spool file to the printer.
  47.  
  48. Your Print Manager gets control on every one of those Pr... calls.  It can
  49. tell the user (by the dialogs) what capabilities are available, and it can
  50. pick and choose which quickdraw calls to interpret and which not.
  51.  
  52. Examples:  When the Imagewriter is spooling, it just uses the Picture
  53. mechanism of QuickDraw to buffer up a page of QuickDraw calls into a
  54. picture structure that it writes to disk.  When the application is done
  55. drawing data it calls PrPicFile, which as defined in the file ImageWriter,
  56. allocates a bitmap representing a band of the page and calls DrawPicture.
  57. It sends the bitmap to the Printer Driver.  Then it reallocates the bitmap
  58. to represent the next band of the page and calls drawPicture again.  It
  59. repeats this until it has drawn the entire page.
  60.  
  61. When it is not spooling, i.e. when it is in draft mode, the ImageWriter
  62. printer manager overrides most of the QDprocs, and interprets attempts to
  63. draw text by telling the printer driver to move to a particular spot on the
  64. paper and draw the characters in one of the printer's built in fonts.
  65.  
  66. The print manager is where all the work happens.  Very few things call the
  67. print driver directly.  The shift-command-4 screen printing is all I can
  68. think of.
  69.  
  70. Now, writing your own printer manager:
  71.  
  72. The Choose Printer desk accessory looks for files on the startup Disk whose
  73. type is 'PRES', so you should create 'PRES' file to hold your printer code.
  74. Create a file whose type is 'PRES' and whose creator field is some 4
  75. characters of your own, but for compatability with the rest of the
  76. universe, should be a mix of upper and lower case, not contflicting with
  77. anyone else's:  'Dave' for example.  (all entirely lower case names and
  78. many upper case names are alreay in use or reserved by apple)
  79.  
  80. Summary:  A printer manager is a file with:
  81.    Type:  'PRES'
  82. Creator:  up to you:  ('Dave' for example)
  83. containing resources:
  84.  type    id
  85. 'BNDL'   128   - so you manager will have an icon on the desktop
  86. 'ICN#'         - so you manager will have an icon on the desktop
  87. 'FREF'         - so you manager will have an icon on the desktop
  88. 'Dave'         -  (for example) ditto
  89.  
  90. 'DRVR'   $E000 - device manager for this printer
  91. 'PREC'   $E000 - (optional) private storage for this printer
  92. 'PREC'   $0000 - 120 byte default print record for this printer
  93. 'STR '   $E001 - default spool file name (like "Print File")
  94.  
  95. 'DLOG'   $E000 - Page Setup Dialog
  96. 'DITL'   $E000 - Page Setup Dialog Item List
  97. 'DLOG'   $E001 - Job Dialog
  98. 'DITL'   $E001 - Job Dialog Item List
  99.  
  100. Lastly, you will need 6 resources whose contents contain pure 68000 machine
  101. language. These are:
  102.  
  103. 'PDEF'   $0000 - Called to do draft printing
  104. 'PDEF'   $0001 - Called to do spool printing (high and standard quality)
  105. 'PDEF'   $0002 - (Optional) print method A
  106. 'PDEF'   $0003 - (Optional) print method B
  107.  
  108. Each of these 4 resources starts with the following code:
  109.     BRA.W    MyPrOpenDocProc
  110.     BRA.W    MyPrCloseDocProc
  111.     BRA.W    MyPrOpenPageProc
  112.     BRA.W    MyPrClosePagePrc
  113.     ... the actual code
  114.  
  115. This code is used as a jump table to actually dispatch to a particular
  116. procedure.
  117.  
  118. 'PDEF'   $0004 - The dialogs
  119.  
  120. This resource starts with the following code:
  121.     BRA.W    MyPrintDefaultProc
  122.     BRA.W    MyPrStlDialogProc
  123.     BRA.W    MyPrJobDialogProc
  124.     BRA.W    MyPrStlInitProc
  125.     BRA.W    MyPrJobInitProc
  126.     BRA.W    MyPrDlgMainProc
  127.     BRA.W    MyPrValidateProc
  128.     BRA.W    MyPrJobMergeProc
  129.  
  130. 'PDEF'   $0005 - The printer spool file interpreter
  131.  
  132. This resource starts with the code to do MyPrPicFileProc.
  133.  
  134. All of the code obeys the pascal calling conventions:
  135.  
  136. Registers A2-A6, D1-D7 must be preserved, parameters are on the stack,
  137. first parameter farthest from the top of stack, and the called routine must
  138. pop the parameters before it returns.
  139.  
  140. The individual calling sequences of the Pr...procs are given in IM, so I
  141. won't repeat them here.
  142.  
  143. Macintosh applications call the correct one of 'PDEF's 0-3 by looking in
  144. the .bjDocLoop field of the print record.  The print record is set by the
  145. procedures MyPrStlDialog and MyPrJobDialog which the application calls to
  146. present the pageSetup and Printing dialogs, respectively, to the user, So
  147. the writer of the print manager has a lot of flexibility.
  148.  
  149. I hope this inspires somebody to write some new print managers I would like
  150. to see one for the standard imagewriter that calls the standard manager to
  151. do most of the work, but gives me control over the margins.  It would also
  152. be possible to write one manager that drove many different kinds of
  153. plotters and dot matrix printers.
  154.  
  155. -- David Oster
  156.