24
24
#include <osg/buffered_value>
25
25
#include <osg/TexEnv>
26
26
#include <osgDB/ReaderWriter>
27
28
#include <osgText/Export>
29
#include <osgText/KerningType>
29
31
#include <OpenThreads/Mutex>
37
KERNING_DEFAULT, //default locked to integer kerning values
38
KERNING_UNFITTED, //use floating point value for kerning
39
KERNING_NONE //no kerning
42
38
/** Read a font from specified file. The filename may contain a path.
43
39
* It will search for the font file in the following places in this order:
63
59
/** read a font from specified stream.*/
64
60
extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
62
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0);
64
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
66
66
extern OSGTEXT_EXPORT std::string findFontFile(const std::string& str);
68
68
/** Pure virtual base class for fonts.
97
97
osg::StateSet* getStateSet() { return _stateset.get(); }
98
98
const osg::StateSet* getStateSet() const { return _stateset.get(); }
100
/** Set the pixel width and height hint.*/
101
virtual void setFontResolution(unsigned int width, unsigned int height);
103
unsigned int getFontWidth() const;
104
unsigned int getFontHeight() const;
106
101
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
107
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType);
102
virtual osg::Vec2 getKerning(const FontResolution& fontSize, unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType);
109
104
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
110
virtual Glyph* getGlyph(unsigned int charcode);
105
virtual Glyph* getGlyph(const FontResolution& fontSize, unsigned int charcode);
112
107
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
113
108
virtual bool hasVertical() const;
164
159
typedef OpenThreads::Mutex FontMutex;
166
/** Get the mutex that enables the serialization of calls to this font.*/
167
static FontMutex* getSerializeFontCallsMutex();
173
void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph);
165
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph);
175
167
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
176
168
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
177
169
typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
179
typedef std::pair< unsigned int, unsigned int > SizePair;
180
typedef std::map< SizePair, GlyphMap > SizeGlyphMap;
182
mutable FontMutex _serializeFontCallsMutex;
171
typedef std::map< FontResolution, GlyphMap > FontSizeGlyphMap;
173
mutable OpenThreads::Mutex _glyphMapMutex;
184
175
osg::ref_ptr<osg::TexEnv> _texenv;
185
176
osg::ref_ptr<osg::StateSet> _stateset;
186
SizeGlyphMap _sizeGlyphMap;
177
FontSizeGlyphMap _sizeGlyphMap;
187
178
GlyphTextureList _glyphTextureList;
189
180
// current active size of font
191
unsigned int _height;
181
FontResolution _fontSize;
192
182
unsigned int _margin;
193
183
float _marginRatio;
210
200
FontImplementation():
211
osg::Referenced(true) {}
201
osg::Referenced(true),
213
204
virtual std::string getFileName() const = 0;
215
/** Set the pixel width and height hint.*/
216
virtual void setFontResolution(unsigned int width, unsigned int height) = 0;
218
206
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
219
virtual Glyph* getGlyph(unsigned int charcode) = 0;
207
virtual Glyph* getGlyph(const FontResolution& fontRes, unsigned int charcode) = 0;
221
209
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
222
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType) = 0;
210
virtual osg::Vec2 getKerning(const FontResolution& fontRes, unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType) = 0;
224
212
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
225
213
virtual bool hasVertical() const = 0;
227
void setFontWidth(unsigned int width) { _facade->_width = width; }
229
void setFontHeight(unsigned int height) { _facade->_height = height; }
231
void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph)
215
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph)
233
_facade->addGlyph(width, height, charcode, glyph);
217
_facade->addGlyph(fontRes, charcode, glyph);