From Tree, added support for using wchar_t strings with osg::Text/EncodedText.

This commit is contained in:
Robert Osfield
2003-02-10 15:01:27 +00:00
parent ebb31fb339
commit 1b08b02df2
4 changed files with 43 additions and 4 deletions

View File

@@ -231,3 +231,28 @@ void EncodedText::setOverrideEncoding(EncodedText::Encoding encoding)
//NB As the original text is not cached we cannot confirm any ENCODING_SIGNATURE until text is set again
}
}
std::string EncodedText::convertWideString(const wchar_t* text)
{
std::string utf8string;
const wchar_t* pChars = text;
int currentChar = *pChars;
while (currentChar)
{
if (currentChar < 0x80)
utf8string+=(char)currentChar;
else if (currentChar < 0x800)
{
utf8string+=(char)(0xc0 | (currentChar>>6));
utf8string+=(char)(0x80 | currentChar & 0x3f);
}
else
{
utf8string+=(char)(0xe0 | (currentChar>>12));
utf8string+=(char)(0x80 | (currentChar>>6) & 0x3f);
utf8string+=(char)(0x80 | currentChar & 0x3f);
}
currentChar = *(++pChars);
}
return utf8string;
}