How to Use Font Binding in Rich Edit Controls
Microsoft Rich Edit 3.0 assigns a character set to plain-text characters depending on their context. Some examples are:
- Greek characters are assigned GREEK_CHARSET.
- Hangul symbols are assigned HANGUL_CHARSET.
- Chinese characters are assigned SHIFTJIS_CHARSET if kana characters are found nearby, or GB2312_CHARSET if no kana are found nearby.
- Non-neutral ANSI characters are assigned ANSI_CHARSET in any event.
The rich edit control uses Unicode internally, so this use of character sets differs from the original one used in font specifications. But the CHARFORMAT structure has a well-defined place for the character set.
Neutral characters like blanks and digits are assigned a character set depending on their context. For example, a blank surrounded by characters of the same character set gets that character set. Neutrals and digits used for bidirectional text are assigned character sets in a way that is based on the Unicode bidirectional algorithm.
What you need to know
- Windows User Interface Programming
Use Font Binding in a Rich Edit Control
After character sets are assigned, Rich Edit scans the text around the insertion point forward and backward to find the nearest fonts that have been used for the character sets. If no font is found for a character set, Rich Edit uses the font chosen by the client for that character set. If the client hasn't specified a font for the character set, Rich Edit uses the default font for that character set. If the client wants some other font, the client can always change it, but this approach will work most of the time. The current default font choices are based on the following table. Note that the default fonts are set per-process, and there are separate lists for UI usage and for non-UI usage.
|Language||UI font name||UI font size||non-UI font name||non-UI font size|
|Western, CE, ME, Vietnamese||Tahoma||8||Arial||10|
|Japanese||MS UI Gothic||9||MS P Gothic||10|
|Thai||MS Sans Serif||8||Tahoma||14|
|Georgian, Armenian||Arial Unicode||8||Arial Unicode||10|
Therefore, in the default font-binding table (entries have a character set, font name, and size), Rich Edit allows ANSI_CHARSET to match several character sets, while the appropriate character set matches other fonts on a one-to-one basis. More precisely, rich edit uses the ANSI_CHARSET choice whenever no other alternative is found. You will be able to specify a finer granularity than this; for example, assign a specific ARABIC_CHARSET for Arabic runs, a specific Greek font for Greek runs, and so on. This finer granularity will also be used if a font with the desired character set stamp is found somewhere in the document before the area that is being font-bound.
Note that Rich Edit does not currently handle a missing glyph in a font that claims to support a character set but is incomplete. At display time in a complex script, Rich Edit does end up knowing that such a glyph is missing, but it does not cause the backing store to use a new font. Normally, the underlying font linking of the operating system will accomplish this.
Rich Edit 4.1: To set the default font for a script, call EM_SETCHARFORMAT with CHARFORMAT2, specifying values for the yHeight, bCharSet, bPitchAndFamily, szFaceName, and lcid members. Also, to get the default font for a specific code page, call EM_GETCHARFORMAT with CHARFORMAT2, specifying values for the bCharSet and lcid members.