Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » DrawWin32.cpp: PrintDraw::InitPrinter()
Re: DrawWin32.cpp: PrintDraw::InitPrinter() [message #19287 is a reply to message #19253] |
Mon, 24 November 2008 12:41   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
I'm testing this on Windows XP. Luckily the Epson Stylus Photo 1290 driver has a preview option in XP and it does not even require the printer to exist to be able to install the driver and use its preview option.
There are two separate problems:
1) Only about 60% of width and about 60% of height of the printable area is covered by the printout.
2) The DrawImage(rect,image) produces a broken image probably due to the resolution mismatch (360x360 versus 600x600). It does not get correctly re-scaled from 600 dpi to 360 dpi in the GDI or the printer driver.
Please see the attached files broken.png and fixed.png.
Current code:
::SetMapMode(handle, MM_ANISOTROPIC);
::SetViewportExtEx(handle, inchPixels.cx, inchPixels.cy, NULL);
::SetViewportOrgEx(handle, 0, 0, NULL);
::SetWindowExtEx(handle, 600, 600 , NULL);
::SetWindowOrgEx(handle, 0, 0, NULL);
Result with current code:

My slightly enhanced solution looks like this:
::SetMapMode(handle, MM_ANISOTROPIC);
int dpi=min(inchPixels.cx,inchPixels.cy);
::SetWindowExtEx(handle, dpi*pagePixels.cx/inchPixels.cx, dpi*pagePixels.cy/inchPixels.cy, NULL);
::SetWindowOrgEx(handle, 0, 0, NULL);
::SetViewportExtEx(handle, pagePixels.cx, pagePixels.cy, NULL);
::SetViewportOrgEx(handle, 0, 0, NULL);
pagePixels.cx=dpi*pagePixels.cx/inchPixels.cx;
pagePixels.cy=dpi*pagePixels.cy/inchPixels.cy;
inchPixels.cx=dpi;
inchPixels.cy=dpi;
The result after the above changes:

With the above change, it works with the standard DrawImage.
Just an opinion, but I think the best printing quality can be obtained using the printer's hardware resolution (and optionally dropping it with integer dividers if it is excessively high). For correct page size and scaling I always use Draw::GetPagePixels() and Draw::GetPixelsPerInch() to get the map scale right on both screen and printer.
(This is irrelevant for the current issue at hand, but since it popped up: The SetDIBitsToDevice() uses hardware resolution and does not respect these Viewport/Window mappings except maybe for the starting point. StretchDIBits(), however, does work with the mappings and is also pretty economic way to put low resolution images to high resolution printers, as it does not necessarily pre-rescale the image to the printer resolution before sending it to the printer.)
// Tom
-
Attachment: broken.png
(Size: 104.54KB, Downloaded 1109 times)
-
Attachment: fixed.png
(Size: 92.33KB, Downloaded 1078 times)
|
|
|
Goto Forum:
Current Time: Tue May 13 01:36:33 CEST 2025
Total time taken to generate the page: 0.00457 seconds
|