openscenegraph
Font
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGTEXT_FONT
15#define OSGTEXT_FONT 1
16
17#include <string>
18#include <istream>
19
20#include <osg/TexEnv>
21#include <osgText/Glyph>
22#include <osgDB/Options>
23
24#include <OpenThreads/Mutex>
25
26namespace osgText {
27
28// forward declare Font
29class Font;
30class TextBase;
31
32#ifdef OSG_PROVIDE_READFILE
52extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);
53
55extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::Options* userOptions = 0);
56#endif
57
58extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);
59
60extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontStream(std::istream& stream, const osgDB::Options* userOptions = 0);
61
62extern OSGTEXT_EXPORT std::string findFontFile(const std::string& str);
63
68{
69// declare the interface to a font.
70public:
71
72 // forward declare nested classes.
74
75public:
76 Font(FontImplementation* implementation=0);
77
78 virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate
79 virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate
80 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Font*>(obj)!=NULL; }
81 virtual const char* className() const { return "Font"; }
82 virtual const char* libraryName() const { return "osgText"; }
83
84 virtual std::string getFileName() const;
85
87
88 typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSets;
89 StateSets& getCachedStateSets() { return _statesets; }
90 const StateSets& getCachedStateSets() const { return _statesets; }
91
92
94 virtual osg::Vec2 getKerning(const FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType);
95
97 virtual Glyph* getGlyph(const FontResolution& fontSize, unsigned int charcode);
98
99
101 virtual Glyph3D* getGlyph3D(const FontResolution& fontSize, unsigned int charcode);
102
104 virtual bool hasVertical() const;
105
108 virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; }
109
112 void setTextureSizeHint(unsigned int width,unsigned int height);
113
114 unsigned int getTextureWidthHint() const;
115 unsigned int getTextureHeightHint() const;
116
121
126
127 void setMaxAnisotropy(float anis) { _maxAnisotropy = anis; }
128 float getMaxAnisotropy() const { return _maxAnisotropy; }
129
130 unsigned int getFontDepth() const { return _depth; }
131
132 void setNumberCurveSamples(unsigned int numSamples) { _numCurveSamples = numSamples; }
133 unsigned int getNumberCurveSamples() const { return _numCurveSamples; }
134
135
136 // make Text a friend to allow it add and remove its entry in the Font's _textList.
137 friend class FontImplementation;
138
140
143
145 virtual void setThreadSafeRefUnref(bool threadSafe);
146
148 virtual void resizeGLObjectBuffers(unsigned int maxSize);
149
153 virtual void releaseGLObjects(osg::State* state=0) const;
154
156
157 typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
158 GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; }
159
160 void assignGlyphToGlyphTexture(Glyph* glyph, ShaderTechnique shaderTechnique);
161
162protected:
163
164 virtual ~Font();
165
166 void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph);
167
168 typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
169 typedef std::map< unsigned int, osg::ref_ptr<Glyph3D> > Glyph3DMap;
170
171 typedef std::map< FontResolution, GlyphMap > FontSizeGlyphMap;
172 typedef std::map< FontResolution, Glyph3DMap > FontSizeGlyph3DMap;
173
175
179
180
182
183 // current active size of font
185
186 unsigned int _textureWidthHint;
187 unsigned int _textureHeightHint;
191
192 unsigned int _depth;
193 unsigned int _numCurveSamples;
194
195
197
198
199// declare the nested classes.
200public:
201
203 {
204 public:
205
207 osg::Referenced(true),
208 _facade(0) {}
209
210 virtual std::string getFileName() const = 0;
211
212 virtual bool supportsMultipleFontResolutions() const = 0;
213
215 virtual Glyph* getGlyph(const FontResolution& fontRes, unsigned int charcode) = 0;
216
218 virtual Glyph3D* getGlyph3D(const FontResolution& fontRes, unsigned int charcode) = 0;
219
221 virtual osg::Vec2 getKerning(const FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType) = 0;
222
224 virtual bool hasVertical() const = 0;
225
226 void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph)
227 {
228 _facade->addGlyph(fontRes, charcode, glyph);
229 }
230
232
233 virtual bool getVerticalSize(float & /*ascender*/, float & /*descender*/) const { return false; }
234 };
235
236};
237
238}
239
240#endif
This class provides an object-oriented thread mutex interface.
Definition Mutex:31
Definition Options:30
void addGlyph(const FontResolution &fontRes, unsigned int charcode, Glyph *glyph)
Definition Font:226
virtual bool getVerticalSize(float &, float &) const
Definition Font:233
Font * _facade
Definition Font:231
virtual bool hasVertical() const =0
virtual osg::Vec2 getKerning(const FontResolution &fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType)=0
virtual Glyph * getGlyph(const FontResolution &fontRes, unsigned int charcode)=0
virtual bool supportsMultipleFontResolutions() const =0
virtual std::string getFileName() const =0
virtual Glyph3D * getGlyph3D(const FontResolution &fontRes, unsigned int charcode)=0
FontImplementation()
Definition Font:206
Definition Font:68
osg::Texture::FilterMode getMinFilterHint() const
void setMinFilterHint(osg::Texture::FilterMode mode)
void setImplementation(FontImplementation *implementation)
osg::ref_ptr< FontImplementation > _implementation
Definition Font:196
virtual void resizeGLObjectBuffers(unsigned int maxSize)
virtual bool hasVertical() const
GlyphTextureList _glyphTextureList
Definition Font:178
FontResolution _fontSize
Definition Font:184
FontSizeGlyphMap _sizeGlyphMap
Definition Font:177
void assignGlyphToGlyphTexture(Glyph *glyph, ShaderTechnique shaderTechnique)
osg::Texture::FilterMode getMagFilterHint() const
StateSets & getCachedStateSets()
Definition Font:89
virtual bool isSameKindAs(const osg::Object *obj) const
Definition Font:80
std::map< FontResolution, Glyph3DMap > FontSizeGlyph3DMap
Definition Font:172
virtual osg::Object * clone(const osg::CopyOp &) const
Definition Font:79
std::map< FontResolution, GlyphMap > FontSizeGlyphMap
Definition Font:171
void setNumberCurveSamples(unsigned int numSamples)
Definition Font:132
unsigned int _textureHeightHint
Definition Font:187
GlyphTextureList & getGlyphTextureList()
Definition Font:158
const FontImplementation * getImplementation() const
virtual void releaseGLObjects(osg::State *state=0) const
std::map< unsigned int, osg::ref_ptr< Glyph3D > > Glyph3DMap
Definition Font:169
virtual ~Font()
virtual osg::Vec2 getKerning(const FontResolution &fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType)
unsigned int _textureWidthHint
Definition Font:186
void setMagFilterHint(osg::Texture::FilterMode mode)
virtual std::string getFileName() const
FontSizeGlyph3DMap _sizeGlyph3DMap
Definition Font:181
std::vector< osg::ref_ptr< osg::StateSet > > StateSets
Definition Font:88
StateSets _statesets
Definition Font:176
virtual Glyph * getGlyph(const FontResolution &fontSize, unsigned int charcode)
osg::Texture::FilterMode _magFilterHint
Definition Font:189
float getMaxAnisotropy() const
Definition Font:128
osg::Texture::FilterMode _minFilterHint
Definition Font:188
unsigned int getTextureHeightHint() const
unsigned int _depth
Definition Font:192
unsigned int getFontDepth() const
Definition Font:130
unsigned int _numCurveSamples
Definition Font:193
virtual void setThreadSafeRefUnref(bool threadSafe)
float _maxAnisotropy
Definition Font:190
std::vector< osg::ref_ptr< GlyphTexture > > GlyphTextureList
Definition Font:157
FontImplementation * getImplementation()
std::map< unsigned int, osg::ref_ptr< Glyph > > GlyphMap
Definition Font:168
const StateSets & getCachedStateSets() const
Definition Font:90
Font(FontImplementation *implementation=0)
virtual osg::Object * cloneType() const
Definition Font:78
void setMaxAnisotropy(float anis)
Definition Font:127
virtual Glyph3D * getGlyph3D(const FontResolution &fontSize, unsigned int charcode)
unsigned int getTextureWidthHint() const
unsigned int getNumberCurveSamples() const
Definition Font:133
OpenThreads::Mutex FontMutex
Definition Font:155
virtual const char * libraryName() const
Definition Font:82
void addGlyph(const FontResolution &fontRes, unsigned int charcode, Glyph *glyph)
OpenThreads::Mutex _glyphMapMutex
Definition Font:174
virtual bool getVerticalSize(float &ascender, float &descender) const
Definition Font:108
static osg::ref_ptr< Font > getDefaultFont()
void setTextureSizeHint(unsigned int width, unsigned int height)
virtual const char * className() const
Definition Font:81
Definition Glyph:181
Definition Glyph:50
Definition CopyOp:41
Definition Object:61
Definition Referenced:44
Definition State:80
FilterMode
Definition Texture:499
Definition Vec2f:29
Definition ref_ptr:32
std::pair< unsigned int, unsigned int > FontResolution
Definition KerningType:20
OSGTEXT_EXPORT osg::ref_ptr< Font > readRefFontFile(const std::string &filename, const osgDB::Options *userOptions=0)
KerningType
Definition KerningType:23
OSGTEXT_EXPORT std::string findFontFile(const std::string &str)
OSGTEXT_EXPORT osg::ref_ptr< Font > readRefFontStream(std::istream &stream, const osgDB::Options *userOptions=0)
ShaderTechnique
Definition Glyph:42
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSGTEXT_EXPORT
Definition osgText/Export:39
#define NULL
Definition osg/Export:55