Solved

WYSIWYG printing

Posted on 1997-11-28
12
252 Views
Last Modified: 2013-12-03
I have a function for rendering text on a device context. It works fine with DISPLAY but when I try to use a printer DC, sometimes words at the end of a line get clipped. It seems to be GDI's problem because when I set the viewport extent larger than the real size of the page (results in different scaling) the words still get clipped but somewhere else. BTW, I think it's irrelevant but it's a program for 16bit Windows.
0
Comment
Question by:wiregin
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1408944
The problem is that printer has much better resolution that dispaly so you must perform neccessary scaling.

Suppose pdc CDC class associated with printer DC,
 
       int ixp=pdc->GetDeviceCaps(LOGPIXELSX);
        int iyp=pdc->GetDeviceCaps(LOGPIXELSY);

        // get the current window's resolution
        CDC* pddc = GetDC();
        int ixd=pddc->GetDeviceCaps(LOGPIXELSX);
        int iyd=pddc->GetDeviceCaps(LOGPIXELSY);

now you must multiply all you graphics by the factor (ixp/ixd) at horizontal direction and by the factor (iyp/iyd) at vertical direction  


0
 

Author Comment

by:wiregin
ID: 1408945
Well isn't GDI supposed to do that? First I set the window and viewport extents and then GDI should do the conversion from logical coordinates to device coordinates. What I do is I set the logical coord. extent to the size of the page on the screen in pixels (it's 800 pixels wide in my case) and then I set the device coord. extent to the size of the physical page in pixels. That is supposed to work isn't it? Part of my code looks like this:

          if(PrintDlg(pd)!=0)
          {
            hs=GetDeviceCaps(pd->hDC,HORZRES);
            vs=GetDeviceCaps(pd->hDC,VERTRES);

             StartDoc(pd->hDC,&di);
             do
             {
               SetMapMode(pd->hDC,MM_ISOTROPIC);
               SetWindowExt(pd->hDC,PAGEWIDTH,PAGEWIDTH);
               SetViewportExt(pd->hDC,hs,hs);

                StartPage(pd->hDC);

               // Perform all the drawing

                EndPage(pd->hDC);
              EndDoc(pd->hDC);
            }

0
 
LVL 7

Expert Comment

by:galkin
ID: 1408946
I don't see how you do scaling. Anyway I suggest you using my code, I got it from my project and it works. Besides, it looks very simple.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 2

Expert Comment

by:JensUniweb
ID: 1408947
I see one error in your code. You use hs as both width and height in SetViewportExt(). But I'm not sure that is the problem. Does scaling seem to be OK?? Not all GDI function work with logical units. How do you write the text??
0
 

Author Comment

by:wiregin
ID: 1408948
Well since I'm using the MM_ISOTROPIC mapping mode, it doesn't matter that I use the same number for both axes. Yes, the scaling is totally fine but as I said, sometimes a word at an end of a line gets clipped on the printer, not on the screen. I use ExtTextOut function to write the text to a DC.
0
 
LVL 1

Expert Comment

by:pking
ID: 1408949
Is the word at the end of a line or the edge of the page?
0
 

Author Comment

by:wiregin
ID: 1408950
It's at the end of a line. Also, it can be in the middle of a page if there are more than one columns.
0
 
LVL 1

Expert Comment

by:pking
ID: 1408951
Are you printing lots of text in one SDK call?  For example, are you printing perhaps 4k more or less?  
0
 

Author Comment

by:wiregin
ID: 1408952
Yes, there's text and graphics.
0
 
LVL 1

Accepted Solution

by:
pking earned 20 total points
ID: 1408953
Specifically, do you send more than 4k worth of text to the ExtTextOut function?  If you are than that is probably your problem.  I recall this issue years ago when doing some printing work on 16-bit Windows.  I found that this problem became a non- issue when I kept the amount of text I sent to the API call at a little less than 4k.  There is a big difference between Win16 and Win32 in this case.
0
 

Author Comment

by:wiregin
ID: 1408954
I'm sorry I misunderstood your question. No I don't send more than 4k in a single ExtTextOut call. What my rendering function does is that it outputs formated text (multiple fonts, alignment, etc.) So there are always only a few words being printed at a time.
0
 
LVL 1

Expert Comment

by:pking
ID: 1408955
Sorry,  If that is the case, then my answer is incorrect.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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