4

I set the font linking to SimSun for my fonts at Window registry.
When I apply that font to my richedit control, it have below behavior:

  • First, it display SimSun - ok
  • When I add text that is not CKJ unicode, then add more text in CKJ, the font window selected is Microsoft Ya Hei instead of SimSun

Here is screenshot:

enter image description here

The fonts are:

  • "阿哥": SimSun
  • "◎": Segoe UI Symbol
  • "[āgē] đại ca" Arial
  • "对兄长的称呼。" Microsft Ya Hei

How I can force window to choose SimSun instead of Microsft Ya Hei in this case?

EDIT
Thank @Cody Gray for perfect answer. Here is worked code:

CHARFORMAT2 cf2;

memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_FACE | CFM_SIZE | CFM_CHARSET | CFM_LCID;
cf2.lcid = 0x0804;
cf2.yHeight = 280;
cf2.bCharSet = CHINESEBIG5_CHARSET;
wcscpy(cf2.szFaceName, L"SimSun");
SendMessage(rtbhWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_ASSOCIATEFONT, (LPARAM)&cf2);

cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_FACE | CFM_SIZE | CFM_CHARSET | CFM_LCID;
cf2.lcid = 0x0409;
cf2.yHeight = 220;
cf2.bCharSet = ANSI_CHARSET;
wcscpy(cf2.szFaceName, L"Segoe UI");
SendMessage(rtbhWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_ASSOCIATEFONT2, (LPARAM)&cf2);
NoName
  • 7,940
  • 13
  • 56
  • 108

1 Answers1

2

You can set the default font for character representations by sending the RichEdit control an EM_SETCHARFORMAT message with the SCF_ASSOCIATEFONT flag.

This involves filling in a CHARFORMAT2 structure with the characteristics of the desired font as well as the LCID corresponding to the locale of the desired character representation, as outlined in the documentation.

See also: How to Use Font Binding in Rich Edit Controls

It looks like to me that Windows 8 introduced the "Microsoft YaHei" font as the default UI font for the Simplified Chinese script. I think (but I'm not certain) that SimSun used to be the default font for this script, so that would explain it if you were seeing this behavior on some systems and not others.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • May I ask one more question, can I bind two font sizes to two selected fonts? For example, if I select a paragraph, set font size=100, then font 1's size =100, font 2's size scale to 150? – NoName Jan 14 '16 at 12:09
  • @Tuyen I'm not entirely sure if I understand your question. But as far as I know, zooming in a RichEdit control is global. If you set a zoom factor with something like `EM_SETZOOM`, it applies to all of the text in the control. You can't set a different zoom factor for individual strings of text. But you can just change the font size, the normal way: send the `EM_SETFONTSIZE` message when you have a string of text already selected. – Cody Gray - on strike Jan 15 '16 at 01:39
  • @Tuyen I'm not entirely sure if I understand your question. But as far as I know, zooming in a RichEdit control is global. If you set a zoom factor with something like `EM_SETZOOM`, it applies to all of the text in the control. You can't set a different zoom factor for individual strings of text. But you can just change the font size, the normal way: send the `EM_SETFONTSIZE` message when you have a string of text already selected. – Cody Gray - on strike Jan 15 '16 at 01:40
  • It is not zoom, for example: There are both latin and CJK letters in a textrange. If I set font size for that text rang to 12, it is good for latin letters, but too small for CKJ. If we set font size to 18, it is OK for CKJ, but too big for latin. One way I can do is split that range to parts, each part contain only latin or CKJ, then set font size for it. But it is quite a hack work. So I wonder if have any method, something like map/link font size of each font face to base font size? If we set base font size for text range = 12, then font 1 size = 12, font 2 size = 12*1.5? – NoName Jan 15 '16 at 02:52