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?
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).
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With