From 24bc48820531b22a67a1bd2d8bcb600cfb693ccb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 22 Jan 2007 09:28:31 +0000 Subject: [PATCH] =?UTF-8?q?From=20Mathias=20Fr=C3=B6hlich,=20"Attached=20i?= =?UTF-8?q?s=20a=20small=20change=20that=20makes=20the=20txf=20loader=20re?= =?UTF-8?q?nder=20the=20same=20resulting=20text=20than=20an=20other=20well?= =?UTF-8?q?=20known=20txf=20loader.=20That=20means=20drawing=20them=20one?= =?UTF-8?q?=20on=20top=20of=20the=20other=20I=20can=20only=20see=20differe?= =?UTF-8?q?nces=20due=20to=20different=20mipmapping=20...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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." --- src/osgPlugins/txf/TXFFont.cpp | 62 +++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/osgPlugins/txf/TXFFont.cpp b/src/osgPlugins/txf/TXFFont.cpp index bae02d1d0..64ef35898 100644 --- a/src/osgPlugins/txf/TXFFont.cpp +++ b/src/osgPlugins/txf/TXFFont.cpp @@ -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; }