diff --git a/include/osgText/Text b/include/osgText/Text index 6f37b36bf..e88331a38 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -119,12 +119,21 @@ public: /** Set the maximum height of the text box. * With horizontal layouts any characters which do not fit are wrapped around. * 0 or negative values indicate that no maximum height is set, lines can be as long as - * they need be to fit thre required text*/ + * they need be to fit the required text*/ void setMaximumHeight(float maximumHeight); /** Get the maximum height of the text box.*/ float getMaximumHeight() const { return _maximumHeight; } + /** Set the line spacing of the text box, given as a percentage of + * the character height. The default value is 0 for backward + * compatibility. For longer paragraphs of text, a value of at + * least 25% (i.e. set line spacing to 0.25) is recommended. */ + void setLineSpacing(float lineSpacing); + + /** Get the line spacing of the text box. */ + float getLineSpacing() const { return _lineSpacing; } + /** Set the position of text.*/ @@ -522,6 +531,7 @@ protected: CharacterSizeMode _characterSizeMode; float _maximumWidth; float _maximumHeight; + float _lineSpacing; String _text; osg::Vec3 _position; diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 10aff1282..b84202660 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -39,6 +39,7 @@ Text::Text(): _characterSizeMode(OBJECT_COORDS), _maximumWidth(0.0f), _maximumHeight(0.0f), + _lineSpacing(0.0f), _alignment(BASE_LINE), _autoRotateToScreen(false), _layout(LEFT_TO_RIGHT), @@ -72,6 +73,7 @@ Text::Text(const Text& text,const osg::CopyOp& copyop): _characterSizeMode(text._characterSizeMode), _maximumWidth(text._maximumWidth), _maximumHeight(text._maximumHeight), + _lineSpacing(text._lineSpacing), _text(text._text), _position(text._position), _alignment(text._alignment), @@ -147,6 +149,12 @@ void Text::setMaximumHeight(float maximumHeight) _maximumHeight = maximumHeight; computeGlyphRepresentation(); } + +void Text::setLineSpacing(float lineSpacing) +{ + _lineSpacing = lineSpacing; + computeGlyphRepresentation(); +} void Text::setText(const String& text) @@ -693,7 +701,7 @@ void Text::computeGlyphRepresentation() { case LEFT_TO_RIGHT: { - startOfLine_coords.y() -= _characterHeight; + startOfLine_coords.y() -= _characterHeight * (1.0 + _lineSpacing); cursor = startOfLine_coords; previous_charcode = 0; _lineCount++; @@ -701,7 +709,7 @@ void Text::computeGlyphRepresentation() } case RIGHT_TO_LEFT: { - startOfLine_coords.y() -= _characterHeight; + startOfLine_coords.y() -= _characterHeight * (1.0 + _lineSpacing); cursor = startOfLine_coords; previous_charcode = 0; _lineCount++; @@ -709,7 +717,7 @@ void Text::computeGlyphRepresentation() } case VERTICAL: { - startOfLine_coords.x() += _characterHeight/_characterAspectRatio; + startOfLine_coords.x() += _characterHeight/_characterAspectRatio * (1.0 + _lineSpacing); cursor = startOfLine_coords; previous_charcode = 0; // because _lineCount is the max vertical no. of characters....