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...
probleme about chinese display and input,thanks a lot..
Moderators: CEGUI MVP, CEGUI Team
Re: probleme about chinese display and input,thanks a lot..
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.
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..
it works!! thank you so much!!
I know my mistake, and if I save the source code into UTF8 that works too...
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..
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?
Another problem:
When i type chinese edit,it break in writeXMLToStream fuction of CEGUIFont.cpp. What should i do to solve this problem?
The problem still exist
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 ?
To jingjie:
I do as you wrote,but it won't work. What else should i do ?
- Dalfy
- CEGUI Team (Retired)
- Posts: 130
- Joined: Tue Oct 11, 2005 16:13
- Location: Paris, FRANCE
- Contact:
Re: The problem still exist
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
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
Type chinese into editbox
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..
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~
{
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..
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 5 guests