Tech Support > Microsoft Windows > Development Resources > Reduce character spacing in an edit or rich edit control?
Reduce character spacing in an edit or rich edit control?
Posted by szuchymj@jmu.edu on January 24th, 2005


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

Posted by Sten Westerback on January 25th, 2005



<szuchymj@jmu.edu> wrote in message
news:1106605612.356907.95780@c13g2000cwb.googlegro ups.com...
Most probably....

At least you have the option to draw each character separately.


Firstly word does it's stuff without an Editbox (nor is it using a
RichEdit).

But for edit boxes... sure you can subclass an edit box and for instance
draw yourself. You could also try to see it helps to set the font of the
HDC provide by WM_CTLCOLOREDIT to an font you create.

wndproc would either not be called (you draw everything yourself) or
it's HDC should be modified and the effects of the called routine disabled.



parts,
is not supposed to be looking exactly the same. I really can't see why
you would need it -- you are usually better of dividing the subsections
of a paper form to a set of tabbed pages in a dialog + fields for help and
value validation messages.

- Sten



Posted by szuchymj@jmu.edu on January 25th, 2005


How do I draw each character in an edit box seperately? I mean I could
see how this would be done with WM_PAINT, but then wouldn't I have to
reimplement the way the cursor moves, highlighting, etc?

I thought kerning was just for different characters, and in
proportional fonts - this Word kerning happens even with fixed width
fonts, typing the same character over and over again.

I can already get the handle to the device context of the edit control
okay, it's just that settextcharacterextra isn't changing the way
things look. Are you saying that calling this in a handler for the
WM_CTLCOLOREDIT message might have more of an effect, because of the
timing?


I would rather not draw everything myself, because at the moment I
don't know how to. The second option looks promising, but how do I
disable the effects of the called routine?

It is a re-creation of a paper form with a bunch of fields, so I am
worried that it will confuse the user to have a field allowing only 30
characters on the screen and maybe 33 on the printer. For now I will
probably just leave it that way. As long as the printed output isn't
too big for the fields on the paper it is not a big deal. Obviously I
do not know much about how controls work, I have been wanting to buy
the Petzold book to gain more knowledge on this topic. But I am putting
it off for a month or two because I am behind on starting another
project, that involves mostly CPU and very little drawing or Win32 API.


Posted by Tony Nelson on January 26th, 2005


In article <1106605612.356907.95780@c13g2000cwb.googlegroups. com>,
szuchymj@jmu.edu wrote:

Have you tried EM_SETTARGETDEVICE? It seems to be for making screen
display match a printer. (I know nothing, I just saw it in the Platform
SDK.)
__________________________________________________ ______________________
TonyN.:' <mailto:tonynlsn@shore.net>
' <http://www3.primushost.com/~tonynlsn/>



Similar Posts