Solved

WYSIWYG printing

Posted on 1997-11-28
12
242 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Is the word at the end of a line or the edge of the page?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:wiregin
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, there's text and graphics.
0
 
LVL 1

Accepted Solution

by:
pking earned 20 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry,  If that is the case, then my answer is incorrect.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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