VPrintDC

A printer drawing canvas.

Synopsis

 * Header:
 * 


 * Class name:
 * vPrintDC

Description
This drawing canvas can be used to draw to a printer. Like all drawing canvases, the available methods are described in [vdc.htm vDC]. A very effective technique for combining a printer DC and a screen DC is to pass a pointer to either a vCanvasPaneDC or a vPrintDC to the code that draws the screen. The same code can then be used to draw or print.

To successfully use a vPrintDC, your code must obtain the physical size of the page in units using GetPhysWidth and GetPhysHeight. On paper, these represent 1/72 inch points, and correspond very closely, but not exactly, to a pixel on the screen.

You must bracket the printing with calls to BeginPrinting</tt> and EndPrinting</tt>. Use BeginPage</tt> and EndPage</tt> to control paging. Note that the width of text will not necessarily be the same on a vCanvasPaneDC</tt> and a vPrintDC</tt>, even for the same fonts. Also, the size of the paper represents the entire page. Most printers cannot actually print all the way to the edges of the paper, so you will usually use vDC:SetTranslate</tt> to leave some margins. (Don't forget to account for margins when you calculate what can fit on a page.)

The implementation of vPrintDC</tt> is somewhat platform dependent. For X, vPrintDC</tt> represents a PostScript printer, and is derived from the class vPSPrintDC</tt>. For Windows, vPrintDC</tt> is derived from the vWinPrintDC</tt> class. To get platform independent operation for your application, use vPrintDC</tt>. On Windows, you can also use the PostScript version directly if you want by using the vPSPrintDC</tt> class, but the program will not conform to standard Windows behavior.

void SetPrinter(vPrinter& printer)
This method is used to associate a vPrinter</tt> with a vPrintDC</tt>. By default, a vPrintDC</tt> represents standard 8.5x11 inch Letter paper printed in black and white in portrait orientation. You can use <tt>vPrinter::Setup</tt> to allow the user to change the attributes of the printer, then use <tt>SetPrinter</tt> to associate those attributes with the <tt>vPrintDC</tt>. Note: If you change the default printer attributes, you must call <tt>SetPrinter</tt> before doing any drawing to the DC.

Example
This is a simple example taken from the <tt>VDraw</tt> demo program. <tt>Print</tt> is called to print the current drawing. <tt>Print</tt> calls <tt>vPrinter::Setup</tt> to set the printer characteristics, and then calls <tt>DrawShapes</tt> with a pointer to the <tt>vPrintDC</tt>. <tt>DrawShapes</tt> is also called to repaint the screen using the <tt>vCanvasPaneDC</tt>. By carefully planning for both screen and printer drawing, your program can often share drawing code in this fashion. //===================>>> myCanvasPane::Print <<<================= void myCanvasPane::Print {    // Print current picture vPrintDC pdc;              // create a vPrintDC object vPrinter printer;          // and a printer to set attributes printer.Setup("test.ps");  // setup the printer pdc.SetPrinter(printer);   // change to the printer we setup if (!pdc.BeginPrinting)  // call BeginPrinting first return; pdc.SetTranslate(36,36);   // Add 1/2" (36 * 1/72") margins DrawShapes(&pdc);          // Now, call shared drawing method pdc.EndPrinting;         // Finish printing } //===================>>> myCanvasPane::DrawShapes <<<================= void myCanvasPane::DrawShapes(vDC* cp) {    // Common code for drawing both on Screen and Printer ...  }