I cannot figure out why this is happening and it's driving me mad. Please assist if at all possible.
I am writing a class to simplify text printing. The entire class is basically finished, but the one problem is that the last 3 characters on each line (if they reach to the end of the line) are not there!
I've tried the code in simplest terms to try to find the problem but to no avail. I'm doing a simple CDC::TextOut() of a line that fits on the page. In fact, it goes all the way right up to the right border, but, again, the last three characters are "invisible."
The CDC::GetTextExtent() of the string I'm printing is 4800 and the width of a page is 4800. The rect dimensions of the page are left=0, right=4800, top=50, bottom=6350 (with a 1/4" margin all around).
I don't want to just limit the length of a line to 3 characters less because the page will look crooked as one side with have the correct margin and the other will be larger. And besides that with a different font (I'm using courier new currently) it may be more or less than 3 characters.
Do you have any idea why this is happening??? Please help. Thanks much in advance.
This is just a guess. But how are you calculating the number of pixels to 1/4 inch horizontally? I believe the x & y dpi values for printers are not necessarily the same. I.e.
may yield slightly different values.
Could this be the source of your problem?
Unfortunately, no, that is not the problem. Since the device's printable region as calculated by the GetDeviceCaps() values is not consistent between printers, I have calculated the margin by retrieving the actual device units in twips mode then converting them to logical units.
Any other ideas?
Do any of you have a program where you print text across the entire horizontal span of the page where all characters are visible?
*scratching my head*
I do. But unfortunately this is written in C++ Builder speak. I rarely use Win API calls directly.
In this, I add a margin around the page, but specify the margin in terms of a configurable percentage page height/width (i.e. around 5%). It seems to work even if margins are set to zero. However, the Borland component library are encapsulating a lot of what you may be doing. So I'm not sure how much help this would be.
Like you, I rarely use win API. I base most all of my windows programming on MFC, but that's neither here nor there.
I'm beginning to think that I should do little more than ignore the problem... I just printed the exact same line that I printed from my program with notepad with .25" all around again. While the margins seem to be padded a little bit by notepad, it too has disappeared a character at the end of the line (just one as opposed to my three).
I also printed the same data with a .50" margin and nothing was missing... Although I don't know the source of the problem, I know that microsoft did the same as I propose (to ignore it), so I guess it's okay to do the same... ?
Or perhaps I'll do what it appears notepad does and just add an extra buffer in addition to the margins. That sound like a disgusting idea or you think I should make like nike and just do it?
This is another wild guess.
Do you have such a concept as a clip rectangle with your printer canvas? With Borland VCL, library objects & methods usually just encapsulate Win API functionality. So I'm guessing you might have.
If this is so, is there a default margin setting in your printer driver configuration window? If so this may set the printer canvas clip rectangle to be inside the physical dimensions of the page. Any region printed outside this rectange will not be rendered, even if it were physical within the page area.
If this sounds familiar, are you checking to ensure that your CDC::GetTextExtent() calls take into account this clip rect, rather than just the raw page rect?
As far as my code is concerned there is no clipping happening at all. I had given this a thought too; like that perhaps there is some magical rect that I am supposed to restrict my writes to.
I am quite positive now that it's just the way it goes. I printed the same line again with .25" margins, but this time from MS Word. The same thing happened from word as from my program. Exact same margin width and character size/spacing and at the end of the line, guess what. There were characters missing! So apparently it has nothing to do with my code (thank goodness since it is very straight forward).
It does, however, just seem to be a problem with 1/4" margins (or smaller I'd presume), and who knows, it may be a problem with the printer too (HPLaserJet8150).
Thanks for all your assistance Davros.
Sounds like your printer can't handle margins that small.