Fixed a bug on the handling of empty EncodedText.

This commit is contained in:
Robert Osfield
2003-01-17 15:01:27 +00:00
parent f87dc60ddd
commit a86d519a89
5 changed files with 25 additions and 18 deletions

View File

@@ -56,7 +56,9 @@ class OSGTEXT_EXPORT EncodedText : public osg::Referenced
Encoding getEncoding() const { return _encoding; }
void setText(const unsigned char* text, int length = -1);
std::vector<int>::const_iterator getUnicodeText() const { return _unicodeText.begin(); }
std::vector<int>::const_iterator begin() const { return _unicodeText.begin(); }
std::vector<int>::const_iterator end() const { return _unicodeText.end(); }
protected:

View File

@@ -121,8 +121,8 @@ class OSGTEXT_EXPORT Text : public osg::Drawable
const osg::Vec3& getAlignmentPos() const { return _alignmentPos; };
void setEncodedText(EncodedText* encodedText) { _encodedText = encodedText; }
const EncodedText* getEncodedText() const { return _encodedText.get(); }
void setEncodedText(EncodedText* encodedText) { _encodedText = encodedText; }
const EncodedText* getEncodedText() const { return _encodedText.get(); }
protected:
@@ -155,7 +155,7 @@ class OSGTEXT_EXPORT Text : public osg::Drawable
int _boundingBoxType;
AxisAlignment _axisAlignment;
osg::ref_ptr<EncodedText> _encodedText;
osg::ref_ptr<EncodedText> _encodedText;
osg::Vec3 _pos;
osg::Vec3 _alignmentPos;

View File

@@ -141,17 +141,18 @@ float FTFont::Advance( const char* string)
return width;
}
float FTFont::Advance( std::vector<int>::const_iterator string)
float FTFont::Advance( std::vector<int>::const_iterator first,
std::vector<int>::const_iterator last)
{
// all are the same, a bit a hack
FTGlyphContainer* glyphList=_contextGlyphList[0];
std::vector<int>::const_iterator c = string;
float width = 0;
while( *c)
for (std::vector<int>::const_iterator c = first;
c!=last;
++c)
{
width += glyphList->Advance( *c, *(c + 1));
c++;
}
return width;
@@ -198,21 +199,22 @@ void FTFont::render( const wchar_t* string , unsigned int renderContext)
}
}
void FTFont::render( std::vector<int>::const_iterator string , unsigned int renderContext)
void FTFont::render( std::vector<int>::const_iterator first,
std::vector<int>::const_iterator last,
unsigned int renderContext)
{
FTGlyphContainer* glyphList=_contextGlyphList[renderContext];
std::vector<int>::const_iterator c = string;
FT_Vector kernAdvance;
pen.x = 0; pen.y = 0;
while( *c)
for (std::vector<int>::const_iterator c = first;
c!=last;
++c)
{
kernAdvance = glyphList->render( *c, *(c + 1), pen);
pen.x += kernAdvance.x;
pen.y += kernAdvance.y;
c++;
}
}

View File

@@ -119,7 +119,8 @@ class FTGL_EXPORT FTFont
* @param string a pointer to an array of decoded unicode characters
* @return advance width
*/
float Advance( std::vector<int>::const_iterator string);
float Advance( std::vector<int>::const_iterator first,
std::vector<int>::const_iterator last);
/**
* Renders a string of characters
@@ -135,7 +136,9 @@ class FTGL_EXPORT FTFont
* @param string unicode string to be output.
*/
// mrn@changes
virtual void render( std::vector<int>::const_iterator string , unsigned int renderContext=0);
virtual void render( std::vector<int>::const_iterator first,
std::vector<int>::const_iterator last,
unsigned int renderContext=0);
/**
* Renders a string of characters

View File

@@ -178,7 +178,7 @@ bool Font::create(osg::State& state)
void Font::output(osg::State& state, const EncodedText* text) const
{
if(_created)
_font->render(text->getUnicodeText(),state.getContextID());
_font->render(text->begin(),text->end(),state.getContextID());
else
{
// ahhhh, this is bit doddy, the draw is potentially
@@ -204,8 +204,8 @@ void Font::clear()
float Font::
getWidth(const EncodedText* text) const
{
if(_init && _created)
return _font->Advance(text->getUnicodeText());
if(_init && _created && text)
return _font->Advance(text->begin(),text->end());
else
return -1;
}