From 740b29d0f732bafddee331e3891fad74ddffbfdf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 26 Jan 2011 16:10:42 +0000 Subject: [PATCH] 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. :-) " --- src/osgQt/QFontImplementation.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/osgQt/QFontImplementation.cpp b/src/osgQt/QFontImplementation.cpp index 563a358a7..978246ae1 100644 --- a/src/osgQt/QFontImplementation.cpp +++ b/src/osgQt/QFontImplementation.cpp @@ -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(); }