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

Hello,

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

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
characters.

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;
VERIFY(font->CreateFont(
   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
    SetFont(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.
    font->DeleteObject();



}
------end----

roger_pearseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KurtVonCommented:
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.
0
mahesh1402Commented:
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

MAHESH
0
mahesh1402Commented:
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.

MAHESH
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

roger_pearseAuthor Commented:
Mahesh,

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?

Roger
0
KurtVonCommented:
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.
0
roger_pearseAuthor Commented:
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.
0
KurtVonCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
roger_pearseAuthor Commented:
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.
0
mahesh1402Commented:
BTW  you tried to change font of your Dialog box ?

MAHESH
0
roger_pearseAuthor Commented:
In the code?  I did.  I changed it from Lucida to first Titus (which worked) and then Estangelo (which did not).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.