Click here to Skip to main content
15,924,507 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I'm using the MFC document/view architecture.

My draw code for the View appears fine, but when I look at it in Print Preview or Print it, everything is scrunched up in a smaller rectangle in the upper left corner except for the text drawing. Only a portion of the text is drawn though, just the part within the smaller rectangle.

Do I need to do something in OnPreparePrinting()?

Update:


I changed the view draw function to use the pDC instead of the memory DC (memory DC bitmap was to avoid flicker for screen drawing) in case of printing or print preview with pDC()->IsPrinting(). Now at least all of the text is drawing correctly but all of the line drawing is not.

I'm using MM_TEXT and LOGPIXELSX and Y to convert to device pixels. I'm going to try out MM_ISOTROPIC in the draw code for objects that draw lines and see if that works or look for something fishy.

Update 2


The answer was that MM_TEXT should work just fine. I just needed to call my re-pagination code with the printer DC and that ended up in View::OnDraw where I check to see if the dc is a printer dc.

My user settings are in inches (object layer) and the GUI layer uses pixels and the pagination works for any device because the function that converts from inches to pixels uses pDC->GetDeviceCaps( LOGPIXELSX ) for both X and Y.

I wonder if anyone would validate this approach or mention something better. Could one just use the view DC and use a DIB and StretchBlt() to the printer dc? If it does work would one lose printing quality? I mean it seems that I have to convert from inches to pixels anyway so the way I did it seems to be about as elegant as possible. Please prove me wrong.
Posted
Updated 17-Apr-10 21:54pm
v6

1 solution

The co-ordinate system for the screen and the printer are different. I have overcome this problem in the past by setting up a group of variables with offsets & scaling factors, I load them at the top of my draw function with appropriate values depending on where I am drawing to and then I use those values to calculate the correct location.

It is not very elegant but it does work.

If you come up with anything better I would be really interested as it is fairly tedious. Good Luck. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900