rds1983 / Myra

UI Library for MonoGame, FNA and Stride
MIT License
742 stars 93 forks source link

Chinese characters not displaying - Font Issue? #469

Open benda opened 3 months ago

benda commented 3 months ago

If I set the Text property of a button to Chinese text, for example "新游戏", the characters are not displayed. If I mix Chinese and English, e.g. "abc新游戏xyz" the English characters are displayed but not the Chinese. I expect the Chinese characters to be displayed.

I realize this is a font issue, however, the following code doesn't fix it for Chinese fonts.

byte[] ttfData = File.ReadAllBytes("C:\windows\fonts\simsunb.ttf"); FontSystem ordinaryFontSystem = new FontSystem(); ordinaryFontSystem.AddFont(ttfData);
Label title = //removed code that retrieves title title.Font = ordinaryFontSystem.GetFont(12);

If instead of byte[] ttfData = File.ReadAllBytes("C:\windows\fonts\simsunb.ttf"); I use byte[] ttfData = File.ReadAllBytes("C:\windows\fonts\gabriola.ttf");

I can display Latin characters in Gabriola font. But why don't the Chinese characters appear in the SimSunB font? Both font ttf files exist on my machine.

In MonoGame itself, adding SpriteFont via the content pipeline and using SpriteBatch.DrawString works as expected, properly displaying the Chinese characters. The MonoGame SprintFont appears to be an incompatible implementation from Myra's SpriteFontBase (from FontStashSharp). Also with MonoGame when importing the font I needed to specify Character Regions, is that not necessary with FontStashSharp or am I missing a step?

CodeRabbit957 commented 1 month ago

Not all fonts support foreign language characters. I'm currently using a font I've added for Japanese characters. If I paste in the input "abc新游戏xyz", all the characters display with the exception of 戏. If the font you are using isn't displaying Chinese characters, you should try a font designed for Chinese characters. (Maybe Noto Sans Simplified Chinese.)