2

Have a Windows program (MFC, MBCS) that uses a RichEdit 2.0 controls (as basically a CRichEditView. When I set the text of the control for a string on Windows 10, the string renders correctly, but on lesser versions, say Server 2016, there is a character that does not render correctly. Impossible to really provide a complete example, but you can get the gist from a few lines.

   // m_rich is a CRichEditCtrl for this example...
   CHARFORMAT cf = { sizeof(cf), CFM_FACE | CFM_SIZE, 0, 16 * 20 };// 16 pt font easy to see
   _tcscpy_s(cf.szFaceName, _countof(cf.szFaceName), _T("Courier New"));
   m_rich.SetDefaultCharFormat(cf);

   SETTEXTEX st = { 0, 1200 };
   WCHAR wsz[] = L"This is the symbol \u26a0 in the middle";
   ::SendMessage(m_rich.GetSafeHwnd(), EM_SETTEXTEX, (WPARAM) &st, (LPARAM) wsz);

On Windows 10, the rich edit displays the warning symbol (⚠). But on Server 2016, it just renders it as an empty box. Supposedly, that is because the character is not supported with the font.

After examining things, I found that what happens on Windows 10, is that the rich edit control is smart and automatically converts the font face for the warning symbol character to "Segoe UI Symbol". On Server 2016, it doesn't do the automatic conversion and the font keeps its "Courier New" font.

Now, a user can put an HTML formatted character into a MBCS string field something like "⚠". We then convert it to a unicode string and put it in a rich edit.

I'd like to be able to detect if one of these characters is not supported by the chosen font, and if not, change the font for the character.

Easy way to do this?

Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
  • 1
    Does 2016 have any fonts that supports that codepoint? RichEdit should support font linking on older versions as well. – Anders Jun 26 '19 at 17:46
  • Sure it does. If I copy and paste the text from one machine to the other (using RDP), the text is rendered correctly on 2016. That is because RTF clipboard format is used. What helps on 10 is that it automatically converts the font of that one character to one that is renderable. On 2016, no automatic conversion is done, and so it renders as an empty box. But, a user can enter any character and the challenge is determining if it can be rendered in the selected font. – Joseph Willcoxson Jun 26 '19 at 18:15
  • Have a look at this [answer](https://stackoverflow.com/a/54053526/4603670) and the function `IsTofuError(hdc, hfont, L"⚠")` That should tell you if `L"⚠"` is printed without error. There is additional font substitution with `get_font_link`, usually for Asian languages, but that section probably doesn't apply to your code. – Barmak Shemirani Jun 27 '19 at 01:51

0 Answers0