mfc >> Reduce character spacing in an edit or rich edit control?

by szuchymj » Tue, 25 Jan 2005 06:26:52 GMT

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



mfc >> Reduce character spacing in an edit or rich edit control?

by Sten Westerback » Wed, 26 Jan 2005 01:48:26 GMT






Most probably....


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

I believe it's using kerning features...


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.

It's should be called by WM_PAINT handler and the default EDIT
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.

You could do that as...
.. it's more cost efficient than to buy some additional components.


I doubt that... printing and screen layout, especially for editable UI
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





mfc >> Reduce character spacing in an edit or rich edit control?

by szuchymj » Wed, 26 Jan 2005 04:33:50 GMT

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

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?

disabled.

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?

subsections
and

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.



Reduce character spacing in an edit or rich edit control?

by Tony Nelson » Thu, 27 Jan 2005 01:40:18 GMT

In article < XXXX@XXXXX.COM >,



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: XXXX@XXXXX.COM >
' < http://www3.primushost.com/ ~tonynlsn/>



Similar Threads

1. Problem with special characters in Rich Edit control

2. count number of characters in rich edit control

How can i count number of characters in rich edit control 2

3. Show format characters in Rich Edit

4. URL link is broken in Rich Edit Box if different language characters are used

Hi

I have built an application using RichEdit20 class for displaying rich
edit box.
When I enter any URL (e.g http:\\dummy.com) it is highlighted and I
can click the URL to open it. But if I introduce some other language
characters in URL e.g. Japanese language characters then link is
broken i.e. it is not highlighted.

Example
If I write http:\\dummy.com then this URL is highlighted properly but
if I write http:\\dumボタンにmy.com where ボタンに are Japanese characters
then link is broken after http:\\dum


How do I get the whole URL highlighted in rich edit box even if I use
characters of different language? Do I need to handle some message for
the same?

Thanks in advance
Varun

5. URL link is broken in Rich Edit Box if different language characters are used

6. URL link is broken in Rich Edit Box if different language characters are used

7. Rich edit control and having a hypertext control to send the messages to windows

8. Rich Edit - adding multibyte characters

The Rich Edit control allows the pasting of multibyte characters - eg
Courier New $25B2.

How can I do this from Delphi?

Arthur