Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display of Asian characters (with Unicode): Difference in character spacing when presented in a RichEdit control compared with using ExtTextOut

This picture illustrates my predicament:

Image1

All of the characters appear to be the same size, but the space between them is different when presented in a RichEdit control compared with when I use ExtTextOut.

I would like to present the characters the same as in the RichEdit control (ideally), in order to preserve wrap positions.

Can anyone tell me:

a) Which is the more correct representation?

b) Why the RichEdit control displays the text with no gaps between the Asian Characters?

c) Is there any way to make ExtTextOut reproduce the behaviour of the RichEdit control when drawing these characters?

d) Would this be any different if I was working on an Asian version of Windows?

Perhaps I'm being optimistic, but if anyone has any hints to offer, I'd be very interested to hear.

In case it helps:

Here's my text:

快的棕色狐狸跳在懶惰狗1 2 3 4 5 6 7 8 9 0

apologies to Asian readers, this is merely for testing our Unicode implemetation and I don't even know what language the characters are taken from, let alone whether they mean anything

In order to view the effect by pasting these characters into a RichEdit control (eg. Wordpad), you may find you have to swipe them and set the font to 'Arial'.

The rich text that I obtain is:

{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 Arial;}}{\colortbl ;\red0\green0\blue0;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\fs22\u24555?\u30340?\u26837?\u33394?\u29392?\u29432?\u36339?\u22312?\u25078?\u24816?\u29399?1 2 3 4 5 6 7 8 9 0\par\pard\'a3 $$ \'80\'80\cf1\lang2057\fs16\par}

It doesn't appear to contain a value for character 'pitch' which was my first thought.

like image 415
Coder_Dan Avatar asked Feb 23 '11 14:02

Coder_Dan


2 Answers

I don't know the answer, but there are several things to suspect:

  • There are several versions of the rich edit control. Perhaps you're using an older one that doesn't have all the latest typographic improvements.
  • There are many styles and flags that affect the behavior of a rich editcontrol, so you might want to explore which ones are set and what they do. For example, look at EM_GETEDITSTYLE.
  • Many Asian fonts come in two versions on Windows. One is optimized for horizontal layout, and the other for vertical layout. That latter usually has the same name, but has @ prepended to it. Perhaps you are using the wrong one in the rich edit control.

UPDATE: By messing around with Wordpad, I was able to reproduce the problem with the crowded text in the rich edit control.

  1. Open a new document in Wordpad on Windows 7. Note that the selected font is Calibri.
  2. Paste the sample text into the document.
  3. Text appears correct, but Wordpad changed the font to SimSun.
  4. Select the text and change the font back to Calibri or Arial.

The text will now be overcrowded, very similar to your example. Thus it appears the fundamental problem is with font linking and fallback. ExtTextOut is probably selecting an appropriate font for the script automatically. Your challenge is to figure out how to identify the right font for the script and set that font in the rich edit control.

like image 149
Adrian McCarthy Avatar answered Nov 10 '22 19:11

Adrian McCarthy


This will only help with part of your problem, but there is a way to draw text to a DC that will look exactly the same as it does with RichEdit: what's called the windowless RichEdit control. It not exactly easy to use: I wrote a CodeProject article on it a few years back. I used this to solve the problem of a scrollable display of blocks of text, each one of which can be edited by clicking on it: the normal drawing is done with the windowless RichEdit, and the editing by showing a "real" RichEdit control on the top of it.

That would at least get you the text looking the same in both cases, though unfortunately both cases would show too little character spacing.

One further thought: if you could rely on Microsoft Office being installed, you could also try later versions of RichEdit that come with office. There's more about these on Murray Sargent's blog, as well as some interesting articles on font binding that might also help.

like image 1
DavidK Avatar answered Nov 10 '22 18:11

DavidK