Fixed handling of Font implementations that don't handle multiple font resolutions.
This commit is contained in:
parent
460f433ca7
commit
fe1c75aa8a
@ -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;
|
||||
};
|
||||
|
||||
|
@ -161,13 +161,15 @@ public:
|
||||
|
||||
typedef OpenThreads::Mutex FontMutex;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
|
||||
GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph);
|
||||
|
||||
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
|
||||
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
|
||||
typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
|
||||
typedef std::map< unsigned int, osg::ref_ptr<Glyph3D> > 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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
||||
|
@ -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);
|
||||
|
@ -33,11 +33,6 @@ DefaultFont::~DefaultFont()
|
||||
{
|
||||
}
|
||||
|
||||
void DefaultFont::setSize(unsigned int, unsigned int)
|
||||
{
|
||||
OSG_INFO<<"DefaultFont::setSize(,) call is ignored."<<std::endl;
|
||||
}
|
||||
|
||||
osgText::Glyph* DefaultFont::getGlyph(const FontResolution& fontRes, unsigned int charcode)
|
||||
{
|
||||
if (_sizeGlyphMap.empty()) return 0;
|
||||
|
@ -30,8 +30,7 @@ public:
|
||||
|
||||
virtual std::string getFileName() const { return ""; }
|
||||
|
||||
/** NOP with DefaultFont since it only supports a single fixed sized font. */
|
||||
virtual void setSize(unsigned int width, unsigned int height);
|
||||
virtual bool supportsMultipleFontResolutions() const { return false; }
|
||||
|
||||
virtual osgText::Glyph* getGlyph(const FontResolution& fontRes, unsigned int charcode);
|
||||
|
||||
|
@ -350,9 +350,14 @@ osg::Texture::FilterMode Font::getMagFilterHint() const
|
||||
|
||||
Glyph* Font::getGlyph(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);
|
||||
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;
|
||||
|
@ -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 = "<<getTextureWidth()<<std::endl;
|
||||
// OSG_NOTICE<<"Texture height = "<<getTextureHeight()<<std::endl;
|
||||
|
||||
// allocate the texture memory.
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA,
|
||||
getTextureWidth(), getTextureHeight(), 0,
|
||||
@ -379,9 +376,37 @@ void GlyphTexture::setThreadSafeRefUnref(bool threadSafe)
|
||||
void GlyphTexture::resizeGLObjectBuffers(unsigned int maxSize)
|
||||
{
|
||||
osg::Texture2D::resizeGLObjectBuffers(maxSize);
|
||||
|
||||
unsigned int initialSize = _glyphsToSubload.size();
|
||||
_glyphsToSubload.resize(maxSize);
|
||||
|
||||
for(unsigned i=initialSize; i<_glyphsToSubload.size(); ++i)
|
||||
{
|
||||
for(GlyphRefList::iterator itr = _glyphs.begin();
|
||||
itr != _glyphs.end();
|
||||
++itr)
|
||||
{
|
||||
_glyphsToSubload[i].push_back(itr->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osg::Image* GlyphTexture::createImage()
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||
image->allocateImage(getTextureWidth(), getTextureHeight(), 1, GL_ALPHA, GL_UNSIGNED_BYTE);
|
||||
memset(image->data(), 0, image->getTotalSizeInBytes());
|
||||
|
||||
for(GlyphRefList::iterator itr = _glyphs.begin();
|
||||
itr != _glyphs.end();
|
||||
++itr)
|
||||
{
|
||||
Glyph* glyph = itr->get();
|
||||
image->copySubImage(glyph->getTexturePositionX(), glyph->getTexturePositionY(), 0, glyph);
|
||||
}
|
||||
|
||||
return image.release();
|
||||
}
|
||||
|
||||
// all the methods in Font::Glyph have been made non inline because VisualStudio6.0 is STUPID, STUPID, STUPID PILE OF JUNK.
|
||||
Glyph::Glyph(Font* font, unsigned int glyphCode):
|
||||
|
Loading…
Reference in New Issue
Block a user