From c3a7ce7352eb6621b254ecef4e336918cc01ce7e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 13 Jan 2003 14:05:08 +0000 Subject: [PATCH] Fixes to osgText to handle std::string correctly. --- include/osgText/EncodedText | 2 +- src/osgText/EncodedText.cpp | 7 +++++-- src/osgText/Text.cpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) 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 ///////////////////////////////////////////////////////////////////////////////