From Romain Ouabdelkader, "This is a fix for osgText to calculate kerning and to load glyph3D with the text's font resolution.

Font::getKerning(...), Font::getGlyph3D(...) doesn't ask for a font resolution so it uses the last font resolution requested by Font:: getGlyph(...).
This can leads to different results depending of the precedent call to Font::getGlyph(...).
See http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2016-January/271952.html for more infos.

This fix adds a font resolution parameter to Font::getKerning(...), Font::getGlyph3D(...) and to the font implementations.
This was made under the base revision r15182."
This commit is contained in:
Robert Osfield
2016-02-15 13:30:39 +00:00
parent 937ef73521
commit 67202b2662
13 changed files with 57 additions and 42 deletions

View File

@@ -377,22 +377,32 @@ Glyph* Font::getGlyph(const FontResolution& fontRes, unsigned int charcode)
else return 0;
}
Glyph3D* Font::getGlyph3D(unsigned int charcode)
Glyph3D* Font::getGlyph3D(const FontResolution &fontRes, unsigned int charcode)
{
if (!_implementation) return 0;
FontResolution fontResUsed(0,0);
if (_implementation->supportsMultipleFontResolutions()) fontResUsed = fontRes;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_glyphMapMutex);
Glyph3DMap::iterator itr = _glyph3DMap.find(charcode);
if (itr!=_glyph3DMap.end()) return itr->second.get();
FontSizeGlyph3DMap::iterator itr = _sizeGlyph3DMap.find(fontResUsed);
if (itr!=_sizeGlyph3DMap.end())
{
Glyph3DMap& glyphmap = itr->second;
Glyph3DMap::iterator gitr = glyphmap.find(charcode);
if (gitr!=glyphmap.end()) return gitr->second.get();
}
}
Glyph3D* glyph = _implementation.valid() ? _implementation->getGlyph3D(charcode) : 0;
Glyph3D* glyph = _implementation->getGlyph3D(fontResUsed, charcode);
if (glyph)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_glyphMapMutex);
_glyph3DMap[charcode] = glyph;
_sizeGlyph3DMap[fontResUsed][charcode] = glyph;
return glyph;
}
return 0;
else return 0;
}
void Font::setThreadSafeRefUnref(bool threadSafe)
@@ -437,9 +447,9 @@ void Font::releaseGLObjects(osg::State* state) const
// const_cast<Font*>(this)->_sizeGlyphMap.clear();
}
osg::Vec2 Font::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType)
osg::Vec2 Font::getKerning(const FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType)
{
if (_implementation.valid()) return _implementation->getKerning(leftcharcode,rightcharcode,kerningType);
if (_implementation.valid()) return _implementation->getKerning(fontRes, leftcharcode, rightcharcode, kerningType);
else return osg::Vec2(0.0f,0.0f);
}