Fixed a bug on the handling of empty EncodedText.
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user