From Wang Rui, "I've found a problem when using QFont (osgQt/QFontImplementation.cpp)
to read fonts: only the first character of a whole text is correctly shown and others are disappeared. I haven't got into the font implementation so can't explain why this happened and how it should work under other platforms, but it seems to be fixed by specifying width and height of the glyph object. The source file is attached for future developments. At present it just works for my own project. :-) "
This commit is contained in:
@@ -55,6 +55,8 @@ osgText::Glyph*
|
||||
QFontImplementation::getGlyph(const osgText::FontResolution& fontRes, unsigned int charcode)
|
||||
{
|
||||
setFontResolution(fontRes);
|
||||
|
||||
float coord_scale = 1.0f/float(_currentRes.second);
|
||||
|
||||
QFontMetrics fontMetrics(_font);
|
||||
QFontMetricsF fontMetricsF(_font);
|
||||
@@ -105,6 +107,9 @@ QFontImplementation::getGlyph(const osgText::FontResolution& fontRes, unsigned i
|
||||
osg::Image::USE_NEW_DELETE,
|
||||
1);
|
||||
glyph->setInternalTextureFormat(GL_ALPHA);
|
||||
|
||||
glyph->setWidth((float)imageWidth * coord_scale);
|
||||
glyph->setHeight((float)imageHeight * coord_scale);
|
||||
|
||||
// Layout parameters
|
||||
float leftBearing = fontMetricsF.leftBearing(QChar(charcode));
|
||||
@@ -112,17 +117,17 @@ QFontImplementation::getGlyph(const osgText::FontResolution& fontRes, unsigned i
|
||||
|
||||
// for horizonal layout
|
||||
osg::Vec2 bottomLeft(leftBearing - margin, - rectF.bottom() - margin);
|
||||
glyph->setHorizontalBearing(bottomLeft);
|
||||
glyph->setHorizontalAdvance(fontMetricsF.width(QChar(charcode)));
|
||||
glyph->setHorizontalBearing(bottomLeft * coord_scale);
|
||||
glyph->setHorizontalAdvance(fontMetricsF.width(QChar(charcode)) * coord_scale);
|
||||
|
||||
// for vertical layout
|
||||
osg::Vec2 topMiddle(- margin + 0.5*(leftBearing - rect.width() - rightBearing),
|
||||
rectF.top() - margin);
|
||||
glyph->setVerticalBearing(topMiddle);
|
||||
glyph->setVerticalAdvance(rectF.height() + fontMetricsF.overlinePos() - fontMetricsF.xHeight());
|
||||
glyph->setVerticalBearing(topMiddle * coord_scale);
|
||||
glyph->setVerticalAdvance((rectF.height() + fontMetricsF.overlinePos() - fontMetricsF.xHeight()) * coord_scale);
|
||||
|
||||
// ... ready
|
||||
addGlyph(fontRes, charcode, glyph.get());
|
||||
//addGlyph(fontRes, charcode, glyph.get());
|
||||
|
||||
return glyph.release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user