From Eric Sokolwsky, "osgText is a useful node kit, but when longer paragraphs are displayed

on the screen, it looks more aesthetically pleasing to have a larger
gap between lines than is given by default. I added a new parameter,
lineSpacing, in the Text class to allow the line spacing to be adjustable
by the application. The default value is 0 meaning there is no extra
spacing given. The value should be given as a percentage of the character
height. A good value for longer paragraphs is 0.25 (25%) or more."
This commit is contained in:
Robert Osfield 2007-01-30 14:32:12 +00:00
parent 35c720420e
commit 77b9a7ae19
2 changed files with 22 additions and 4 deletions

View File

@ -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;

View File

@ -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....