Solved

WYSIWYG printing

Posted on 1997-11-28
12
246 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

861 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

23 Experts available now in Live!

Get 1:1 Help Now