Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem displaying Chinese/Japanese/Korean characters  (Read 9408 times)

0 Members and 1 Guest are viewing this topic.

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
Problem displaying Chinese/Japanese/Korean characters
« 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();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem displaying Chinese/Japanese/Korean characters
« Reply #1 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)
Laurent Gomila - SFML developer

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
Problem displaying Chinese/Japanese/Korean characters
« Reply #2 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.
  • 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 "?"

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem displaying Chinese/Japanese/Korean characters
« Reply #3 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?
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem displaying Chinese/Japanese/Korean characters
« Reply #4 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), it works.
Code: [Select]
Font font = new Font("mplus-1p-medium.ttf");
Text text = new Text(new string(new char[] { '\u4EBA', '\u4F11' }), font);
Laurent Gomila - SFML developer

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
Problem displaying Chinese/Japanese/Korean characters
« Reply #5 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem displaying Chinese/Japanese/Korean characters
« Reply #6 on: September 25, 2011, 08:57:16 am »
I just took the OpenGL example and replaced line 28 with these two lines of code.
Laurent Gomila - SFML developer

philongxp

  • Newbie
  • *
  • Posts: 2
    • Yahoo Instant Messenger - hiryuuxp
    • View Profile
    • Email
Problem displaying Chinese/Japanese/Korean characters
« Reply #7 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 練習.


And the font file 1.2mb you got with good Kanji set, it should work with 練習 character.


This is my Basic Test code.

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
Problem displaying Chinese/Japanese/Korean characters
« Reply #8 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?

philongxp

  • Newbie
  • *
  • Posts: 2
    • Yahoo Instant Messenger - hiryuuxp
    • View Profile
    • Email
Problem displaying Chinese/Japanese/Korean characters
« Reply #9 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.

 

anything