From 4d35807a54c64f0dcd6302ace2a05d7bc2f4c491 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 8 Jun 2006 13:34:29 +0000 Subject: [PATCH] From Matt Green, fix to handling of centering of multi-line text entries. --- src/osgText/Text.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 909a64b0f..b85622b9f 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -377,6 +377,18 @@ String::iterator Text::computeLastCharacterOnLine(osg::Vec2& cursor, String::ite while (lastValidChar!=first && deliminatorSet.count(*lastValidChar)==0) { --lastValidChar; + + //Substract off glyphs from the cursor position (to correctly center text) + Font::Glyph* glyph = activefont->getGlyph(*lastValidChar); + if (glyph) + { + switch(_layout) + { + case LEFT_TO_RIGHT: cursor.x() -= glyph->getHorizontalAdvance() * wr; break; + case VERTICAL: cursor.y() += glyph->getVerticalAdvance() * hr; break; + case RIGHT_TO_LEFT: break; // nop. + } + } } if (first!=lastValidChar) { @@ -919,7 +931,6 @@ void Text::drawImplementation(osg::State& state) const } } - glNormal3fv(_normal.ptr()); glColor4fv(_color.ptr());