Jump to content
  • Advertisement
Sign in to follow this  
ratha

Displaying Chinese Characters

This topic is 2842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!
I've set the Text to my label from an XML file. I need to set a chinese word to a label. Here is my XML file contents:

<?xml version="1.0" encoding="UTF-8" ?>
<Remember>??????????????????</Remember>

The chinese word is for test purpose only(may not be meaningful word). Here is my code for reading this tag and setting the text to a label.

XmlDocument ^ Config = gcnew XmlDocument;

if(System::IO::File::Exists("Config.xml"))
{
Config->Load("Config.xml");
}
XPathNavigator ^ nav = Config->CreateNavigator();
XPathNodeIterator ^ iter;
iter = nav->Select("download/Remember");
while(iter->MoveNext())
{
System::String ^ ConfigText = iter->Current->Value;
ConfigText->Trim();
}
System::Runtime::InteropServices::Marshal::StringToHGlobalUni(ConfigText);
m_pRemember->Text = ConfigText;

While I execute the program only boxes are displayed in place of the chinese characters. If I open the XML file in a browser, the chinese characters are displayed. What else to do to display the chinese language?

Share this post


Link to post
Share on other sites
Advertisement
What is m_pRemember? The standard Label control can display Chinese text.

That said, there are some oddities in your code; for example, you declare System::String ^ ConfigText inside the while loop but then access it outside the loop.

Speaking of which, System.String is immutable; calling Trim() doesn't modify the string, it returns a new instance that has been trimmed.

In addition, your sample XML file does not match your code - I presume the XML file should have a <download> node?

I'm also unsure as to why you use StringToHGlobalUni.

Share this post


Link to post
Share on other sites
Generally, if you're getting boxes instead of non-ascii characters it is because your font does not support them. Microsoft Word can be a good slapdash verification tool to play around with fonts and make sure everything is good on that end.

Share this post


Link to post
Share on other sites

Generally, if you're getting boxes instead of non-ascii characters it is because your font does not support them. Microsoft Word can be a good slapdash verification tool to play around with fonts and make sure everything is good on that end.

The WinForms controls typically support font substitution, so if the selected font doesn't contain the requisite glyphs it'll use a different font that does:

this.someLabel.Font = new Font("Comic Sans MS", 12);
this.someLabel.Text = "Hello, world: ?????????????????? foo bar baz";

If you look at Comic Sans MS using Character Map you'll see that none of those Chinese characters are available, yet the label renders correctly.

Share this post


Link to post
Share on other sites
Ah, good to know. My only experience with localization concerns was with Java, which had that issue.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!