Solved

Printing in LOMETRIC

Posted on 2004-09-02
18
526 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:r2far
  • 10
  • 8
18 Comments
 
LVL 4

Author Comment

by:r2far
ID: 11964314
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?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11971743
What happens with SRCCOPY instead of SRCAND in the BitBlt?  (Are you actually drawing anything in the code you missed out?)
0
 
LVL 4

Author Comment

by:r2far
ID: 11972788
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...
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11972836
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
0
 
LVL 4

Author Comment

by:r2far
ID: 11973290
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.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11973833
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?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11973940
rPlotArea is valid isn't it (check width and height as being >0)
0
 
LVL 4

Author Comment

by:r2far
ID: 11974719
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.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11980842
Try changing the -ve values into +ve values.  I suspect that is giving the problems (bitmap of zero height?)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Author Comment

by:r2far
ID: 11997383
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).
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11997424
I'll have a think and try some code.  It maybe tomorrow before I find some time.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12003795
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.
0
 
LVL 4

Author Comment

by:r2far
ID: 12009637
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?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 12009779
     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");
      }


      CRect rPlotArea(0, 0, 400, 400);
      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 */
      dcPlots.FillSolidRect(rPlotArea, RGB(0, 255, 0));
      dcPlots.FillSolidRect(25, 25, 125, 125, RGB(255, 0, 0));

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



This displays on screen and in the print preview.  (Using a bitmap and BitBlt.)
Note the rPlotArea uses a normalized rectangle.

I suspect you can use your current technique BUT you have a problem in your rPlotArea as I mentioned earlier.  Have you put a breakpoint in and checked the values in the rectangle.
0
 
LVL 4

Author Comment

by:r2far
ID: 12027379
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 =]
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12028932
Yr welcome - remember the IsPrinting() fn of the DC, that should assist in the critical sections of code.
0
 
LVL 4

Author Comment

by:r2far
ID: 12068375
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 =]
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12072213
Yr welcome - it can be a bit mind bending with +ve/-ve co-ords as to what goes where.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now