home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vwinprdc.cpp < prev    next >
C/C++ Source or Header  |  1999-02-24  |  6KB  |  156 lines

  1. //===============================================================
  2. // vWinPrinterC - a basic canvas for drawing
  3. //
  4. // Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11.  
  12. #include <v/vos2.h>           // for OS/2 stuff
  13. #include <math.h>
  14.  
  15. #include <v/vwinprdc.h>
  16. #include <v/vapp.h>             // need access to the app
  17. //-----------------------------------------------------------------------
  18. //================>>> vWinPrinterDC::vWinPrinterDC <<<========================
  19.   vWinPrinterDC::vWinPrinterDC(const int scalePrinting) : vWinDC()
  20.   {
  21.     SysDebug(Constructor,"vWinPrinterDC::vWinPrinterDC() constructor\n")
  22.  
  23.     // _isPrinterDC is < 0 if we are scaling. For scaled printing, fonts
  24.     // get treated differently. If we aren't scaling, then we use the old
  25.     // default mode, which lets the GDI handle scaling. This is kind of
  26.     // messy, but it seemed the easiest way to patch things given that
  27.     // _isPrinterDC is really used by vWinDC.
  28.  
  29.     _isPrinterDC = scalePrinting ? -1 : 1;
  30.     _scalePrinting = scalePrinting;
  31.   }
  32.  
  33. //================>>> vWinPrinterDC::~vWinPrinterDC <<<========================
  34.   vWinPrinterDC::~vWinPrinterDC()
  35.   {
  36.     SysDebug(Destructor,"vWinPrinterDC::~vWinPrinterDC() destructor\n")
  37.   }
  38. //================>>> vWinPrinterDC::SetBackground <<<==========================
  39.   void vWinPrinterDC::SetBackground(VCONST vColor& color)
  40.   {
  41.     _canvasBG = color.pixel();           // retrieve pixel value
  42.     GpiSetBackColor (_hdc, _canvasBG);
  43.   }
  44. //======================>>> vWinPrinterDC::SetFont <<<===========================
  45.   void vWinPrinterDC::SetFont(VCONST vFont& vf)
  46.   {
  47.     // Change the font associated with this window.
  48.     _font = vf;
  49.   }
  50. //================>>> vWinPrinterDC::BeginPrinting <<<========================
  51. // returns 0 if problem
  52.   int vWinPrinterDC::BeginPrinting()
  53.   {
  54.     // after the printer is chosen and printing is about to start
  55.     // we create the print PS
  56.  
  57.     // We will support two modes of printing - default and scaled (raw).
  58.     // In scaled (raw), it is up to the user to find the page size and scale
  59.     // things accordingly to make them fit.
  60.  
  61.     // The default mode produces output that closely matches the postscript
  62.     // printer output, but forces the printer resolution to 72 dpi, which
  63.     // may be inappropriate for bitmaps which will come out scaled and chunky
  64.     // looking. The scaled (raw) mode, will use the printer native resolution
  65.     // so that bitmaps that look good on the screen will be very tiny on
  66.     // the printed page compared to the width of the page.
  67.  
  68.     // if a PS already exists for this printer, it will be destroyed and
  69.     // re-created with the latest printer setup info
  70.  
  71.     // _scalePrinting controls the resolution of the resulting PS
  72.     //   0->  default mode (printer resolution artifically set to 72 dpi to match screen)
  73.     //   1 ->  raw mode (native printer resolution usually 300-600 dpi)
  74.  
  75.     _hdc = _printer.CreateHDC(_scalePrinting);   // set the _hdc in the printer canvas
  76.  
  77.     if (!_hdc)             // should not happen...
  78.     {
  79.       ERRORID err;
  80.       err = WinGetLastError(theApp->AppHab());
  81.       SysDebug1(Build,"vWinPrinter::BeginPrinting() failed to create _hdc (err=%x)\n",
  82.     err)
  83.       return 0;
  84.     }
  85.  
  86.     // We set the scaling of the printer canvas to give us either
  87.     // 72 dpi (default) or native printer (scaled).
  88.     SetOS2Map(_printer.GetHeight(_scalePrinting), _printer.GetScale(_scalePrinting));
  89.  
  90.     _pages = 0;
  91.  
  92.     BeginPage();
  93.     return 1;
  94.   }
  95.  
  96. //================>>> vWinPrinterDC::BeginPage <<<========================
  97.   void vWinPrinterDC::BeginPage()
  98.   {
  99.     if (!_printer.GetHDC())             // should not happen...
  100.     {
  101.       return;
  102.     }
  103.  
  104.     ++_pages;           // bump number of pages so far
  105.  
  106.     // we send a NEWFRAME command if this is not the first page
  107.     // to eject the previous page
  108.     if (_pages != 1)
  109.     {
  110.       _printer.NewFrame();
  111.  
  112. //      DevEscape (_printer.GetHDevC(), DEVESC_NEWFRAME, strlen(_printer.GetDocName()),
  113. //      _printer.GetDocName(), NULL, NULL);
  114.     }
  115.  
  116.     SysDebug(Build,"vWinPrinterDC::BeginPage()  beginning new page \n")
  117.   }
  118.  
  119. //================>>> vWinPrinterDC::EndPage <<<========================
  120.   void vWinPrinterDC::EndPage()
  121.   {
  122.     // this is a NO-OP for OS/2
  123.   }
  124. //================>>> vWinPrinterDC::EndPrinting <<<========================
  125.   void vWinPrinterDC::EndPrinting()
  126.   {
  127.  
  128.     if (!_printer.GetHDC())
  129.     return;
  130.  
  131.     _jobID = _printer.EndDoc();
  132. /*
  133.     // signal end of printjob and get job id
  134.     LONG SizeJobID = sizeof(_jobID);
  135.     DevEscape(_printer.GetHDevC(), DEVESC_ENDDOC, 0, NULL,
  136.       SizeJobID, (PVBYTE) &_jobID);
  137.     // after print is complete free-up the print PS
  138.     _printer.DestroyHDC();
  139. */
  140.     SysDebug1(Build,"vWinPrinterDC::EndPrinting() Job ID is %hu \n", _jobID)
  141.   }
  142.  
  143. //=====================>>> vWinPrinterDC::SetPrinter <<<============================
  144.  void vWinPrinterDC::SetPrinter(vPrinter& printer)
  145.   {
  146.     _printer = printer;
  147.  
  148.     // according to the docs, these are in 1/72 inch units (ie. 72 dpi)
  149.     // for regular print and native printer dpi if _scalePrinting is set
  150.     _physHeight = _printer.GetHeight(_scalePrinting);
  151.     _physWidth = _printer.GetWidth(_scalePrinting);
  152.   }
  153.  
  154.  
  155.  
  156.