Link to home
Start Free TrialLog in
Avatar of r2far
r2far

asked on

Printing in LOMETRIC

Most of my print code is working great, except for one section that is giving me problems.

At one point in the printout, I need to draw a series of plots for a graph within a given area of the page without going outside that area.  Rendering to the screen was easy enough, i just made a buffer dc, and gave it a bitmap the size of the area i wante.  I then rendered the plots onto the buffer and blitted the buffer onto the main DC.

That same method yields unfavourable results when used for printing.  I am printing in LOMETRIC mapping mode (1 point = .1mm, negative Y-Axis).  When i print using that mehtod, I end up with a solid color where the plots should have rendered.

I need help to either make this buffer dc method work, or i need a viable alternative.  Whatever the solution, the plots rendered CANNOT go outside the given area so there must be some method of clipping off what is un wanted.



// here is the buffer dc code that has failed
CDC dcPlots;
dcPlots.CreateCompatibleDC(pDC);
CBitmap bmPlots;
bmPlots.CreateCompatibleBitmap(pDC,rPlotArea.Width(),rPlotArea.Height());
CBitmap* pOldBM = dcPlots.SelectObject(&bmPlots);
dcPlots.BitBlt(0,0,rPlotArea.Width(),rPlotArea.Height(),&dcPlots,0,0,WHITENESS);

/* plots rendered onto dcPlots HERE */

pDC->BitBlt(rPlotArea.left,rPlotArea.top,rPlotArea.Width(),rPlotArea.Height(),&dcPlots,0,0,SRCAND );
                  
dcPlots.SelectObject(pOldBM);
dcPlots.DeleteDC();
bmPlots.DeleteObject();




Thanks for your help in advance
Avatar of r2far
r2far

ASKER

UPDATE:

I have now been trying to use CRgn with SelectClipRgn (NO buffer dc).  I do not get a solid color anymore, but i get nothing instead.

CRgn rgn;
rgn.CreateRectRgn(rPlotArea.left,rPlotArea.top,rPlotArea.right,rPlotArea.bottom);
pDC->SelectClipRgn(&rgn,RGN_COPY);

Can a CRgn hold the negative coordinates needed to clip in LOMETRIC mode?  if not, then is there a way to get around this?
Avatar of AndyAinscow
What happens with SRCCOPY instead of SRCAND in the BitBlt?  (Are you actually drawing anything in the code you missed out?)
Avatar of r2far

ASKER

Thanks for your response,

SRCCOPY does the same thing.   And yes... it is drawing code that i left out.  But it is just lines, no fills, no rectangles, ect...
What I mean is are you actually drawing anything.  You may be getting just white because that is all you are putting into the dc before the BitBlt
Avatar of r2far

ASKER

I never get white.  In fact i can actually account for the solid color the fills the graphing area.  It is the same color as the last plot rendered typically.  But why it does that i am not sure.
dcPlots.BitBlt(0,0,rPlotArea.Width(),rPlotArea.Height(),&dcPlots,0,0,WHITENESS);

/* plots rendered onto dcPlots HERE */

pDC->BitBlt(rPlotArea.left,rPlotArea.top,rPlotArea.Width(),rPlotArea.Height(),&dcPlots,0,0,SRCAND );

I never get white.  In fact i can actually account for the solid color the fills the graphing area.  It is the same color as the last plot rendered typically.


Leave out the drawing code, is it now white?  (It should be).


Try the following.  Draw a big plus that should go outside the area you actually want on each axis.  Do you get an 'orphan' line?
rPlotArea is valid isn't it (check width and height as being >0)
Avatar of r2far

ASKER

yes. leaving out draw code yields white.

As for rPlotArea, this is where i get confused.  Due to the LOMETRIC map mode, the Y-axis is negative downwards and thus so are the Y-coordinates of rPlotArea is also negative.  I am wondering if this is causing problems with the bitmap or something.  But this is where my theory knowledge is lacking a little.
Try changing the -ve values into +ve values.  I suspect that is giving the problems (bitmap of zero height?)
Avatar of r2far

ASKER

sry for response delay.

I can make the bitmap dimensions positive no problem, but how does that effect painting on the DC when the mapping mode demands negative y-axis values.  To visually think about it, wont the bitmap rectangle start at 0 and head upwards, and the area of the CDC being drawn on start at 0 and head downwards?  If this is true, then the only time something i draw on the CDC will end up on the bitmap (and thus be copied to the main dc) is when part of what i draw lands at 0 y-axis value.


positive (bitmap coordinates)
/ \
 |
 |
 0   (y-axis)
 |
 |
\ /
negative (LOMETRIC Coordinates)


If I can't get the buffer DC to work... is there anyway to setup a clipping region dispite the negative coordinates.  I have tried this method as well, but the final result yielded nothing, no solid color, and no lines ect...

I know the draw code works, because when i remove the code that is suppose to either use a CDC or a CRgn to clip the graph area, I actually get the proper printout (only the graph lines go off the page which is what I am trying to prevent from happening).
I'll have a think and try some code.  It maybe tomorrow before I find some time.
I've done a plain SDI app with print/preview.  In the OnDraw I have

      pDC->SetMapMode(MM_LOMETRIC);

      pDC->MoveTo(100, -100);
      pDC->LineTo(500, -350);
      pDC->LineTo(800, -350);
      pDC->LineTo(100, -100);

      pDC->Ellipse(800, -350, 1200, -450);

      if(pDC->IsPrinting())
      {
            pDC->TextOut(1500, -100, "Hello");
      }


On screen I get a triangle and an ellipse.
On printpreview I get both of those AND the text - hello.

Maybe what you could do is use the buffering for when you are on screen and for the print just draw direct to the printing DC.

Drawing outside the area.  Use the GetDeviceCaps of the printing DC to determine the available area for you to draw on and 'clip' the LineTo calls yourself.
Avatar of r2far

ASKER

The actuall area to print on is a full sheet.  But I want a certain portion of the code to restrict it's rendering to a certain rectangle.  Clipping is what i want to do.  

To recap: I traditionally do this by rendering the portion to be clipped on a seperate DC and then blit it onto the main DC.  This will not work for prinintg.

Is there a way i can setup a clipping region before i render the graph onto the print DC using SelectClipRgn()?  I have tried but it never worked.  Maybe Clip regions can't handle negative numbers?
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r2far

ASKER

I think that last bit of code might help... I think it will invert my drawing though (will just re-write my plot rendering code to account for that).  Give me some time to re-write my code to implement the possible solution and I will get back to you.

Thanks for all your help so far AndyAinscow =]
Yr welcome - remember the IsPrinting() fn of the DC, that should assist in the critical sections of code.
Avatar of r2far

ASKER

sry for delay.  So much to do so little time =\

as i suspected, the printout was inverted.  but i solved that easily enough by making some mods to the blit from the buffer to the main dc.

// in the context of your example, I think the changes would have been:
pDC->BitBlt(120,-560-rPlotArea.Height(),rPlotArea.Width(),-rPlotArea.Height(),&dcPlots,0,-rPlotArea.Height(),SRCAND);

The important thing is that i got the plots to print, now it is a matter of getting the annotations and other stuff to print properly (which will now be easy thanks to your help).

Thanx again =]
Yr welcome - it can be a bit mind bending with +ve/-ve co-ords as to what goes where.