Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a unicode text in C#

My App displays English, Japanese and Chinese characters on a TextBox and a LinkLabel. Currently, I check if there are unicode characters and change the font to MS Mincho or else leave it in Tahoma.

Now MS Mincho displays Japanese properly, but for Chinese I have to use Sim Sun. How can I distinguish between the two?

How can I ensure that unicode text are displayed properly regardless of the font/language?

like image 766
Mugunth Avatar asked Sep 03 '09 01:09

Mugunth


3 Answers

If you have unicode characters for each of the text, using a font that supports unicode should cover it properly for you (e.g. Arial Unicode MS).

like image 175
shahkalpesh Avatar answered Sep 22 '22 15:09

shahkalpesh


You can't ensure that unicode text is displayed properly regardless of the font and language, because there is no single font that can render all possible unicode characters. You have to select a font that can display the unicode characters that you need to render.

like image 33
MusiGenesis Avatar answered Sep 24 '22 15:09

MusiGenesis


All strings in C# are Unicode. The English (Latin), Japanese and Chinese code points are just located in different code point ranges.

I think you have two options:

  • Find a Unicode font that contains characters for all code points in all three language.

  • Try to guess the language and choose a font that contains the characters for the code points in that language.

For option 2 you can look at the Unicode charts to find out where the different code points are and expand your algorithm to guess the language.

Example for Hiragana:

bool IsHiragana(char ch)
{
    return (ch >= '\u3040') && (ch <= '\u309f');
}

bool IsHiragana(string s)
{
    return s.Count(IsHiragana) > 0;
}
like image 37
dtb Avatar answered Sep 26 '22 15:09

dtb