~ubuntu-branches/ubuntu/trusty/openscenegraph/trusty

« back to all changes in this revision

Viewing changes to OpenSceneGraph/include/osgText/Font

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-07-29 04:34:38 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080729043438-no1h9h0dpsrlzp1y
* Non-maintainer upload.
* No longer try to detect (using /proc/cpuinfo when available) how many
  CPUs are available, fixing the FTBFS (due to -j0) on various platforms
  (Closes: #477353). The right way to do it is to support parallel=n in
  DEB_BUILD_OPTIONS (see Debian Policy §4.9.1), and adequate support has
  been implemented.
* Add patch to fix FTBFS due to the build system now refusing to handle
  whitespaces (Policy CMP0004 say the logs), thanks to Andreas Putzo who
  provided it (Closes: #482239):
   - debian/patches/fix-cmp0004-build-failure.dpatch
* Remove myself from Uploaders, as requested a while ago, done by Luk in
  his 2.2.0-2.1 NMU, which was never acknowledged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <osg/buffered_value>
25
25
#include <osg/TexEnv>
26
26
#include <osgDB/ReaderWriter>
 
27
 
27
28
#include <osgText/Export>
 
29
#include <osgText/KerningType>
28
30
 
29
31
#include <OpenThreads/Mutex>
30
32
 
32
34
 
33
35
class Font;
34
36
class Text;
35
 
enum KerningType
36
 
{
37
 
    KERNING_DEFAULT,    //default locked to integer kerning values
38
 
    KERNING_UNFITTED,   //use floating point value for kerning
39
 
    KERNING_NONE        //no kerning
40
 
};
41
37
 
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);
65
61
 
 
62
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0);
 
63
 
 
64
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
 
65
 
66
66
extern OSGTEXT_EXPORT std::string findFontFile(const std::string& str);
67
67
 
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(); }
99
99
 
100
 
    /** Set the pixel width and height hint.*/
101
 
    virtual void setFontResolution(unsigned int width, unsigned int height);
102
100
    
103
 
    unsigned int getFontWidth() const;
104
 
    unsigned int getFontHeight() const;
105
 
 
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);
108
103
 
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);
111
106
    
112
107
    /** Return true if this font provides vertical alignments and spacing or glyphs.*/
113
108
    virtual bool hasVertical() const;
163
158
 
164
159
    typedef OpenThreads::Mutex FontMutex;
165
160
    
166
 
    /** Get the mutex that enables the serialization of calls to this font.*/
167
 
    static FontMutex* getSerializeFontCallsMutex();
168
 
 
169
161
protected:
170
162
 
171
163
    virtual ~Font();
172
164
    
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);
174
166
    
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;
178
170
    
179
 
    typedef std::pair< unsigned int, unsigned int >         SizePair;
180
 
    typedef std::map< SizePair, GlyphMap >                  SizeGlyphMap;
181
 
    
182
 
    mutable FontMutex               _serializeFontCallsMutex;
183
 
 
 
171
    typedef std::map< FontResolution, GlyphMap >              FontSizeGlyphMap;
 
172
    
 
173
    mutable OpenThreads::Mutex      _glyphMapMutex;
 
174
    
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;
188
179
    
189
180
    // current active size of font
190
 
    unsigned int                    _width;
191
 
    unsigned int                    _height;
 
181
    FontResolution                  _fontSize;
192
182
    unsigned int                    _margin;
193
183
    float                           _marginRatio;
194
184
 
208
198
    public:
209
199
    
210
200
        FontImplementation():
211
 
            osg::Referenced(true) {}
 
201
            osg::Referenced(true),
 
202
            _facade(0) {}
212
203
    
213
204
        virtual std::string getFileName() const = 0;
214
205
 
215
 
        /** Set the pixel width and height hint.*/
216
 
        virtual void setFontResolution(unsigned int width, unsigned int height) = 0;
217
 
 
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;
220
208
 
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;
223
211
 
224
212
        /** Return true if this font provides vertical alignments and spacing or glyphs.*/
225
213
        virtual bool hasVertical() const = 0;
226
214
        
227
 
        void setFontWidth(unsigned int width) { _facade->_width = width; }
228
 
 
229
 
        void setFontHeight(unsigned int height) { _facade->_height = height; }
230
 
        
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)
232
216
        {
233
 
            _facade->addGlyph(width, height, charcode, glyph);
 
217
            _facade->addGlyph(fontRes, charcode, glyph);
234
218
        }
235
219
 
236
220
        Font* _facade;
272
256
 
273
257
 
274
258
        // parameter used to compute the size and position of empty space
275
 
        // in the texture which could accomodate new glyphs.
 
259
        // in the texture which could accommodate new glyphs.
276
260
        int _margin;
277
261
        float _marginRatio;
278
262
        int _usedY;