Moved handling of character aspect ratio into osgText::Style.

This commit is contained in:
Robert Osfield
2010-09-29 12:45:35 +00:00
parent 9bde24d3d2
commit dab1c79127
6 changed files with 40 additions and 29 deletions

View File

@@ -89,7 +89,7 @@ String::iterator Text::computeLastCharacterOnLine(osg::Vec2& cursor, String::ite
if (!activefont) return last;
float hr = _characterHeight/getFontHeight();
float wr = hr/_characterAspectRatio;
float wr = hr/getCharacterAspectRatio();
bool kerning = true;
unsigned int previous_charcode = 0;
@@ -252,7 +252,7 @@ void Text::computeGlyphRepresentation()
unsigned int lineNumber = 0;
float hr = _characterHeight/getFontHeight();
float wr = hr/_characterAspectRatio;
float wr = hr/getCharacterAspectRatio();
for(String::iterator itr=_text.begin();
itr!=_text.end();
@@ -509,7 +509,7 @@ void Text::computeGlyphRepresentation()
}
case VERTICAL:
{
startOfLine_coords.x() += _characterHeight/_characterAspectRatio * (1.0 + _lineSpacing);
startOfLine_coords.x() += _characterHeight/getCharacterAspectRatio() * (1.0 + _lineSpacing);
cursor = startOfLine_coords;
previous_charcode = 0;
// because _lineCount is the max vertical no. of characters....
@@ -662,7 +662,7 @@ void Text::computePositions(unsigned int contextID) const
float pixelSizeVector_w = M(3,2)*P23 + M(3,3)*P33;
float pixelSizeVert=(_characterHeight*sqrtf(scale_10.length2()))/(pixelSizeVector_w*0.701f);
float pixelSizeHori=(_characterHeight/_characterAspectRatio*sqrtf(scale_00.length2()))/(pixelSizeVector_w*0.701f);
float pixelSizeHori=(_characterHeight/getCharacterAspectRatio()*sqrtf(scale_00.length2()))/(pixelSizeVector_w*0.701f);
// avoid nasty math by preventing a divide by zero
if (pixelSizeVert == 0.0f)
@@ -673,7 +673,7 @@ void Text::computePositions(unsigned int contextID) const
if (_characterSizeMode==SCREEN_COORDS)
{
float scale_font_vert=_characterHeight/pixelSizeVert;
float scale_font_hori=_characterHeight/_characterAspectRatio/pixelSizeHori;
float scale_font_hori=_characterHeight/getCharacterAspectRatio()/pixelSizeHori;
if (P10<0)
scale_font_vert=-scale_font_vert;

View File

@@ -19,14 +19,12 @@ namespace osgText
{
Text3D::Text3D():
_style(0),
_renderMode(PER_GLYPH)
{
}
Text3D::Text3D(const Text3D & text3D, const osg::CopyOp & copyop):
osgText::TextBase(text3D, copyop),
_style(text3D._style),
_renderMode(text3D._renderMode)
{
computeGlyphRepresentation();
@@ -40,8 +38,7 @@ float Text3D::getCharacterDepth() const
void Text3D::setCharacterDepth(float characterDepth)
{
if (!_style) _style = new Style;
_style->setThicknessRatio(characterDepth / _characterHeight);
getOrCreateStyle()->setThicknessRatio(characterDepth / _characterHeight);
computeGlyphRepresentation();
}
@@ -434,7 +431,7 @@ void Text3D::computeGlyphRepresentation()
}
case VERTICAL:
{
startOfLine_coords.x() += _characterHeight / _characterAspectRatio * (1.0 + _lineSpacing);
startOfLine_coords.x() += _characterHeight / getCharacterAspectRatio() * (1.0 + _lineSpacing);
// because _lineCount is the max vertical no. of characters....
_lineCount = (_lineCount >linelength)?_lineCount:linelength;
break;
@@ -503,7 +500,7 @@ void Text3D::computePositions(unsigned int contextID) const
osg::Matrix& matrix = atc._matrix;
osg::Vec3 scaleVec(_characterHeight, _characterHeight / _characterAspectRatio, _characterHeight);
osg::Vec3 scaleVec(_characterHeight, _characterHeight / getCharacterAspectRatio(), _characterHeight);
matrix.makeTranslate(-_offset);
matrix.postMultScale(scaleVec);

View File

@@ -33,7 +33,6 @@ using namespace osgText;
TextBase::TextBase():
_fontSize(32,32),
_characterHeight(32),
_characterAspectRatio(1.0f),
_characterSizeMode(OBJECT_COORDS),
_maximumWidth(0.0f),
_maximumHeight(0.0f),
@@ -56,9 +55,9 @@ TextBase::TextBase():
TextBase::TextBase(const TextBase& textBase,const osg::CopyOp& copyop):
osg::Drawable(textBase,copyop),
_font(textBase._font),
_style(textBase._style),
_fontSize(textBase._fontSize),
_characterHeight(textBase._characterHeight),
_characterAspectRatio(textBase._characterAspectRatio),
_characterSizeMode(textBase._characterSizeMode),
_maximumWidth(textBase._maximumWidth),
_maximumHeight(textBase._maximumHeight),
@@ -104,20 +103,27 @@ void TextBase::setFont(const std::string& fontfile)
setFont(readRefFontFile(fontfile));
}
void TextBase::setFontResolution(unsigned int width, unsigned int height)
{
_fontSize = FontResolution(width,height);
computeGlyphRepresentation();
}
void TextBase::setCharacterSize(float height,float aspectRatio)
void TextBase::setCharacterSize(float height)
{
_characterHeight = height;
_characterAspectRatio = aspectRatio;
computeGlyphRepresentation();
}
void TextBase::setCharacterSize(float height, float aspectRatio)
{
if (getCharacterAspectRatio()!=aspectRatio)
{
getOrCreateStyle()->setWidthRatio(aspectRatio);
}
setCharacterSize(height);
}
void TextBase::setMaximumWidth(float maximumWidth)
{
_maximumWidth = maximumWidth;