Rich Edit Control, two unicode fonts, same character present in both, but only one of them will display that character

Posted on 2006-03-28
Medium Priority
Last Modified: 2013-12-03

I'm having a curious problem with one unicode font.  I'm running XP, and VS7,

I have a tiny application with a single window with a Richtextbox.  I'm
compiling with unicode characters, and am running the following code to
check that I'm OK.  My code has two Greek characters, and two Syriac

If I use the palatino linotype font, the two Greek characters display OK, and I
get two square boxes for the Syriac.

If I use the TITUS Cyberbit Basic free font (which includes all
characters) then I get all four symbols displayed OK.

If I use the Estrangelo Edessa font (which is basically just Syriac,
and comes with XP) then the Syriac characters don't display (and only
one of the Greek; but that's fine).  Yet I can see the characters fine
in charmap, and if I copy and paste one into the running application,
it displays OK in the window.

Why would my code work for TITUS, but not Estrangelo Edessa?

I'm pretty new to the MFC, so I may be doing some howlers.  Here's the
code I'm running, and all comments are very welcome.

Roger Pearse

---- start -----
void CharnessView::OnFileRun()

        CRichEditCtrl& rCtrl = GetRichEditCtrl();

// Initializes a CFont object with the specified characteristics.
        CFont * font = new CFont;
   36,                        // nHeight
   0,                         // nWidth
   0,                         // nEscapement
   0,                         // nOrientation
   FW_NORMAL,                 // nWeight
   FALSE,                     // bItalic
   FALSE,                     // bUnderline
   0,                         // cStrikeOut
   ANSI_CHARSET,              // nCharSet
   OUT_DEFAULT_PRECIS,        // nOutPrecision
   CLIP_DEFAULT_PRECIS,       // nClipPrecision
   DEFAULT_QUALITY,           // nQuality
   DEFAULT_PITCH | FF_DONTCARE,  // nPitchAndFamily
   _T("estrangelo edessa")));                 // lpszFacename
//   _T("titus cyberbit basic")));                 // lpszFacename
//   _T("palatino linotype")));                 // lpszFacename

        // Cause the textbox to use the new font

        rCtrl.SetSel(-1,-1);  // end of line
        rCtrl.ReplaceSel( _T("some text\n") );

        //WriteRedTxt(_T("red text\n"));
        rCtrl.SetSel(-1,-1);  // end of line
        rCtrl.ReplaceSel(_T("\x03ac \x1ff6\n"));   // Greek text
        rCtrl.SetSel(-1,-1);  // end of line
        rCtrl.ReplaceSel(_T("\x0710 \x0717\n"));   // Syriac
        rCtrl.SetSel(-1,-1);  // end of line
        rCtrl.ReplaceSel(_T("more text\n"));

    // Done with the font.  Delete the font object.


Question by:roger_pearse
  • 4
  • 3
  • 3
LVL 11

Expert Comment

ID: 16315484
Well, I don't see what the problem is directly, but you definately shouldn't be deleting teh font while it is still in use.  You font should be a member variable of the class and never deleted until the control is destroyed or you SetFont a different font.  Otherwise the control will be pointing to a bad font handle (this applies to all windows, not just CRichEditCtrl).

Specifically for CRichEditCtrl you should be using SetSelectionCharFormat ( http://msdn2.microsoft.com/en-US/library/kwc5txzf(VS.80).aspx ) instead of SetFont.

Hope this helps.
LVL 22

Assisted Solution

mahesh1402 earned 1000 total points
ID: 16318425
You may refer this About display UNICODE characters in Edit Controls :

http://www.codeguru.com/cpp/cpp/cpp_mfc/general/article.php/c10285/ <==

refer CUnicodeDlg::SetControlsFont() function on above link to create and set UNICODE font

LVL 22

Expert Comment

ID: 16318453
as shown in above link you can create UNICODE font by using CreateFontIndirect() by passing LOGFONT type structure to it.

In LOGFONT strcuture there is lfCharSet parameter which allows you to set character set like GREEK_CHARSET etc.

Refer above article for more.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 16324893

I tried using the sample code supplied, and the same problem happened.  I added a couple of Syriac characters onto the unicode.txt file (editing using Notepad, get the characters from charmap), and changed the font in the code to Titus Cyberbit Basic, and they displayed; changed it to Estrangelo Edessa and it did not.

So I can only infer that I am not doing anything wildly daft; but why does it not work, I wonder?

LVL 11

Expert Comment

ID: 16325360
Did you try using Estrangelo Edessa in WordPad?  WordPad is basically just a CRichEditCtrl with a menu bar, so if it works in that you are doing something wrong, and if it doesn't work it is the font's problem.

Author Comment

ID: 16325488
Well, I can paste unicode characters from charmap in Estrangelo Edessa into Wordpad, and indeed into my application just fine.  It's purely when I try to write them to the Richtextbox in code.  That's why I felt that *I* was doing something wrong.  But the fact that the sample app. given by Mahesh has the same problem reading a file containing the characters suggests that it is not me.

This last suggested that something may be odd about the font.  Other Syriac fonts made by the same people (the 'Meltho' fonts for Syriac) are fine.

So I queried the SYRCOM forum for Syriac computing, and got an interesting response, although I don't know if it is relevant: "George Kiraz [the font author] explained to me that Edessa was the first font they made and when it shipped XP did not yet have Syriac capability fully so they labeled Edessa as an arabic font to make it work. The problem arises for me when I have a word document in Talada (which is the prettier font according to many anyway) which XP/Word    recognizes as Syriac and then if I change it to Edessa the boxes come up since Edessa is tagged as Arabic. The problem (at least within word) is solved by manually  changing the  language (tools>language) to either Syriac or Arabic so that it works."

I'm not sure that I entirely understand about fonts belonging to languages, tho.
LVL 11

Accepted Solution

KurtVon earned 1000 total points
ID: 16325949
I think what he means is that the font isn't tagged to contain the Syriac characters (even though it does) so anything that looks at those tags is automatically going to think the characters are blank.

If they paste into your RichEdit fine, then it is undoubtedly the way the text is being added.  Since other fonts work from code it must be the ReplaceSel function is doing some translation work "under the hood" to make sure characters are part of the font.  It appears pasting bypasses this.

Try using SetWindowText just to see if sticking teh characters in directly changes things.  You could also call EM_REPLACESEL directly: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_replacesel.asp
or EM_SETTEXTEX: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditmessages/em_settextex.asp

Author Comment

ID: 16330701
My PC melted last night, so it will be a few days before I can get another and get going again.  I will try these ideas!  Thanks, Roger.
LVL 22

Expert Comment

ID: 16332589
BTW  you tried to change font of your Dialog box ?


Author Comment

ID: 16340611
In the code?  I did.  I changed it from Lucida to first Titus (which worked) and then Estangelo (which did not).

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question