From a86d519a8966e4e5fde032544f3e3c9aaacc9bb5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 17 Jan 2003 15:01:27 +0000 Subject: [PATCH] Fixed a bug on the handling of empty EncodedText. --- include/osgText/EncodedText | 4 +++- include/osgText/Text | 6 +++--- src/osgText/FTFont.cpp | 20 +++++++++++--------- src/osgText/FTFont.h | 7 +++++-- src/osgText/Font.cpp | 6 +++--- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/osgText/EncodedText b/include/osgText/EncodedText index cc2a18e8d..ac5a37bc4 100644 --- a/include/osgText/EncodedText +++ b/include/osgText/EncodedText @@ -56,7 +56,9 @@ class OSGTEXT_EXPORT EncodedText : public osg::Referenced Encoding getEncoding() const { return _encoding; } void setText(const unsigned char* text, int length = -1); - std::vector::const_iterator getUnicodeText() const { return _unicodeText.begin(); } + + std::vector::const_iterator begin() const { return _unicodeText.begin(); } + std::vector::const_iterator end() const { return _unicodeText.end(); } protected: diff --git a/include/osgText/Text b/include/osgText/Text index 1eeeafef2..1c3b529c8 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -121,8 +121,8 @@ class OSGTEXT_EXPORT Text : public osg::Drawable const osg::Vec3& getAlignmentPos() const { return _alignmentPos; }; - void setEncodedText(EncodedText* encodedText) { _encodedText = encodedText; } - const EncodedText* getEncodedText() const { return _encodedText.get(); } + void setEncodedText(EncodedText* encodedText) { _encodedText = encodedText; } + const EncodedText* getEncodedText() const { return _encodedText.get(); } protected: @@ -155,7 +155,7 @@ class OSGTEXT_EXPORT Text : public osg::Drawable int _boundingBoxType; AxisAlignment _axisAlignment; - osg::ref_ptr _encodedText; + osg::ref_ptr _encodedText; osg::Vec3 _pos; osg::Vec3 _alignmentPos; diff --git a/src/osgText/FTFont.cpp b/src/osgText/FTFont.cpp index 3c25b97e7..9aa621efc 100644 --- a/src/osgText/FTFont.cpp +++ b/src/osgText/FTFont.cpp @@ -141,17 +141,18 @@ float FTFont::Advance( const char* string) return width; } -float FTFont::Advance( std::vector::const_iterator string) +float FTFont::Advance( std::vector::const_iterator first, + std::vector::const_iterator last) { // all are the same, a bit a hack FTGlyphContainer* glyphList=_contextGlyphList[0]; - std::vector::const_iterator c = string; float width = 0; - while( *c) + for (std::vector::const_iterator c = first; + c!=last; + ++c) { width += glyphList->Advance( *c, *(c + 1)); - c++; } return width; @@ -198,21 +199,22 @@ void FTFont::render( const wchar_t* string , unsigned int renderContext) } } -void FTFont::render( std::vector::const_iterator string , unsigned int renderContext) +void FTFont::render( std::vector::const_iterator first, + std::vector::const_iterator last, + unsigned int renderContext) { FTGlyphContainer* glyphList=_contextGlyphList[renderContext]; - std::vector::const_iterator c = string; FT_Vector kernAdvance; pen.x = 0; pen.y = 0; - while( *c) + for (std::vector::const_iterator c = first; + c!=last; + ++c) { kernAdvance = glyphList->render( *c, *(c + 1), pen); pen.x += kernAdvance.x; pen.y += kernAdvance.y; - - c++; } } diff --git a/src/osgText/FTFont.h b/src/osgText/FTFont.h index 481847887..d157a30db 100644 --- a/src/osgText/FTFont.h +++ b/src/osgText/FTFont.h @@ -119,7 +119,8 @@ class FTGL_EXPORT FTFont * @param string a pointer to an array of decoded unicode characters * @return advance width */ - float Advance( std::vector::const_iterator string); + float Advance( std::vector::const_iterator first, + std::vector::const_iterator last); /** * Renders a string of characters @@ -135,7 +136,9 @@ class FTGL_EXPORT FTFont * @param string unicode string to be output. */ // mrn@changes - virtual void render( std::vector::const_iterator string , unsigned int renderContext=0); + virtual void render( std::vector::const_iterator first, + std::vector::const_iterator last, + unsigned int renderContext=0); /** * Renders a string of characters diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 5e677c394..333e9a730 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -178,7 +178,7 @@ bool Font::create(osg::State& state) void Font::output(osg::State& state, const EncodedText* text) const { if(_created) - _font->render(text->getUnicodeText(),state.getContextID()); + _font->render(text->begin(),text->end(),state.getContextID()); else { // ahhhh, this is bit doddy, the draw is potentially @@ -204,8 +204,8 @@ void Font::clear() float Font:: getWidth(const EncodedText* text) const { - if(_init && _created) - return _font->Advance(text->getUnicodeText()); + if(_init && _created && text) + return _font->Advance(text->begin(),text->end()); else return -1; }