Re: [Win32Lib] stretchBlt a virtual window to Printer?

new topic     » goto parent     » topic index » view thread      » older message » newer message
AndyDrummond said...

Dan,

I wrote a module a while back to print lines and boxes and you-name-it. The point is that it gets the printer parameters and uses them to allow me to print in absolute units (mm, cm, inches) without worrying about the printer characteristics. The module is called GrPrint.ew in the contribs, and may well contain some of the information you need. I have done a few additions since then but th eone in contribs contains what you are after. As far as stretchBlt() is concerned, that is fine as long as you know how many pixels to the inch in x & y directions. At least, it is fine from a pixmap and I assume the screen can count as that. I used it to print to a PDF but it failed, so I now stretchBlt to a pixmap and the print that to PDF. Hope this is of some use...

Andy

Andy,

I'll take a look at your GrPrint.ew (it's possible I already have it somewhere, too), but as far as I can see right now, stretchBlt has worked FINE, without apparently needing to know pixels per inch etc. One thing I had to do to make it work was to be careful exactly where I put my call to the print routine, as it apparently needed the VirtScrn to be fully drawn, which makes sense, but what didn't make too much sense (but worked), was to put my call AFTER and NOT before some SCROLL bar adjustment statements. Somehow that's what made sure VirtScrn was finished, I guess/think. Weird.

Here's approx. what I did, much/most lifted from one demo or another:

function InitPrinter() 
    sequence lRect 
    sequence lPrinterDef 
    atom lAspectX 
    atom lAspectY 
    atom lResX 
    atom lResY 
 
 
    lPrinterDef =  
        getPrintChoice(1, w32or_all({PD_NOSELECTION,PD_NOPAGENUMS}), 0) 
    if length(lPrinterDef) = 0 then 
        return {} 
    end if 
 
    lAspectX = w32Func(xGetDeviceCaps, {lPrinterDef[4], HORZSIZE}) 
    lAspectY = w32Func(xGetDeviceCaps, {lPrinterDef[4], VERTSIZE}) 
    lResX = w32Func(xGetDeviceCaps, {lPrinterDef[4], HORZRES}) 
    lResY = w32Func(xGetDeviceCaps, {lPrinterDef[4], VERTRES}) 
    lRect = getClientRect(Printer) -- gets size of printer 
 
	return {lRect, lAspectX, lAspectY, lResX, lResY} 
end function 
 
 
---------------------------------------------------------------------- 
procedure PrintVirtScrn() -- this should take the VirtScrn & print it? 
 sequence result 
 sequence printerInfo 
 sequence virtSize 
 
 
   printerInfo = InitPrinter()   
   --{lRect, lAspectX, lAspectY, lResX, lResY} 
   if length(printerInfo) = 0 then 
      return 
   end if 
 
   virtSize = getClientRect(VirtScrn) 
 
--PRINTER STUFF (printerInfo[1]) 
--{ left, top, width, height, bottom, right } 
--{0,0,2976,3876,2975,3875} 
 
  -- start a new document 
     VOID = startDoc( "This is the Document title, in TitleBar") 
 
 
  -- start a new page 
     VOID = startPage() 
 
------************************************** 
--yPosAfterEACHbox -- need to use this to make new page(s) when necessary 
-- probably need a loop, a test for if too long to fit page, and an EXIT 
------************************************** 
 
 
--stretchBlt ( dst, dstX, dstY, dstWide, dstHigh, 
--             src, srcX, srcY, srcWide, srcHigh, rop ) 
 
--  dst: Image destination             Printer 
-- dstX: X position in destination     1 
-- dstY: Y position in destination     1 
-- dstWide: Width of resulting image   printerInfo[1][3] 
-- dstHigh: Height of resulting image  printerInfo[1][4] 
-- src: Image source                      VirtScrn 
-- srcX: X position in source             1 
-- srcY: Y position in source             1 
-- srcWide: Width of image to copy        virtSize[3] 
-- srcHigh: Height of image to copy       virtSize[4] 
-- rop: Raster opeartion (ROP) code to apply  SrcCopy 
--      SrcCopy : dest = source 
 
-- and the following, now, is all it takes to print my virtual screen!   
   stretchBlt ( Printer, 1, 1, printerInfo[1][3], printerInfo[1][4], 
             VirtScrn, 1, 1, virtSize[3], virtSize[4], SrcCopy ) 
 
  -- close the page 
  VOID = endPage() 
 
  -- close the document 
     VOID = endDoc() 
 
  -- release the printer 
  releasePrinter() 
end procedure 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu