Solved

WYSIWYG printing

Posted on 1997-11-28
12
251 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Import all database objects 12 56
Timely operations (on order of hours) from within a VM 3 63
VBA Error Since Excel 2016 x64 5 119
What .NET website keeps me current? 9 77
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…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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