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
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
    LVL 11

    Expert Comment

    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 ( ) instead of SetFont.

    Hope this helps.
    LVL 22

    Assisted Solution

    You may refer this About display UNICODE characters in Edit Controls : <==

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

    LVL 22

    Expert Comment

    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.


    Author Comment


    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

    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

    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

    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:

    Author Comment

    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

    BTW  you tried to change font of your Dialog box ?


    Author Comment

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

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    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.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now