SFML community forums
Bindings - other languages => DotNet => Topic started 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.
//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();
-
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?
string text = new string(new char[]{ '\u70B9','\u83DC' });
(quickly found on stackoverflow -- sorry if it's not correct)
-
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.- Standard characters (a-z, 1-0) work fine, i.e. /u0057 "W" is correctly displayed as "W"
- Some symbols work fine, i.e. /u00AE "®" works fine.
- 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 "?"
-
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?
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?
-
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.
Font font = new Font("mplus-1p-medium.ttf");
Text text = new Text(new string(new char[] { '\u4EBA', '\u4F11' }), font);
-
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.
-
I just took the OpenGL example and replaced line 28 with these two lines of code.
-
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.
-
@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?
-
Just only source code hosted in GIT repository, so we must build them ourselves in 32bit or 64bit up to target machine.