2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
|
|
|
*/
|
2001-11-12 18:04:57 +08:00
|
|
|
|
|
|
|
#ifndef OSGTEXT_FONT
|
2003-03-03 05:05:05 +08:00
|
|
|
#define OSGTEXT_FONT 1
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
#include <osg/Vec2>
|
|
|
|
#include <osg/Image>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osg/StateSet>
|
|
|
|
#include <osg/buffered_value>
|
2001-11-12 18:04:57 +08:00
|
|
|
|
|
|
|
#include <osgText/Export>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
namespace osgText {
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
class Font;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
/** read a font from specified file.*/
|
|
|
|
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename);
|
2001-11-12 18:04:57 +08:00
|
|
|
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
/** Pure virtual base class for fonts.
|
|
|
|
* Concrete implementation are the DefaultFont found in src/osgText/DefaultFont.cpp
|
|
|
|
* and FreeTypeFont found in src/osgPlugins/freetype/FreeTypeFont.cpp*/
|
2001-11-12 18:04:57 +08:00
|
|
|
class OSGTEXT_EXPORT Font : public osg::Object
|
|
|
|
{
|
2003-03-03 05:05:05 +08:00
|
|
|
// declare the interface to a font.
|
|
|
|
public:
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
// forward declare nested classes.
|
|
|
|
class Glyph;
|
|
|
|
class GlyphTexture;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
Font();
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
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"; }
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
virtual std::string getFileName() const = 0;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
/** Set the pixel width and height */
|
|
|
|
virtual void setSize(unsigned int width, unsigned int height) = 0;
|
|
|
|
|
|
|
|
unsigned int getWidth() { return _width; }
|
|
|
|
unsigned int getHeight() { return _height; }
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
virtual Glyph* getGlyph(unsigned int charcode) = 0;
|
|
|
|
|
|
|
|
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode) = 0;
|
|
|
|
|
|
|
|
virtual bool hasVertical() const = 0;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
protected:
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
virtual ~Font();
|
|
|
|
|
|
|
|
void addGlyph(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;
|
|
|
|
|
|
|
|
GlyphMap _glyphMap;
|
|
|
|
GlyphTextureList _glyphTextureList;
|
|
|
|
StateSetList _stateSetList;
|
|
|
|
|
|
|
|
// current active size of font
|
|
|
|
unsigned int _width;
|
|
|
|
unsigned int _height;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
|
|
|
|
// declare the nested classes.
|
|
|
|
public:
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
class OSGTEXT_EXPORT GlyphTexture : public osg::Texture2D
|
|
|
|
{
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
public:
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
GlyphTexture();
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
void setStateSet(osg::StateSet* stateset) { _stateset = stateset; }
|
|
|
|
osg::StateSet* getStateSet() { return _stateset; }
|
|
|
|
const osg::StateSet* getStateSet() const { return _stateset; }
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
bool getSpaceForGlyph(Glyph* glyph, int& posX, int& posY);
|
2002-07-23 00:01:00 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
void addGlyph(Glyph* glyph,int posX, int posY);
|
|
|
|
|
|
|
|
virtual void apply(osg::State& state) const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
protected:
|
2003-03-03 05:05:05 +08:00
|
|
|
|
|
|
|
virtual ~GlyphTexture();
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osg::StateSet* _stateset;
|
|
|
|
|
|
|
|
// parameter used to compute the size and position of empty space
|
|
|
|
// in the texture which could accomodate new glyphs.
|
|
|
|
int _usedY;
|
|
|
|
int _partUsedX;
|
|
|
|
int _partUsedY;
|
|
|
|
|
2003-03-04 00:12:00 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<Glyph> > GlyphRefList;
|
|
|
|
typedef std::vector< const Glyph* > GlyphPtrList;
|
|
|
|
typedef osg::buffered_object< GlyphPtrList > GlyphBuffer;
|
2003-03-03 05:05:05 +08:00
|
|
|
|
2003-03-04 00:12:00 +08:00
|
|
|
GlyphRefList _glyphs;
|
2003-03-03 05:05:05 +08:00
|
|
|
mutable GlyphBuffer _glyphsToSubload;
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
};
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
class OSGTEXT_EXPORT Glyph : public osg::Image
|
|
|
|
{
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
public:
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
Glyph();
|
|
|
|
virtual ~Glyph();
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
unsigned int getGlyphCode() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setFont(Font* font);
|
|
|
|
Font* getFont() const;
|
2002-01-16 18:36:20 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setHorizontalBearing(const osg::Vec2& bearing);
|
|
|
|
const osg::Vec2& getHorizontalBearing() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setHorizontalAdvance(float advance);
|
|
|
|
float getHorizontalAdvance() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setVerticalBearing(const osg::Vec2& bearing);
|
|
|
|
const osg::Vec2& getVerticalBearing() const;
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setVerticalAdvance(float advance);
|
|
|
|
float getVerticalAdvance() const;
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setTexture(GlyphTexture* texture);
|
|
|
|
GlyphTexture* getTexture();
|
|
|
|
const GlyphTexture* getTexture() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
osg::StateSet* getStateSet();
|
|
|
|
const osg::StateSet* getStateSet() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setTexturePosition(int posX,int posY);
|
|
|
|
int getTexturePositionX() const;
|
|
|
|
int getTexturePositionY() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setMinTexCoord(const osg::Vec2& coord);
|
|
|
|
const osg::Vec2& getMinTexCoord() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 06:18:33 +08:00
|
|
|
void setMaxTexCoord(const osg::Vec2& coord);
|
|
|
|
const osg::Vec2& getMaxTexCoord() const;
|
2003-03-03 05:05:05 +08:00
|
|
|
|
2003-03-04 00:12:00 +08:00
|
|
|
void subload() const;
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
Font* _font;
|
|
|
|
unsigned int _glyphCode;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osg::Vec2 _horizontalBearing;
|
|
|
|
float _horizontalAdvance;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osg::Vec2 _verticalBearing;
|
|
|
|
float _verticalAdvance;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-04 00:12:00 +08:00
|
|
|
GlyphTexture* _texture;
|
2003-03-03 05:05:05 +08:00
|
|
|
int _texturePosX;
|
|
|
|
int _texturePosY;
|
|
|
|
osg::Vec2 _minTexCoord;
|
|
|
|
osg::Vec2 _maxTexCoord;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
};
|
2001-11-12 18:04:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
};
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
|
|
|
|
#endif
|