Page 1 of 1

[Solved] UTF-8 Files and CEGUI::String

Posted: Sun May 22, 2005 20:32
by Ceacy
Hello,
I have a problem with files containing UTF-8 encoded text and CEGUI : as i have to use std::ifstream and std;;string, I lose all accentuated characters ...

Code: Select all

std::ifstream fTextIntro( "intro_text.txt" );
   CEGUI::String strTextIntro;
   std::string strLine;
   if( fTextIntro )
   {
      while( std::getline( fTextIntro, strLine ) )
      {
         strTextIntro += strLine;
         strTextIntro += '\n';
      }
   }

   CEGUI::MultiLineEditbox* editbox = dynamic_cast<CEGUI::MultiLineEditbox*>( mSheet->getChild( (CEGUI::utf8*) "TextIntro" ) );
      editbox->setText( strTextIntro );


I also tried with std::wifstream and std::wstring, but there it seems to be not way to convert wifstream to CEGUI::String ... so i have no ideas any more :oops:

If someone could help me ... ;)

Re: UTF-8 Files and CEGUI::String

Posted: Tue May 24, 2005 19:49
by Ceacy
Nobody can help me ? :(

Re: UTF-8 Files and CEGUI::String

Posted: Tue May 24, 2005 20:31
by lindquist
In which manner do loose the accentuated characters ?

Are they not rendered?

Are you loading the appropriate glyphs when initialising your font ?

Does it work if you hardcode the strings and save your source in UTF8 format?

Some more information is needed to help you out of the blue!

Re: UTF-8 Files and CEGUI::String

Posted: Wed May 25, 2005 12:07
by Ceacy
They 're "just" not rendered. I've done some tests, and it seems that the text is correctly converted in CEGUI::String ; however, accentuated characters are not displayed :

Code: Select all

CEGUI::FontManager::getSingleton().createFont( "ForgottenUncial", "forgotten_uncial.ttf", 12, 0 );
// [...]
mGUISystem->setDefaultFont( (CEGUI::utf8*) "ForgottenUncial" ); // this font supports accentuated characters like "é", "è" ...
// [...]
std::ifstream fTextIntro( "intro_text.txt" );
   CEGUI::String strTextIntro;
   String strLine;
   if( fTextIntro )
   {
      while( std::getline( fTextIntro, strLine ) )
      {
         strTextIntro += (CEGUI::utf8*) strLine.c_str();
         strTextIntro += '\n';
      }
   }
   CEGUI::MultiLineEditbox* editbox = dynamic_cast<CEGUI::MultiLineEditbox*>( mSheet->getChild( (CEGUI::utf8*) "TextIntro" ) );
      editbox->setText( strTextIntro );
   
   std::cout << strTextIntro << std::endl;
   std::cout << editbox->getText() << std::endl;


Returns, in console :
Un monde, plat. Un monde où les Dieux sont comme tout le monde, mais en pire. Un monde où même une pluie de météorites violettes en forme de canards semblerait banale. Un monde où, par endroit, il est recommandé de vérifier au matin qu'on a bien la même forme que la veille.
Un monde où croire en un dieu, c'est le faire exister. Un monde de fous.

Un monde, plat. Un monde où les Dieux sont comme tout le monde, mais en pire. Un monde où même une pluie de météorites violettes en forme de canards semblerait banale. Un monde où, par endroit, il est recommandé de vérifier au matin qu'on a bien la même forme que la veille.
Un monde où croire en un dieu, c'est le faire exister. Un monde de fous.


But, in the editbox, i see :
Un monde, plat. Un monde o les Dieux sont comme tout le monde, mais en pire. Un monde o mme une pluie de mtorites violettes en forme de canards semblerait banale. Un monde o, par endroit, il est recommand de vrifier au matin qu'on a bien la mme forme que la veille.
Un monde o croire en un dieu, c'est le faire exister. Un monde de fous.


Any idea ?


---

EDIT : Oh. I've serached the forum with "glyphs" keyword, and I found.

Code: Select all

CEGUI::Font* font = CEGUI::System::getSingleton().getDefaultFont();
   CEGUI::String glyphSets( font->getAvailableGlyphs() );
      glyphSets += (CEGUI::utf8*) "éèêëàùûôöîï" ;
      font->defineFontGlyphs( glyphSets );

Sorry ...