Index: src/osgText/Text.cpp
===================================================================
--- src/osgText/Text.cpp	(revision 7891)
+++ src/osgText/Text.cpp	(working copy)
@@ -29,7 +29,7 @@
 using namespace osg;
 using namespace osgText;
 
-//#define TREES_CODE_FOR_MAKING_SPACES_EDITABLE
+#define TREES_CODE_FOR_MAKING_SPACES_EDITABLE
 
 Text::Text():
     _color(1.0f,1.0f,1.0f,1.0f),
@@ -452,38 +452,50 @@
                     glyphquad._glyphs.push_back(glyph);
                     glyphquad._lineNumbers.push_back(lineNumber);
 
-                    // set up the coords of the quad
-                    glyphquad._coords.push_back(local+osg::Vec2(0.0f,height));
-                    glyphquad._coords.push_back(local+osg::Vec2(0.0f,0.0f));
-                    glyphquad._coords.push_back(local+osg::Vec2(width,0.0f));
-                    glyphquad._coords.push_back(local+osg::Vec2(width,height));
+                    osg::Vec2 mintc = glyph->getMinTexCoord();
+                    osg::Vec2 maxtc = glyph->getMaxTexCoord();
+                    osg::Vec2 vDiff = maxtc - mintc;
+                    float fHorizTCMargin = 1.0f / glyph->getTexture()->getTextureWidth();
+                    float fVertTCMargin = 1.0f / glyph->getTexture()->getTextureHeight();
+                    float fHorizQuadMargin = vDiff.x() == 0.0f ? 0.0f : width * fHorizTCMargin / vDiff.x();
+                    float fVertQuadMargin = vDiff.y() == 0.0f ? 0.0f : height * fVertTCMargin / vDiff.y();
+                    mintc.x() -= fHorizTCMargin;
+                    mintc.y() -= fVertTCMargin;
+                    maxtc.x() += fHorizTCMargin;
+                    maxtc.y() += fVertTCMargin;
 
-                    // set up the tex coords of the quad
-                    const osg::Vec2& mintc = glyph->getMinTexCoord();
-                    const osg::Vec2& maxtc = glyph->getMaxTexCoord();
-
                     glyphquad._texcoords.push_back(osg::Vec2(mintc.x(),maxtc.y()));
                     glyphquad._texcoords.push_back(osg::Vec2(mintc.x(),mintc.y()));
                     glyphquad._texcoords.push_back(osg::Vec2(maxtc.x(),mintc.y()));
                     glyphquad._texcoords.push_back(osg::Vec2(maxtc.x(),maxtc.y()));
 
+                    // set up the coords of the quad
+                    osg::Vec2 upLeft = local+osg::Vec2(0.0f-fHorizQuadMargin,height+fVertQuadMargin);
+                    osg::Vec2 lowLeft = local+osg::Vec2(0.0f-fHorizQuadMargin,0.0f-fVertQuadMargin);
+                    osg::Vec2 lowRight = local+osg::Vec2(width+fHorizQuadMargin,0.0f-fVertQuadMargin);
+                    osg::Vec2 upRight = local+osg::Vec2(width+fHorizQuadMargin,height+fVertQuadMargin);
+                    glyphquad._coords.push_back(upLeft);
+                    glyphquad._coords.push_back(lowLeft);
+                    glyphquad._coords.push_back(lowRight);
+                    glyphquad._coords.push_back(upRight);
+
                     // move the cursor onto the next character.
                     // also expand bounding box
                     switch(_layout)
                     {
                       case LEFT_TO_RIGHT:
                           cursor.x() += glyph->getHorizontalAdvance() * wr;
-                          _textBB.expandBy(osg::Vec3(local.x(),local.y(),0.0f)); //lower left corner
-                          _textBB.expandBy(osg::Vec3(cursor.x(),local.y()+height,0.0f)); //upper right corner
+                          _textBB.expandBy(osg::Vec3(lowLeft.x(), lowLeft.y(), 0.0f)); //lower left corner
+                          _textBB.expandBy(osg::Vec3(upRight.x(), upRight.y(), 0.0f)); //upper right corner
                           break;
                       case VERTICAL:
                           cursor.y() -= glyph->getVerticalAdvance() *hr;
-                          _textBB.expandBy(osg::Vec3(local.x(),local.y()+height,0.0f)); //upper left corner
-                          _textBB.expandBy(osg::Vec3(local.x()+width,cursor.y(),0.0f)); //lower right corner
+                          _textBB.expandBy(osg::Vec3(upLeft.x(),upLeft.y(),0.0f)); //upper left corner
+                          _textBB.expandBy(osg::Vec3(lowRight.x(),lowRight.y(),0.0f)); //lower right corner
                           break;
                       case RIGHT_TO_LEFT:
-                          _textBB.expandBy(osg::Vec3(local.x()+width,local.y(),0.0f)); //lower right corner
-                          _textBB.expandBy(osg::Vec3(cursor.x(),local.y()+height,0.0f)); //upper left corner
+                          _textBB.expandBy(osg::Vec3(lowRight.x(),lowRight.y(),0.0f)); //lower right corner
+                          _textBB.expandBy(osg::Vec3(upLeft.x(),upLeft.y(),0.0f)); //upper left corner
                           break;
                     }
 
