SFML community forums

Bindings - other languages => DotNet => Topic started by: Brendon on September 22, 2011, 11:25:55 pm

Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Brendon on September 22, 2011, 11:25:55 pm
I'm trying to display Japanese characters with .Net SFML2.  But instead of printing the characters, I'm just getting question marks ("????"). The font contains the necessary characters, and entering English characters works fine.

Anyone have any experience with displaying Japanese characters, or have any tips? The code seems fairly straight-forward.

Code: [Select]
//initialization
Font font = new Font(@"mplus-1p-medium.ttf");

string japanese = "練習モド";
Text text = new Text(japanese, font, 64);
text.Position = new Vector2(80, 200);
text.Color = Color.Black;

...

//rendering
renderWindow.Draw(text);
renderWindow.Display();
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Laurent on September 23, 2011, 07:49:58 am
What is the encoding of your source file? Is it compatible with what the compiler expects for Unicode characters?

Have you tried with Unicode values directly?
Code: [Select]
string text = new string(new char[]{ '\u70B9','\u83DC' });
(quickly found on stackoverflow -- sorry if it's not correct)
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Brendon on September 23, 2011, 09:08:03 am
To the best of my knowledge, my source file is unicode. I'm using Visual Studio 2008.

I ran some tests with the direct unicode values.
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Laurent on September 23, 2011, 09:24:39 am
Quote
To the best of my knowledge, my source file is unicode

Unicode is the name of the standard, which defines several encodings. Is it UTF-8? UTF-16? UTF-32?

Quote
Non-standard characters act strange, i.e. /u0165 "ť" is displayed as "t" (no accent).
Exotic characters become question marks, i.e. /u01B1 "Ʊ" and /u4EEE "仮" both are displayed as "?"

Ok, I'll do some tests. Can you send me the font that you use?
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Laurent on September 23, 2011, 01:40:59 pm
I downloaded the font that you use, and with characters that it actually contains (according to this page (http://www.fonts2u.com/m-1p-medium.font)), it works.
Code: [Select]
Font font = new Font("mplus-1p-medium.ttf");
Text text = new Text(new string(new char[] { '\u4EBA', '\u4F11' }), font);
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Brendon on September 25, 2011, 03:28:55 am
Thanks, Laurent-

I got the same font from a different place. Interestingly, the one I have is 1.2 mb, and the one you linked is 67 kb. I replaced my font with yours, but the same issue is appearing.

I'm guessing the problem is something with my code or my compiler.  Can you possibly post the source code for your quick test? I'm guessing it's not very different from mine, but I'd like to verify my code isn't doing anything differently.
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Laurent on September 25, 2011, 08:57:16 am
I just took the OpenGL example and replaced line 28 with these two lines of code.
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: philongxp on September 25, 2011, 03:18:55 pm
Have you try to use latest .Net SFML2 version from GIT repository?
I see you use Vector2 instead Vector2f for sprite position.
I'd got the same issue several months ago. And now it should work correctly.

The font file from Laurent link (67kb) have full Hiragana and Katakana character set and only few basic Kanji characters.
So it can display '\u4EBA', '\u4F11' for 人休  but can't display character 練習.
(http://i.imgur.com/Z0qXF.png)

And the font file 1.2mb you got with good Kanji set, it should work with 練習 character.
(http://i.imgur.com/iSxyM.png)

This is my Basic Test (http://www.mediafire.com/?u4z81fvk4kmua1a) code.
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: Brendon on September 25, 2011, 05:25:03 pm
@philongxp - you're right - thanks! I was using SFML2 from June 2011. I downloaded the dlls from your link and now my test works fine.

Slight hijack - just so I stay up to date with the builds, are there precompiled SFML2 + .Net libraries in the GIT repository, or do we currently build them ourselves via Cmake?
Title: Problem displaying Chinese/Japanese/Korean characters
Post by: philongxp on September 25, 2011, 06:12:43 pm
Just only source code hosted in GIT repository, so we must build them ourselves in 32bit or 64bit up to target machine.