Display Asian characters (using Unicode): difference in character spacing when represented in a RichEdit control compared to using ExtTextOut

This picture illustrates my predicament:

Image1

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

I would like to represent the characters in the same way as in the RichEdit control (ideally) in order to preserve the transfer positions.

Can anyone tell me:

a) What is the most correct representation?

b) Why does the RichEdit control display text without spaces between Asian characters?

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

d) Would it be different if I were working on an Asian version of Windows?

I may be optimistic, but if anyone has any hints, I would be very interested to hear.

In case this helps:

Here is my text:

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

apologizes to Asian readers, this is just to test our Unicode implementation, and I don’t even know what language the characters are taken in, not to mention whether they mean anything.

To view the effect by pasting these characters into a RichEdit control (such as Wordpad), you may find that you need to scroll through them and set the font to “Arial”.

The rich text that I get 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 does not seem to contain the meaning for the “step” of the character, which was my first thought.

+4
source share
3 answers

I do not know the answer, but there are several reasons to suspect:

  • There are several versions of advanced editing. You may be using an older version that does not have all the latest typography improvements.
  • There are many styles and flags that affect the behavior of the rich editcontrol, so you can learn which ones are installed and what they do. For example, see EM_GETEDITSTYLE .
  • Many Asian fonts come in two versions on Windows. One is optimized for horizontal layout, and the other for vertical layout. This last one, as a rule, has the same name, but has an @ to it. You may be using the wrong control for editing.

UPDATE: by teaming with Wordpad, I was able to reproduce the problem with overflowing text in the advanced editing control.

  • Open a new document in Wordpad on Windows 7. Note that the selected font is Calibri.
  • Insert sample text into the document.
  • The text is displayed correctly, but Wordpad changed the font to SimSun.
  • Select the text and return the font back to Calibri or Arial.

The text will now be full, very similar to your example. So the main problem is with font binding and backing. ExtTextOut probably automatically selects the appropriate font for the script. Your task is to figure out how to determine the correct font for the script and set this font in the advanced edit control.

+3
source

ExtTextOut allows you to specify the logical distance between records. It has the lpDx parameter, which is a constant pointer to an array of values ​​indicating the distance between the roots of neighboring symbol cells. The Microsoft API documentation states that if you did not install it, it sets its own default interval. I have to say why ExtTextOut is working fine.

In particular, when you create an EMR_EXTTEXTOUTW entry in EMF, it populates the EMR_TEXT structure with this DX array, which considers one of your comments, allowed RichEdit to insert EMF with the information contained in the entry, in which if you did not set the font binding, then the RTF entry makes some coincidence to determine which font to use.

In terms of the RichEdit control, the following article may be useful:

Use font binding in Rich Edit Control

After assigning character sets, Rich Edit scans the text around to insert a dot forward and backward to find the closest fonts that were used for the character sets. If the font is not found for the character set, Rich Edit uses the font selected by the client for this character set. If the client has not specified a font for the set character, Rich Edit uses the default font for this character set. If the client wants a different font, the client can always change it, but this approach will work most of the time. The current default font selection is based on the following table. Note that the default fonts are set for each process, and there are separate lists for using the user interface and for the non-user interface.

If you have not set the character set, then it further explains that it returns to ANSI_CHARSET. However, it is more definitely much more complicated than that , as this article on the blog of Murray Sargent (a programmer at Microsoft) shows.

+1
source

This will only partially solve your problem, but there is a way to draw text in DC that will look exactly like with RichEdit: what is called a windowless RichEdit control. It's not quite simple: I wrote a CodeProject article on it a few years ago. I used this to solve the problem of scrollable display of blocks of text, each of which can be edited by clicking on it: a regular drawing is performed without window RichEdit and editing, showing the "real" RichEdit control on top of it.

This will at least give you text that looks the same in both cases, although unfortunately both cases will show too little spacing between characters.

Another thought: if you can rely on the installed Microsoft Office, you can also try the later versions of RichEdit that come with the office. You can learn more about this on Murray Sargent's blog , as well as some interesting font binding articles that may also help.

0
source

Source: https://habr.com/ru/post/1340974/


All Articles