diff --git a/include/osgText/EncodedText b/include/osgText/EncodedText index 79dba6e76..cc2a18e8d 100644 --- a/include/osgText/EncodedText +++ b/include/osgText/EncodedText @@ -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::const_iterator getUnicodeText() const { return _unicodeText.begin(); } protected: diff --git a/src/osgText/EncodedText.cpp b/src/osgText/EncodedText.cpp index cc322b29f..01b5fbdd4 100644 --- a/src/osgText/EncodedText.cpp +++ b/src/osgText/EncodedText.cpp @@ -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 } diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index a27119b95..c55c58366 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -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 ///////////////////////////////////////////////////////////////////////////////