From Mathias Fröhlich, "Attached is a small change that makes the txf loader render the same resulting

text than an other well known txf loader. That means drawing them one on top
of the other I can only see differences due to different mipmapping ...

That is it introduces an additional gap of 0.1*height between the glyphs.
There is an additional mapping between upper and lowercase characters if one
of them is not available in the txf file.
And we have an artificial blank character that is very often missing in txf
files."
This commit is contained in:
Robert Osfield 2007-01-22 09:28:31 +00:00
parent 89cb2a438c
commit 24bc488205

View File

@ -91,9 +91,33 @@ osgText::Font::Glyph*
TXFFont::getGlyph(unsigned int charcode)
{
GlyphMap::iterator i = _chars.find(charcode);
if (i == _chars.end())
return 0;
return i->second.get();
if (i != _chars.end())
return i->second.get();
// ok, not available, we have an additional chance with some translations
// That is to make the loader compatible with an other prominent one
if (charcode >= 'A' && charcode <= 'Z')
{
i = _chars.find(charcode - 'A' + 'a');
if (i != _chars.end())
{
_chars[charcode] = i->second;
addGlyph(i->second->s(), i->second->t(), charcode, i->second.get());
return i->second.get();
}
}
else if (charcode >= 'a' && charcode <= 'z')
{
i = _chars.find(charcode - 'a' + 'A');
if (i != _chars.end())
{
_chars[charcode] = i->second;
addGlyph(i->second->s(), i->second->t(), charcode, i->second.get());
return i->second.get();
}
}
return 0;
}
bool
@ -208,6 +232,10 @@ TXFFont::loadFont(std::istream& stream)
for (unsigned i = 0; i < glyphs.size(); ++i)
{
// have a special one for that
if (glyphs[i].ch == ' ')
continue;
// add the characters ...
osgText::Font::Glyph* glyph = new osgText::Font::Glyph;
@ -239,8 +267,7 @@ TXFFont::loadFont(std::istream& stream)
float texToVertX = float(glyphs[i].width)/width;
float texToVertY = float(glyphs[i].height)/height;
glyph->setHorizontalAdvance(glyphs[i].advance);
glyph->setHorizontalAdvance(glyphs[i].advance + 0.1f*maxheight);
glyph->setHorizontalBearing(osg::Vec2((glyphs[i].x_off - 0.5f)*texToVertX,
(glyphs[i].y_off - 0.5f)*texToVertY));
glyph->setVerticalAdvance(sourceHeight);
@ -251,5 +278,30 @@ TXFFont::loadFont(std::istream& stream)
addGlyph(width, height, glyphs[i].ch, glyph);
}
// insert a trivial blank character
osgText::Font::Glyph* glyph = new osgText::Font::Glyph;
unsigned margin = _facade->getGlyphImageMargin();
unsigned width = 1 + 2*margin;
unsigned height = 1 + 2*margin;
glyph->allocateImage(width, height, 1, GL_ALPHA, GL_UNSIGNED_BYTE);
glyph->setInternalTextureFormat(GL_ALPHA);
for (unsigned k = 0; k < width; ++k)
{
for (unsigned l = 0; l < height; ++l)
{
*glyph->data(k, l) = 0;
}
}
glyph->setHorizontalAdvance(0.5f*_facade->getFontHeight());
glyph->setHorizontalBearing(osg::Vec2(0, 0));
glyph->setVerticalAdvance(_facade->getFontHeight());
glyph->setVerticalBearing(osg::Vec2(0, 0));
_chars[' '] = glyph;
addGlyph(width, height, ' ', glyph);
return true;
}