Page 1 of 1

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

Posted: Tue Oct 11, 2005 03:51
by snos
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...

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

Posted: Tue Oct 11, 2005 07:58
by jingjie
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.

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

Posted: Wed Oct 12, 2005 04:08
by snos
it works!! :D thank you so much!!
I know my mistake, and if I save the source code into UTF8 that works too...

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

Posted: Tue Jun 13, 2006 09:58
by chybin
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?

Posted: Tue Jun 13, 2006 10:05
by Dalfy
Which is the version you are using ?

The problem still exist

Posted: Tue Jun 13, 2006 10:22
by chybin
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 ?

Re: The problem still exist

Posted: Tue Jun 13, 2006 12:12
by Dalfy
chybin wrote:When typing chinese into edit,It will break in writeXMLToStream of ceguifont.cpp.

Which version of CEGUI are you using ?

Re: The problem still exist

Posted: Wed Jun 14, 2006 01:14
by chybin
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

Posted: Wed Jun 14, 2006 06:06
by Dalfy
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.

Type chinese into editbox

Posted: Mon Jun 19, 2006 09:48
by chybin
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.

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

Posted: Sat May 22, 2010 15:11
by wang37921
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~

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

Posted: Sat May 22, 2010 15:16
by wang37921

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;
}