probleme about chinese display and input,thanks a lot..

Forum for general chit-chat or off-topic discussion.

Moderators: CEGUI MVP, CEGUI Team

User avatar
snos
Just popping in
Just popping in
Posts: 4
Joined: Sun Oct 09, 2005 06:46

probleme about chinese display and input,thanks a lot..

Postby snos » Tue Oct 11, 2005 03:51

I have some problem in chinese display and input in CEGUI,
as in the CEGUIchinesedemo i add a font to scheme and load font with following code:

in the font xml:
<?xml version="1.0" ?>
<Font Name="mingliu" Filename="../datafiles/fonts/mingliu.ttc" Type="Dynamic" Size="12" NativeHorzRes="800" NativeVertRes="600" AutoScaled="true">
<GlyphSet Glyphs="你好世界退出演示"/>
</Font>

in the source code:
SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"../datafiles/schemes/TaharezLook.scheme");
System::getSingleton().setDefaultFont((CEGUI::utf8*)"mingliu");
CEGUI::Font* font = CEGUI::FontManager::getSingleton().getFont((CEGUI::utf8*)"mingliu");
font->setAutoScalingEnabled(true);
font->setNativeResolution(Size(800, 600));
when using font:
btn->setText((CEGUI::utf8*)"退出");

as the result the words"退出"never show up:
could you give me some advice about my error??
thanks a lot...

User avatar
jingjie
Just popping in
Just popping in
Posts: 3
Joined: Mon Oct 03, 2005 03:18

Re: probleme about chinese display and input,thanks a lot..

Postby jingjie » Tue Oct 11, 2005 07:58

your problem about chinese display is that you don't tranfer your string into utf8 Format.
I has two ways to support you.
First Way
if your project is Unicode Set, you have to trander Unicode into UTF8.
example :
//unicode->utf8

std::wstring szWstring(L"你好,世界!" );
char *szUtf8String = NULL;
int iLengthAnsiString = 0;
iLengthAnsiString = WideCharToMultiByte(CP_UTF8, 0,szWstring.c_str(), szWstring.capacity(), NULL, 0, NULL, NULL);
szUtf8String = new char[ iLengthAnsiString];
memset(szUtf8String, 0, sizeof(char)*(iLengthAnsiString));
WideCharToMultiByte(CP_UTF8, 0,szWstring.c_str(), szWstring.length(), szUtf8String, iLengthAnsiString, NULL, NULL);
fwnd1->setText((CEGUI::utf8*)szUtf8String);
delete [] szUtf8String;
szUtf8String = NULL;

Second Way
if your project is Multibyte Set, you must to trander Ansi into UTF8.
example :

int AnsiToUtf8(char *szAnsi, char *szUtf8 )
{
wchar_t *szUnicode = NULL;
int iLengthUnicode = 0;
iLengthUnicode = MultiByteToWideChar(CP_ACP, 0, szAnsi, (int)strlen(szAnsi), NULL, 0);
szUnicode = new wchar_t[ iLengthUnicode ];
memset(szUnicode, 0, sizeof(wchar_t)*(iLengthUnicode));
MultiByteToWideChar(CP_ACP, 0, szAnsi, (int)strlen(szAnsi), szUnicode, iLengthUnicode);

char *szUtf8String = NULL;
int iLengthAnsiString = 0;
iLengthAnsiString = WideCharToMultiByte(CP_UTF8, 0, szUnicode, iLengthUnicode, NULL, 0, NULL, NULL);
szUtf8String = new char[ iLengthAnsiString];
memset(szUtf8String, 0, sizeof(char)*(iLengthAnsiString));
WideCharToMultiByte(CP_UTF8, 0, szUnicode, iLengthUnicode, szUtf8String, iLengthAnsiString, NULL, NULL);

if(szUtf8 )
{
memcpy(szUtf8, szUtf8String, (iLengthAnsiString));
}

if(szUnicode) {delete[] szUnicode; szUnicode = NULL;}
if(szUtf8String) {delete[] szUtf8String; szUtf8String = NULL;}

return iLengthAnsiString;
}

//Ansi->unicode->utf8
char* szutf8 = new char[AnsiToUtf8("你好,世界!",0)];
AnsiToUtf8("你好,世界!",szutf8 );
fwnd1->setText((CEGUI::utf8*)szutf8 );
delete [] szutf8;
I suggest you use firstway,because unicode is multi-language supported sulution.

User avatar
snos
Just popping in
Just popping in
Posts: 4
Joined: Sun Oct 09, 2005 06:46

Re: probleme about chinese display and input,thanks a lot..

Postby snos » Wed Oct 12, 2005 04:08

it works!! :D thank you so much!!
I know my mistake, and if I save the source code into UTF8 that works too...

chybin
Just popping in
Just popping in
Posts: 8
Joined: Fri Jun 02, 2006 10:20
Contact:

Re: probleme about chinese display and input,thanks a lot..

Postby chybin » Tue Jun 13, 2006 09:58

I do as you ,but it still can't work!!

Another problem:

When i type chinese edit,it break in writeXMLToStream fuction of CEGUIFont.cpp. What should i do to solve this problem?

