diff --git a/include/osgQt/QFontImplementation b/include/osgQt/QFontImplementation index b8a161b88..f9408808b 100644 --- a/include/osgQt/QFontImplementation +++ b/include/osgQt/QFontImplementation @@ -30,16 +30,19 @@ public: virtual std::string getFileName() const; - void setFontResolution(const osgText::FontResolution& fontSize); + virtual bool supportsMultipleFontResolutions() const { return true; } + virtual osgText::Glyph* getGlyph(const osgText::FontResolution& fontRes, unsigned int charcode); + virtual osgText::Glyph3D* getGlyph3D(unsigned int charcode) { return 0; } + virtual osg::Vec2 getKerning(unsigned int leftcharcode, unsigned int rightcharcode, osgText::KerningType kerningType); + virtual bool hasVertical() const; protected: std::string _filename; - osgText::FontResolution _currentRes; QFont _font; }; diff --git a/include/osgText/Font b/include/osgText/Font index 1514ce591..39b96410a 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -161,13 +161,15 @@ public: typedef OpenThreads::Mutex FontMutex; + typedef std::vector< osg::ref_ptr > GlyphTextureList; + GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; } + protected: virtual ~Font(); void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph); - typedef std::vector< osg::ref_ptr > GlyphTextureList; typedef std::vector< osg::ref_ptr > StateSetList; typedef std::map< unsigned int, osg::ref_ptr > GlyphMap; typedef std::map< unsigned int, osg::ref_ptr > Glyph3DMap; @@ -214,6 +216,8 @@ public: virtual std::string getFileName() const = 0; + virtual bool supportsMultipleFontResolutions() const = 0; + /** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/ virtual Glyph* getGlyph(const FontResolution& fontRes, unsigned int charcode) = 0; diff --git a/include/osgText/Glyph b/include/osgText/Glyph index cff491d08..67fe77a92 100644 --- a/include/osgText/Glyph +++ b/include/osgText/Glyph @@ -263,6 +263,9 @@ public: /** Resize any per context GLObject buffers to specified size. */ virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** create an image that maps all the associated Glyph's onto a single image, that is equivilant to what will be downloaded to the texture.*/ + osg::Image* createImage(); + protected: virtual ~GlyphTexture(); diff --git a/src/osgPlugins/freetype/FreeTypeFont.h b/src/osgPlugins/freetype/FreeTypeFont.h index 015a3a6b5..f71ebf0dd 100644 --- a/src/osgPlugins/freetype/FreeTypeFont.h +++ b/src/osgPlugins/freetype/FreeTypeFont.h @@ -31,6 +31,8 @@ public: virtual std::string getFileName() const { return _filename; } + virtual bool supportsMultipleFontResolutions() const { return true; } + virtual osgText::Glyph* getGlyph(const osgText::FontResolution& fontRes,unsigned int charcode); virtual osgText::Glyph3D* getGlyph3D(unsigned int charcode); diff --git a/src/osgPlugins/txf/TXFFont.h b/src/osgPlugins/txf/TXFFont.h index bd5544a61..5d5faed92 100644 --- a/src/osgPlugins/txf/TXFFont.h +++ b/src/osgPlugins/txf/TXFFont.h @@ -28,6 +28,8 @@ public: virtual std::string getFileName() const; + virtual bool supportsMultipleFontResolutions() const { return false; } + virtual osgText::Glyph* getGlyph(const osgText::FontResolution& fontRes, unsigned int charcode); virtual osgText::Glyph3D* getGlyph3D(unsigned int) { return 0; } diff --git a/src/osgQt/QFontImplementation.cpp b/src/osgQt/QFontImplementation.cpp index 978246ae1..82a4bfcb5 100644 --- a/src/osgQt/QFontImplementation.cpp +++ b/src/osgQt/QFontImplementation.cpp @@ -27,8 +27,6 @@ QFontImplementation::QFontImplementation(const QFont& font) : _filename(font.toString().toStdString() + ".qfont"), _font(font) { - _currentRes.first = 0; - _currentRes.second = 0; } QFontImplementation::~QFontImplementation() @@ -41,22 +39,13 @@ QFontImplementation::getFileName() const return _filename; } -void -QFontImplementation::setFontResolution(const osgText::FontResolution& fontSize) -{ - if (fontSize == _currentRes) - return; - - _currentRes = fontSize; - _font.setPixelSize(fontSize.second); -} - osgText::Glyph* QFontImplementation::getGlyph(const osgText::FontResolution& fontRes, unsigned int charcode) { - setFontResolution(fontRes); + unsigned int fontSize = fontRes.second; + _font.setPixelSize(fontSize); - float coord_scale = 1.0f/float(_currentRes.second); + float coord_scale = 1.0f/float(fontSize); QFontMetrics fontMetrics(_font); QFontMetricsF fontMetricsF(_font); diff --git a/src/osgText/DefaultFont.cpp b/src/osgText/DefaultFont.cpp index 154ba34ce..2b6bc3f23 100644 --- a/src/osgText/DefaultFont.cpp +++ b/src/osgText/DefaultFont.cpp @@ -33,11 +33,6 @@ DefaultFont::~DefaultFont() { } -void DefaultFont::setSize(unsigned int, unsigned int) -{ - OSG_INFO<<"DefaultFont::setSize(,) call is ignored."<supportsMultipleFontResolutions()) fontResUsed = fontRes; + { OpenThreads::ScopedLock lock(_glyphMapMutex); - FontSizeGlyphMap::iterator itr = _sizeGlyphMap.find(fontRes); + FontSizeGlyphMap::iterator itr = _sizeGlyphMap.find(fontResUsed); if (itr!=_sizeGlyphMap.end()) { GlyphMap& glyphmap = itr->second; @@ -361,10 +366,10 @@ Glyph* Font::getGlyph(const FontResolution& fontRes, unsigned int charcode) } } - Glyph* glyph = _implementation.valid() ? _implementation->getGlyph(fontRes, charcode) : 0; + Glyph* glyph = _implementation->getGlyph(fontResUsed, charcode); if (glyph) { - addGlyph(fontRes, charcode, glyph); + addGlyph(fontResUsed, charcode, glyph); return glyph; } else return 0; diff --git a/src/osgText/Glyph.cpp b/src/osgText/Glyph.cpp index 4a8fb7853..ab0b1b975 100644 --- a/src/osgText/Glyph.cpp +++ b/src/osgText/Glyph.cpp @@ -73,7 +73,7 @@ bool GlyphTexture::getSpaceForGlyph(Glyph* glyph, int& posX, int& posY) // move used markers on. _partUsedX += width; if (_usedY+height>_partUsedY) _partUsedY = _usedY+height; - + return true; } @@ -91,7 +91,7 @@ bool GlyphTexture::getSpaceForGlyph(Glyph* glyph, int& posX, int& posY) // move used markers on. _partUsedX += width; if (_usedY+height>_partUsedY) _partUsedY = _usedY+height; - + return true; } @@ -204,9 +204,6 @@ void GlyphTexture::apply(osg::State& state) const } -// OSG_NOTICE<<"Texture width = "<