Fixes to osgText to handle std::string correctly.

This commit is contained in:
Robert Osfield 2003-01-13 14:05:08 +00:00
parent 29f4fa713f
commit c3a7ce7352
3 changed files with 7 additions and 4 deletions

View File

@ -55,7 +55,7 @@ class OSGTEXT_EXPORT EncodedText : public osg::Referenced
Encoding getOverrideEncoding() const { return _overrideEncoding; }
Encoding getEncoding() const { return _encoding; }
void setText(const unsigned char* text);
void setText(const unsigned char* text, int length = -1);
std::vector<int>::const_iterator getUnicodeText() const { return _unicodeText.begin(); }
protected:

View File

@ -200,21 +200,24 @@ EncodedText::Encoding EncodedText::findEncoding(const unsigned char*& charString
return ENCODING_ASCII;
}
void EncodedText::setText(const unsigned char* text)
void EncodedText::setText(const unsigned char* text, int length)
{
_unicodeText.clear();
if (text != NULL)
{
const unsigned char* textStart = text;
if ((_overrideEncoding == ENCODING_SIGNATURE) ||
(_overrideEncoding == ENCODING_UTF16) ||
(_overrideEncoding == ENCODING_UTF32))
_encoding = findEncoding(text);
int character = getNextCharacter(text);
while (character)
int charCount = (int)(text-textStart);
while ((character) && (charCount <= length))
{
_unicodeText.push_back(character);
character = getNextCharacter(text);
charCount = (int)(text-textStart);
}
_unicodeText.push_back(0); //just making the null-termination explicit
}

View File

@ -505,7 +505,7 @@ setText(const std::string& text)
{
_text=text;
_initAlignment=false;
_encodedText->setText((const unsigned char*)_text.data());
_encodedText->setText((const unsigned char*)_text.data(),_text.size());
}
// Text
///////////////////////////////////////////////////////////////////////////////