Font
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGTEXT_FONT
#define OSGTEXT_FONT 1
#include <string>
#include <istream>
#include <osg/TexEnv>
#include <osgText/Glyph>
#include <osgDB/Options>
#include <OpenThreads/Mutex>
namespace osgText {
// forward declare Font
class Font;
class TextBase;
#ifdef OSG_PROVIDE_READFILE
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);
extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::Options* userOptions = 0);
#endif
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontStream(std::istream& stream, const osgDB::Options* userOptions = 0);
extern OSGTEXT_EXPORT std::string findFontFile(const std::string& str);
class OSGTEXT_EXPORT Font : public osg::Object
{
// declare the interface to a font.
public:
// forward declare nested classes.
class FontImplementation;
public:
Font(FontImplementation* implementation=0);
virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate
virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Font*>(obj)!=NULL; }
virtual const char* className() const { return "Font"; }
virtual const char* libraryName() const { return "osgText"; }
virtual std::string getFileName() const;
static osg::ref_ptr<Font> getDefaultFont();
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSets;
StateSets& getCachedStateSets() { return _statesets; }
const StateSets& getCachedStateSets() const { return _statesets; }
virtual osg::Vec2 getKerning(const FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType);
virtual Glyph* getGlyph(const FontResolution& fontSize, unsigned int charcode);
virtual Glyph3D* getGlyph3D(const FontResolution& fontSize, unsigned int charcode);
virtual bool hasVertical() const;
virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; }
void setTextureSizeHint(unsigned int width,unsigned int height);
unsigned int getTextureWidthHint() const;
unsigned int getTextureHeightHint() const;
void setMinFilterHint(osg::Texture::FilterMode mode);
osg::Texture::FilterMode getMinFilterHint() const;
void setMagFilterHint(osg::Texture::FilterMode mode);
osg::Texture::FilterMode getMagFilterHint() const;
void setMaxAnisotropy(float anis) { _maxAnisotropy = anis; }
float getMaxAnisotropy() const { return _maxAnisotropy; }
unsigned int getFontDepth() const { return _depth; }
void setNumberCurveSamples(unsigned int numSamples) { _numCurveSamples = numSamples; }
unsigned int getNumberCurveSamples() const { return _numCurveSamples; }
// make Text a friend to allow it add and remove its entry in the Font's _textList.
friend class FontImplementation;
void setImplementation(FontImplementation* implementation);
FontImplementation* getImplementation();
const FontImplementation* getImplementation() const;
virtual void setThreadSafeRefUnref(bool threadSafe);
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* state=0) const;
typedef OpenThreads::Mutex FontMutex;
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; }
void assignGlyphToGlyphTexture(Glyph* glyph, ShaderTechnique shaderTechnique);
protected:
virtual ~Font();
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph);
typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
typedef std::map< unsigned int, osg::ref_ptr<Glyph3D> > Glyph3DMap;
typedef std::map< FontResolution, GlyphMap > FontSizeGlyphMap;
typedef std::map< FontResolution, Glyph3DMap > FontSizeGlyph3DMap;
mutable OpenThreads::Mutex _glyphMapMutex;
StateSets _statesets;
FontSizeGlyphMap _sizeGlyphMap;
GlyphTextureList _glyphTextureList;
FontSizeGlyph3DMap _sizeGlyph3DMap;
// current active size of font
FontResolution _fontSize;
unsigned int _textureWidthHint;
unsigned int _textureHeightHint;
osg::Texture::FilterMode _minFilterHint;
osg::Texture::FilterMode _magFilterHint;
float _maxAnisotropy;
unsigned int _depth;
unsigned int _numCurveSamples;
osg::ref_ptr<FontImplementation> _implementation;
// declare the nested classes.
public:
class FontImplementation : public osg::Referenced
{
public:
FontImplementation():
osg::Referenced(true),
_facade(0) {}
virtual std::string getFileName() const = 0;
virtual bool supportsMultipleFontResolutions() const = 0;
virtual Glyph* getGlyph(const FontResolution& fontRes, unsigned int charcode) = 0;
virtual Glyph3D* getGlyph3D(const FontResolution& fontRes, unsigned int charcode) = 0;
virtual osg::Vec2 getKerning(const FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType) = 0;
virtual bool hasVertical() const = 0;
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph)
{
_facade->addGlyph(fontRes, charcode, glyph);
}
Font* _facade;
virtual bool getVerticalSize(float & /*ascender*/, float & /*descender*/) const { return false; }
};
};
}
#endif
Glyph
Mutex
Options
TexEnv
OpenThreads::Mutex
This class provides an object-oriented thread mutex interface.
Definition Mutex:31
osgDB::Options
Definition Options:30
osgText::Font::FontImplementation
Definition Font:203
osgText::Font::FontImplementation::addGlyph
void addGlyph(const FontResolution &fontRes, unsigned int charcode, Glyph *glyph)
Definition Font:226
osgText::Font::FontImplementation::getVerticalSize
virtual bool getVerticalSize(float &, float &) const
Definition Font:233
osgText::Font::FontImplementation::_facade
Font * _facade
Definition Font:231
osgText::Font::FontImplementation::hasVertical
virtual bool hasVertical() const =0
osgText::Font::FontImplementation::getKerning
virtual osg::Vec2 getKerning(const FontResolution &fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType)=0
osgText::Font::FontImplementation::getGlyph
virtual Glyph * getGlyph(const FontResolution &fontRes, unsigned int charcode)=0
osgText::Font::FontImplementation::supportsMultipleFontResolutions
virtual bool supportsMultipleFontResolutions() const =0
osgText::Font::FontImplementation::getFileName
virtual std::string getFileName() const =0
osgText::Font::FontImplementation::getGlyph3D
virtual Glyph3D * getGlyph3D(const FontResolution &fontRes, unsigned int charcode)=0
osgText::Font::FontImplementation::FontImplementation
FontImplementation()
Definition Font:206
osgText::Font::getMinFilterHint
osg::Texture::FilterMode getMinFilterHint() const
osgText::Font::setMinFilterHint
void setMinFilterHint(osg::Texture::FilterMode mode)
osgText::Font::setImplementation
void setImplementation(FontImplementation *implementation)
osgText::Font::_implementation
osg::ref_ptr< FontImplementation > _implementation
Definition Font:196
osgText::Font::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgText::Font::hasVertical
virtual bool hasVertical() const
osgText::Font::_glyphTextureList
GlyphTextureList _glyphTextureList
Definition Font:178
osgText::Font::_fontSize
FontResolution _fontSize
Definition Font:184
osgText::Font::_sizeGlyphMap
FontSizeGlyphMap _sizeGlyphMap
Definition Font:177
osgText::Font::assignGlyphToGlyphTexture
void assignGlyphToGlyphTexture(Glyph *glyph, ShaderTechnique shaderTechnique)
osgText::Font::getMagFilterHint
osg::Texture::FilterMode getMagFilterHint() const
osgText::Font::getCachedStateSets
StateSets & getCachedStateSets()
Definition Font:89
osgText::Font::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition Font:80
osgText::Font::FontSizeGlyph3DMap
std::map< FontResolution, Glyph3DMap > FontSizeGlyph3DMap
Definition Font:172
osgText::Font::clone
virtual osg::Object * clone(const osg::CopyOp &) const
Definition Font:79
osgText::Font::FontSizeGlyphMap
std::map< FontResolution, GlyphMap > FontSizeGlyphMap
Definition Font:171
osgText::Font::setNumberCurveSamples
void setNumberCurveSamples(unsigned int numSamples)
Definition Font:132
osgText::Font::_textureHeightHint
unsigned int _textureHeightHint
Definition Font:187
osgText::Font::getGlyphTextureList
GlyphTextureList & getGlyphTextureList()
Definition Font:158
osgText::Font::getImplementation
const FontImplementation * getImplementation() const
osgText::Font::releaseGLObjects
virtual void releaseGLObjects(osg::State *state=0) const
osgText::Font::Glyph3DMap
std::map< unsigned int, osg::ref_ptr< Glyph3D > > Glyph3DMap
Definition Font:169
osgText::Font::~Font
virtual ~Font()
osgText::Font::getKerning
virtual osg::Vec2 getKerning(const FontResolution &fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType)
osgText::Font::_textureWidthHint
unsigned int _textureWidthHint
Definition Font:186
osgText::Font::setMagFilterHint
void setMagFilterHint(osg::Texture::FilterMode mode)
osgText::Font::getFileName
virtual std::string getFileName() const
osgText::Font::_sizeGlyph3DMap
FontSizeGlyph3DMap _sizeGlyph3DMap
Definition Font:181
osgText::Font::StateSets
std::vector< osg::ref_ptr< osg::StateSet > > StateSets
Definition Font:88
osgText::Font::_statesets
StateSets _statesets
Definition Font:176
osgText::Font::getGlyph
virtual Glyph * getGlyph(const FontResolution &fontSize, unsigned int charcode)
osgText::Font::_magFilterHint
osg::Texture::FilterMode _magFilterHint
Definition Font:189
osgText::Font::getMaxAnisotropy
float getMaxAnisotropy() const
Definition Font:128
osgText::Font::_minFilterHint
osg::Texture::FilterMode _minFilterHint
Definition Font:188
osgText::Font::getTextureHeightHint
unsigned int getTextureHeightHint() const
osgText::Font::_depth
unsigned int _depth
Definition Font:192
osgText::Font::getFontDepth
unsigned int getFontDepth() const
Definition Font:130
osgText::Font::_numCurveSamples
unsigned int _numCurveSamples
Definition Font:193
osgText::Font::setThreadSafeRefUnref
virtual void setThreadSafeRefUnref(bool threadSafe)
osgText::Font::_maxAnisotropy
float _maxAnisotropy
Definition Font:190
osgText::Font::GlyphTextureList
std::vector< osg::ref_ptr< GlyphTexture > > GlyphTextureList
Definition Font:157
osgText::Font::getImplementation
FontImplementation * getImplementation()
osgText::Font::GlyphMap
std::map< unsigned int, osg::ref_ptr< Glyph > > GlyphMap
Definition Font:168
osgText::Font::getCachedStateSets
const StateSets & getCachedStateSets() const
Definition Font:90
osgText::Font::Font
Font(FontImplementation *implementation=0)
osgText::Font::cloneType
virtual osg::Object * cloneType() const
Definition Font:78
osgText::Font::setMaxAnisotropy
void setMaxAnisotropy(float anis)
Definition Font:127
osgText::Font::getGlyph3D
virtual Glyph3D * getGlyph3D(const FontResolution &fontSize, unsigned int charcode)
osgText::Font::getTextureWidthHint
unsigned int getTextureWidthHint() const
osgText::Font::getNumberCurveSamples
unsigned int getNumberCurveSamples() const
Definition Font:133
osgText::Font::FontMutex
OpenThreads::Mutex FontMutex
Definition Font:155
osgText::Font::libraryName
virtual const char * libraryName() const
Definition Font:82
osgText::Font::addGlyph
void addGlyph(const FontResolution &fontRes, unsigned int charcode, Glyph *glyph)
osgText::Font::_glyphMapMutex
OpenThreads::Mutex _glyphMapMutex
Definition Font:174
osgText::Font::getVerticalSize
virtual bool getVerticalSize(float &ascender, float &descender) const
Definition Font:108
osgText::Font::getDefaultFont
static osg::ref_ptr< Font > getDefaultFont()
osgText::Font::setTextureSizeHint
void setTextureSizeHint(unsigned int width, unsigned int height)
osgText::Font::className
virtual const char * className() const
Definition Font:81
osgText::Glyph3D
Definition Glyph:181
osgText::Glyph
Definition Glyph:50
osg::CopyOp
Definition CopyOp:41
osg::Object
Definition Object:61
osg::Referenced
Definition Referenced:44
osg::Referenced::Referenced
Referenced()
osg::State
Definition State:80
osg::Texture::FilterMode
FilterMode
Definition Texture:499
osg::ref_ptr
Definition ref_ptr:32
osgText
osgText::FontResolution
std::pair< unsigned int, unsigned int > FontResolution
Definition KerningType:20
osgText::readRefFontFile
OSGTEXT_EXPORT osg::ref_ptr< Font > readRefFontFile(const std::string &filename, const osgDB::Options *userOptions=0)
osgText::KerningType
KerningType
Definition KerningType:23
osgText::findFontFile
OSGTEXT_EXPORT std::string findFontFile(const std::string &str)
osgText::readRefFontStream
OSGTEXT_EXPORT osg::ref_ptr< Font > readRefFontStream(std::istream &stream, const osgDB::Options *userOptions=0)
osgText::ShaderTechnique
ShaderTechnique
Definition Glyph:42
osg
Definition AlphaFunc:19
osg::Vec2
Vec2f Vec2
Definition Vec2:21
OSGTEXT_EXPORT
#define OSGTEXT_EXPORT
Definition osgText/Export:39
NULL
#define NULL
Definition osg/Export:55