Updates to osgText to fix a crash on ikart.tff font available under Linux, the
bug was related to texel padding of the height not be accounted for in texture size calculation, but was used during populating the image data causing a mismatch.
This commit is contained in:
parent
b462845857
commit
f7a2567bca
@ -46,14 +46,14 @@ bool FTGLTextureFont::MakeGlyphList()
|
||||
|
||||
GetSize();
|
||||
GLuint totalMem;
|
||||
|
||||
if( textureHeight > maxTextSize)
|
||||
|
||||
if( textureHeight > (maxTextSize-padding*2))
|
||||
{
|
||||
numTextures = static_cast<int>( textureHeight / maxTextSize) + 1;
|
||||
numTextures = static_cast<int>( textureHeight / (maxTextSize-padding*2)) + 1;
|
||||
if( numTextures > 15) // FIXME
|
||||
numTextures = 15;
|
||||
|
||||
GLsizei heightRemain = NextPowerOf2( textureHeight % maxTextSize);
|
||||
GLsizei heightRemain = NextPowerOf2( textureHeight % (maxTextSize-padding*2));
|
||||
totalMem = ((maxTextSize * ( numTextures - 1)) + heightRemain) * textureWidth;
|
||||
|
||||
glGenTextures( numTextures, (GLuint*)&glTextureID[0]);
|
||||
@ -79,7 +79,8 @@ bool FTGLTextureFont::MakeGlyphList()
|
||||
}
|
||||
else
|
||||
{
|
||||
textureHeight = NextPowerOf2( textureHeight);
|
||||
|
||||
textureHeight = NextPowerOf2( textureHeight+padding*2);
|
||||
totalMem = textureWidth * textureHeight;
|
||||
|
||||
glGenTextures( numTextures, (GLuint*)&glTextureID[0]);
|
||||
@ -95,7 +96,6 @@ bool FTGLTextureFont::MakeGlyphList()
|
||||
return !err;
|
||||
}
|
||||
|
||||
|
||||
unsigned int FTGLTextureFont::FillGlyphs( unsigned int glyphStart, GLuint id, GLsizei width, GLsizei height, unsigned char* textdata)
|
||||
{
|
||||
int currentTextX = padding;
|
||||
@ -105,7 +105,7 @@ unsigned int FTGLTextureFont::FillGlyphs( unsigned int glyphStart, GLuint id, GL
|
||||
float currTextV = (float)padding / (float)height;
|
||||
|
||||
unsigned int n;
|
||||
|
||||
|
||||
for( n = glyphStart; n <= numGlyphs; ++n)
|
||||
{
|
||||
FT_Glyph* ftGlyph = face.Glyph( n, FT_LOAD_NO_HINTING);
|
||||
@ -136,6 +136,7 @@ unsigned int FTGLTextureFont::FillGlyphs( unsigned int glyphStart, GLuint id, GL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -143,13 +144,14 @@ unsigned int FTGLTextureFont::FillGlyphs( unsigned int glyphStart, GLuint id, GL
|
||||
void FTGLTextureFont::GetSize()
|
||||
{
|
||||
//work out the max width. Most likely maxTextSize
|
||||
textureWidth = NextPowerOf2( numGlyphs * glyphWidth);
|
||||
textureWidth = NextPowerOf2( (numGlyphs * glyphWidth) + padding*2);
|
||||
if( textureWidth > maxTextSize)
|
||||
{
|
||||
textureWidth = maxTextSize;
|
||||
}
|
||||
|
||||
int h = static_cast<int>( textureWidth / glyphWidth);
|
||||
int h = static_cast<int>( (textureWidth-padding*2) / glyphWidth);
|
||||
|
||||
textureHeight = (( numGlyphs / h) + 1) * glyphHeight;
|
||||
}
|
||||
|
||||
|
@ -33,14 +33,15 @@ bool FTGlyphContainer::Add( FTGlyph* tempGlyph)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
float FTGlyphContainer::Advance( unsigned int index, unsigned int next)
|
||||
{
|
||||
unsigned int left = face->CharIndex( index);
|
||||
unsigned int right = face->CharIndex( next);
|
||||
|
||||
|
||||
|
||||
float width = face->KernAdvance( left, right).x;
|
||||
width += glyphs[left]->Advance();
|
||||
if (left<glyphs.size()) width += glyphs[left]->Advance();
|
||||
|
||||
return width;
|
||||
}
|
||||
@ -57,7 +58,7 @@ FT_Vector& FTGlyphContainer::render( unsigned int index, unsigned int next, FT_V
|
||||
|
||||
if( !face->Error())
|
||||
{
|
||||
advance = glyphs[left]->Render( pen);
|
||||
if (left<glyphs.size()) advance = glyphs[left]->Render( pen);
|
||||
}
|
||||
|
||||
kernAdvance.x = advance + kernAdvance.x;
|
||||
|
@ -30,9 +30,9 @@ using namespace osgText;
|
||||
// define the default paths to look for fonts.
|
||||
// note delimator is : for unix, ; for windows.
|
||||
#if defined(__linux) || defined(__FreeBSD__) || defined (__sgi)
|
||||
static char* s_FontFilePath = "/usr/share/fonts/ttf:/usr/share/fonts/ttf/western:/usr/share/fonts/ttf/decoratives";
|
||||
static char* s_FontFilePath = ".:/usr/share/fonts/ttf:/usr/share/fonts/ttf/western:/usr/share/fonts/ttf/decoratives";
|
||||
#elif defined(WIN32)
|
||||
static char* s_FontFilePath = ".;";
|
||||
static char* s_FontFilePath = ".;C:/windows/fonts";
|
||||
#else
|
||||
static char* s_FontFilePath = ".:";
|
||||
#endif
|
||||
@ -528,9 +528,9 @@ calcBounds(Vec3* min,Vec3* max) const
|
||||
if(!_init)
|
||||
return;
|
||||
|
||||
int h=_font->getHeight();
|
||||
int w=_font->getWidth(_text.c_str());
|
||||
int descender=_font->getDescender();
|
||||
float h=_font->getHeight();
|
||||
float w=_font->getWidth(_text.c_str());
|
||||
float descender=_font->getDescender();
|
||||
|
||||
min->set(0,descender,0);
|
||||
max->set(w,h + descender ,0);
|
||||
@ -577,9 +577,9 @@ initAlignement(Vec3* min,Vec3* max)
|
||||
if(!_init)
|
||||
return;
|
||||
|
||||
int h=_font->getHeight();
|
||||
int w=_font->getWidth(_text.c_str());
|
||||
int descender=_font->getDescender();
|
||||
float h=_font->getHeight();
|
||||
float w=_font->getWidth(_text.c_str());
|
||||
float descender=_font->getDescender();
|
||||
|
||||
min->set(0,descender,0);
|
||||
max->set(w,h + descender ,0);
|
||||
@ -591,33 +591,33 @@ initAlignement(Vec3* min,Vec3* max)
|
||||
switch(_alignement)
|
||||
{
|
||||
case LEFT_TOP:
|
||||
_alignementPos.set(0,h,0);
|
||||
_alignementPos.set(0.0,h,0.0);
|
||||
break;
|
||||
case LEFT_CENTER:
|
||||
_alignementPos.set(0,h/2,0);
|
||||
_alignementPos.set(0.0,h/2.0,0.0);
|
||||
break;
|
||||
case LEFT_BOTTOM:
|
||||
_alignementPos.set(0,0,0);
|
||||
_alignementPos.set(0.0,0.0,0.0);
|
||||
break;
|
||||
|
||||
case CENTER_TOP:
|
||||
_alignementPos.set(w/2,h,0);
|
||||
_alignementPos.set(w/2.0,h,0.0);
|
||||
break;
|
||||
case CENTER_CENTER:
|
||||
_alignementPos.set(w/2,h/2,0);
|
||||
_alignementPos.set(w/2.0,h/2.0,0.0);
|
||||
break;
|
||||
case CENTER_BOTTOM:
|
||||
_alignementPos.set(w/2,0,0);
|
||||
_alignementPos.set(w/2.0,0.0,0.0);
|
||||
break;
|
||||
|
||||
case RIGHT_TOP:
|
||||
_alignementPos.set(w,h,0);
|
||||
_alignementPos.set(w,h,0.0);
|
||||
break;
|
||||
case RIGHT_CENTER:
|
||||
_alignementPos.set(w,h/2,0);
|
||||
_alignementPos.set(w,h/2.0,0.0);
|
||||
break;
|
||||
case RIGHT_BOTTOM:
|
||||
_alignementPos.set(w,0,0);
|
||||
_alignementPos.set(w,0.0,0.0);
|
||||
break;
|
||||
};
|
||||
_alignementPos=-_alignementPos;
|
||||
@ -630,33 +630,33 @@ initAlignement(Vec3* min,Vec3* max)
|
||||
switch(_alignement)
|
||||
{
|
||||
case LEFT_TOP:
|
||||
_alignementPos.set(0,h + descender,0);
|
||||
_alignementPos.set(0.0,h + descender,0.0);
|
||||
break;
|
||||
case LEFT_CENTER:
|
||||
_alignementPos.set(0,(max->y()-min->y()) /2 + descender,0);
|
||||
_alignementPos.set(0.0,(max->y()-min->y()) /2.0 + descender,0.0);
|
||||
break;
|
||||
case LEFT_BOTTOM:
|
||||
_alignementPos.set(0,descender,0);
|
||||
_alignementPos.set(0.0,descender,0.0);
|
||||
break;
|
||||
|
||||
case CENTER_TOP:
|
||||
_alignementPos.set(w/2,h + descender,0);
|
||||
_alignementPos.set(w/2.0,h + descender,0.0);
|
||||
break;
|
||||
case CENTER_CENTER:
|
||||
_alignementPos.set(w/2,(max->y()-min->y()) /2 + descender,0);
|
||||
_alignementPos.set(w/2.0,(max->y()-min->y()) /2.0 + descender,0.0);
|
||||
break;
|
||||
case CENTER_BOTTOM:
|
||||
_alignementPos.set(w/2,descender,0);
|
||||
_alignementPos.set(w/2.0,descender,0.0);
|
||||
break;
|
||||
|
||||
case RIGHT_TOP:
|
||||
_alignementPos.set(w,h + descender,0);
|
||||
_alignementPos.set(w,h + descender,0.0);
|
||||
break;
|
||||
case RIGHT_CENTER:
|
||||
_alignementPos.set(w,(max->y()-min->y()) /2 + descender,0);
|
||||
_alignementPos.set(w,(max->y()-min->y()) /2.0 + descender,0.0);
|
||||
break;
|
||||
case RIGHT_BOTTOM:
|
||||
_alignementPos.set(w,descender,0);
|
||||
_alignementPos.set(w,descender,0.0);
|
||||
break;
|
||||
};
|
||||
_alignementPos=-_alignementPos;
|
||||
|
Loading…
Reference in New Issue
Block a user