Summary:
I want to alter the text on screen so as to better match what is
printed. I would like to use SetTextCharacterExtra on an edit or rich
edit control so that the text may be squished together. Is this
possible?
Details:
I am having a WYSIWYG problem with fonts, in particular the Courier New
font. The problem is that the horizontal CPI (characters per inch) of
the font is different on the screen than it is on the printer. The
cause appears to be that the screen does not have as high a density of
pixels as the printer. So windows tries to make the font looks nice on
screen by giving it more horizontal space to display itself. This way,
a character will not get stuck between two pixels on screen.
Unfortunately, this also makes the width of a given string on the
screen a good deal wider than it would be on the printer.
I see two solutions to this. One, is to make the printed text wider to
match the screen. Two, is to make the text on screen less wide, to
match the printer. Solution one is of no use to me, because I require
that the printed text be at the same width as it is currently. Is there
an easy way to do solution two?
Microsoft Word gets around this, for Courier New at least, by using
uneven character spacing to draw the text much more closely to its
width on the printer. For example, say there is a Courier New string of
ten characters in a Word document, i.e. 1234567890. Between each of
characters one to three, there will be two pixels of space. Between
four to seven, there will be one pixel of space. Between eight to zero,
there will be two pixels of space. So for this string, on average,
there will be 1.444 pixels between each character on the screen. This
makes the text on the screen look just like it does on the printer.
This is in contrast to say WordPad or an edit control, where there will
always be 2 pixels between characters on screen, no matter what. This
is different (wider) from how it looks when printed.
Is there an easy way to configure/subclass a standard edit or rich edit
control so that it would show text like Word does? I looked into using
SetTextCharacterExtra with a negative number to squish the text
together. But, passing the device context of the edit control to this
function seems to do nothing, even with a positive number. I am
guessing that SetTextCharacterExtra requires some kind of canvas
because it is a GDI function. The same goes for ExtTextOut, it sounds
like what I need but I wouldn't even begin to know how that gets
called from an edit control if at all.
The alternative is to create my own edit control that uses a canvas and
GDI to draw text. This seems like overkill for just the Courier New
font at a single point size. Maybe someone knows of a component I can
purchase?
In closing, I am sure this problem has happened to a lot of other
people besides me, but I could not find a post that addressed the issue
of changing the text onscreen to fit the printer rather than vice
versa. I am guessing that is because it is impossible without
recreating the windows edit control, but I just thought I would double
check to make sure I am not missing anything obvious.
keywords: intercharacter spacing, intracharacter spacing, tedit,
trichedit, text box, letterspacing, kerning, fixed width, monospaced,
win32 api, Q22553, cricheditctrl, cedit