User avatar
Dalfy
CEGUI Team (Retired)
Posts: 130
Joined: Tue Oct 11, 2005 16:13
Location: Paris, FRANCE
Contact:

Postby Dalfy » Tue Jun 13, 2006 10:05

Which is the version you are using ?

chybin
Just popping in
Just popping in
Posts: 8
Joined: Fri Jun 02, 2006 10:20
Contact:

The problem still exist

Postby chybin » Tue Jun 13, 2006 10:22

When typing chinese into edit,It will break in writeXMLToStream of ceguifont.cpp.

To jingjie:
I do as you wrote,but it won't work. What else should i do ?

User avatar
Dalfy
CEGUI Team (Retired)
Posts: 130
Joined: Tue Oct 11, 2005 16:13
Location: Paris, FRANCE
Contact:

Re: The problem still exist

Postby Dalfy » Tue Jun 13, 2006 12:12

chybin wrote:When typing chinese into edit,It will break in writeXMLToStream of ceguifont.cpp.

Which version of CEGUI are you using ?

chybin
Just popping in
Just popping in
Posts: 8
Joined: Fri Jun 02, 2006 10:20
Contact:

Re: The problem still exist

Postby chybin » Wed Jun 14, 2006 01:14

Dalfy wrote:
chybin wrote:When typing chinese into edit,It will break in writeXMLToStream of ceguifont.cpp.

Which version of CEGUI are you using ?



cegui_mk-0.4.0-deps-vc71-xerces.zip

User avatar
Dalfy
CEGUI Team (Retired)
Posts: 130
Joined: Tue Oct 11, 2005 16:13
Location: Paris, FRANCE
Contact:

Postby Dalfy » Wed Jun 14, 2006 06:06

This version of CEGUI does not process correcly the XML export its fixed in HEAD of trunk. However I don't see why you need to use writeXMLToStream. only editing tools needs them or for dumping.

chybin
Just popping in
Just popping in
Posts: 8
Joined: Fri Jun 02, 2006 10:20
Contact:

Type chinese into editbox

Postby chybin » Mon Jun 19, 2006 09:48

Dalfy wrote:This version of CEGUI does not process correcly the XML export its fixed in HEAD of trunk. However I don't see why you need to use writeXMLToStream. only editing tools needs them or for dumping.


I have not used writexml to stream, it is called by cegui system when i type chinese into editbox.

wang37921
Just popping in
Just popping in
Posts: 20
Joined: Thu Dec 24, 2009 11:22
Contact:

Re: probleme about chinese display and input,thanks a lot..

Postby wang37921 » Sat May 22, 2010 15:11

CEGUI::String AnsiToUtf8( char *szAnsi )
{
wchar_t *szUnicode = NULL;
int iLengthUnicode = 0;
iLengthUnicode = MultiByteToWideChar(CP_ACP, 0, szAnsi, (int)strlen(szAnsi), NULL, 0);
iLengthUnicode = MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, NULL, 0);

copy from MSDN:
MultiByteToWideChar or WideCharToMultiByte
the fourth parameter:If this value is –1, the string is assumed to be null-terminated and the length is calculated automatically.

strlen:
Return Values
Each of these functions returns the number of characters in string, excluding the terminal NULL. No return value is reserved to indicate an error.

so,the function has a little problem, when i input "王". But, when i input "你好",it can work~

wang37921
Just popping in
Just popping in
Posts: 20
Joined: Thu Dec 24, 2009 11:22
Contact:

Re: probleme about chinese display and input,thanks a lot..

Postby wang37921 » Sat May 22, 2010 15:16

Code: Select all

CEGUI::String AnsiToUtf8( char *szAnsi )
{
   wchar_t *szUnicode = NULL;
   int iLengthUnicode = 0;
   //iLengthUnicode = MultiByteToWideChar(CP_ACP, 0, szAnsi, (int)strlen(szAnsi), NULL, 0);
   iLengthUnicode = MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, NULL, 0);
   szUnicode = new wchar_t[ iLengthUnicode ];
   memset(szUnicode, 0, sizeof(wchar_t)*(iLengthUnicode));
   //MultiByteToWideChar(CP_ACP, 0, szAnsi, (int)strlen(szAnsi), szUnicode, iLengthUnicode);
   MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, szUnicode, iLengthUnicode);

   char *szUtf8String = NULL;
   int iLengthAnsiString = 0;
   iLengthAnsiString = WideCharToMultiByte(CP_UTF8, 0, szUnicode, iLengthUnicode, NULL, 0, NULL, NULL);
   szUtf8String = new char[ iLengthAnsiString];
   memset(szUtf8String, 0, sizeof(char)*(iLengthAnsiString));
   WideCharToMultiByte(CP_UTF8, 0, szUnicode, iLengthUnicode, szUtf8String, iLengthAnsiString, NULL, NULL);

   CEGUI::String rs((CEGUI::utf8*)szUtf8String);

   if(szUnicode) {delete[] szUnicode; szUnicode = NULL;}
   if(szUtf8String) {delete[] szUtf8String; szUtf8String = NULL;}

   return rs;
}


Return to “Offtopic Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests