PrOpenDoc
PrOpenDoc
Initialize a GrafPort before printing a document Ptr pIOBuf ; address of an I/O buffer; 0=allocate one returns address of a TPrPort (a printing grafPort) PrOpenDoc initializes a printing grafPort to be used in subsequent Print Manager calls and makes it the active grafPort.
hPrtRec is a handle leading to a 120-byte TPrint structure. This should be a valid printing record containing information set via PrStlDialog, and PrJobDialog. Fields in the record are used in setting up the grafPort and in deciding whether print spooling will be used.
pPrPort is the address of a 178-byte TPrPort record (whose first 108 bytes are a GrafPort). If pPrPort = 0, then the Printing Manager automatically allocates such a structure as a nonrelocatable object on
the heap.
pIOBuf is the address of a 522-byte buffer to be used for I/O operations. If
pIOBuf = 0, then the volume buffer of the volume containing the
spool file is used (by default, the buffer of the current volume).
Returns: a TPrPort; the address of the printing grafPort to be used. If pPrPort was non-zero on entry, that same address is returned.
Notes: Normal usage is to use NIL for both pPrPort and pIOBuf; e.g.:
If you allocate the TPrPort yourself (e.g., to avoid fragmenting the heap), don't waste time pre-setting any of its fields. It is completely initialized by
The bJDocLoop field of the TPrint record determines whether printing will be streamed to the printer or spooled to disk. This field is set by the Print
Manager dialogs and should NOT be changed by the caller.
The print record's prJob.pIdleProc is cleared to NIL by this call, so if you
want to perform any background task while printing (such as displaying the
current page number), you must set pIdleProc after calling both
The following example assumes a valid TPrint record. Notice the call to PrPicFile at the end of the example. You must use similar code to be able to handle the common operation of spooled print files.
Example
#include <PrintTraps.h>
short pgCnt, pgNum;
/* let system allocate port and IO buf */
pgCnt = MyPaginateDoc( ); [TOKEN:12074] user code to set page breaks */
(*hPrtRec)->prJob.pIdleProc=MyIdleProc; /* install bkgnd task ( optional)*/
for (pgNum = 1; pgNum < pgCnt; pgNum++ ) { /* print all pages */
if ( PrError() ) { /* ...process the error... */} MyDrawPage( pgNum ); /* use Quickdraw commands to draw */
if ( PrError() ) {/* ...process the error... */} /* check for error */ }
if ( (*hPrtRec)->prJob.bJDocLoop == bSpoolLoop ) {
MyMakeSomeRoom(); /* free up as much RAM as possible */
if ( PrError() ) {/* ...process the error... */} }