Printing a Drawing
Printing a Drawing
// Printing a drawing
// This is a very simple demo of how to use the Print Manager to
// print a drawing.
// Assumes inclusion of
#include <PrintTraps.h>
void PrintPicture (PicHandle whichPic, Rect * whichDestRect);
void ToolBoxInit(void);
void ToolBoxInit ()
{
InitGraf (&thePort);
TEInit ();
}
void PrintPicture (PicHandle whichPic, Rect * whichDestRect)
{
GrafPtr savePort;
TPrStatus prStatus;
TPPrPort printPort;
OSErr err;
THPrint hPrint;
GetPort(&savePort);
hPrint = (THPrint) NewHandle(sizeof(TPrint));
PrintDefault(hPrint);
ClipRect (& whichDestRect);
if (PrJobDialog(hPrint)) {
printPort = PrOpenDoc(hPrint, nil, nil);
SetPort(& printPort->gPort);
PrOpenPage( printPort, nil); // Open this page ...
// ---------
DrawPicture( whichPic, whichDestRect); // Or any other drawing
// commands ...
// ---------
PrClosePage( printPort); // Close this page ...
PrCloseDoc( printPort);
// Handle print spooler
if (((*hPrint)->prJob.bJDocLoop = bSpoolLoop) && (!PrError() ) )
PrPicFile(hPrint, nil, nil, nil, &prStatus);
}
SetPort(savePort);
}
void main ()
{
PicHandle myPict;
Rect drawingRect,
scratchRect;
short i;
ToolBoxInit();
SetRect(& drawingRect, 40, 40, 300, 300);
wind = NewWindow (nil, & drawingRect, "\p", TRUE, documentProc,
(WindowPtr) -1, FALSE, 0 );
SetPort (wind);
myPict = OpenPicture(& drawingRect); // 'Open' a picture
// --------- Do your drawing here ...
PenSize(4, 4);
SetRect(&scratchRect, 50, 50, 200, 200);
for (i = 0; i < 10; i++) {
FrameOval(&scratchRect);
InsetRect(&scratchRect, 10, 10);
}
// --------- After your drawing is finished
HidePen(); // So closing the picture will make the pen visible
PrintPicture(myPict, & drawingRect); // This will print our drawing
}