OpenSceneGraph/include/osgText/Font

279 lines
8.0 KiB
Plaintext
Raw Normal View History

/* -*-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.
*/
2002-07-17 04:07:32 +08:00
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
2001-11-12 18:04:57 +08:00
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
/* --------------------------------------------------------------------------
*
* openscenegraph textLib / FTGL wrapper
*
* --------------------------------------------------------------------------
*
* prog: max rheiner;mrn@paus.ch
* date: 4/25/2001 (m/d/y)
*
* --------------------------------------------------------------------------
*
* --------------------------------------------------------------------------
*/
#ifndef OSGTEXT_FONT
#define OSGTEXT_FONT 1
#include <osg/Object>
#include <osg/State>
2001-11-12 18:04:57 +08:00
#include <osgText/Export>
#include <osgText/EncodedText>
2001-11-12 18:04:57 +08:00
#include <string>
// http://homepages.paradise.net.nz/henryj/code/
class FTFont;
namespace osgText {
/** META_Font macro define the standard clone, isSameKindAs,
* className and getType methods.
* Use when subclassing from Object to make it more convinient to define
* the standard pure virtual methods which are required for all Object
* subclasses.*/
#define META_Font(library,name) \
virtual osg::Object* cloneType() const { return new name(); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
virtual const char* libraryName() const { return #library; } \
virtual const char* className() const { return #name; } \
2001-11-12 18:04:57 +08:00
class OSGTEXT_EXPORT Font : public osg::Object
{
public:
2001-11-12 18:04:57 +08:00
Font();
Font(const Font& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(font,copyop),
_init(false),
_created(false),
_font(0L),
_fontName(font._fontName),
_pointSize(font._pointSize),
_res(font._res),
_textureSize(font._textureSize)
{}
2001-11-12 18:04:57 +08:00
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Font *>(obj)!=NULL; }
virtual const char* libraryName() const { return "osgText"; }
virtual const char* className() const { return "Font"; }
2001-11-12 18:04:57 +08:00
bool open(const char* font);
bool open(const std::string& font);
2001-11-12 18:04:57 +08:00
virtual bool create(osg::State& state,int pointSize, unsigned int res = 72 );
virtual bool create(osg::State& state);
virtual void output(osg::State& state, const EncodedText* text) const;
2001-11-12 18:04:57 +08:00
virtual bool isOk(void) const { return _init; }
virtual bool isCreated(void) const { return isOk() && _created; }
2001-11-12 18:04:57 +08:00
virtual float getWidth(const EncodedText* text) const;
virtual int getHeight() const;
virtual int getDescender() const;
virtual int getAscender() const;
2001-11-12 18:04:57 +08:00
int getPointSize(void) const { return _pointSize; }
int getTextureSize(void) const { return _textureSize; }
const std::string& getFontName() const { return _fontName; }
/// Transfer font settings to another Font object and invalidate this one.
void copyAndInvalidate(Font &dest);
2001-11-12 18:04:57 +08:00
FTFont* getFont(void) { return _font; }
2001-11-12 18:04:57 +08:00
protected:
2001-11-12 18:04:57 +08:00
virtual ~Font();
2001-11-12 18:04:57 +08:00
virtual void clear();
2001-11-12 18:04:57 +08:00
virtual FTFont* createFontObj(void)=0;
2001-11-12 18:04:57 +08:00
bool init(const std::string& font);
2001-11-12 18:04:57 +08:00
bool _init;
bool _created;
FTFont* _font;
std::string _fontName;
int _pointSize;
int _res;
int _textureSize;
2001-11-12 18:04:57 +08:00
};
2001-11-12 18:04:57 +08:00
class OSGTEXT_EXPORT RasterFont:public Font
{
public:
2001-11-12 18:04:57 +08:00
RasterFont():Font(){}
RasterFont(const RasterFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
Font(font,copyop) {}
RasterFont(const std::string& /*font*/):Font() {}
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const RasterFont *>(obj)!=NULL; }
virtual const char* libraryName() const { return "osgText"; }
virtual const char* className() const { return "RasterFont"; }
protected:
2001-11-12 18:04:57 +08:00
};
2001-11-12 18:04:57 +08:00
class OSGTEXT_EXPORT VectorFont:public Font
{
public:
2002-07-23 00:01:00 +08:00
VectorFont():Font(),_precision(0.0) {}
VectorFont(const VectorFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
2002-07-23 00:01:00 +08:00
Font(font,copyop),
_precision(font._precision) {}
VectorFont(const std::string& /*font*/):Font(){}
2001-11-12 18:04:57 +08:00
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const VectorFont *>(obj)!=NULL; }
virtual const char* libraryName() const { return "osgText"; }
virtual const char* className() const { return "VectorFont"; }
protected:
double _precision;
2001-11-12 18:04:57 +08:00
};
2001-11-12 18:04:57 +08:00
class OSGTEXT_EXPORT BitmapFont:public RasterFont
{
public:
2001-11-12 18:04:57 +08:00
BitmapFont() {}
BitmapFont(const BitmapFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
RasterFont(font,copyop) {}
BitmapFont(const std::string& font,
int point_size);
2001-11-12 18:04:57 +08:00
META_Font(osgText,BitmapFont);
2001-11-12 18:04:57 +08:00
protected:
2001-11-12 18:04:57 +08:00
virtual FTFont* createFontObj(void);
2001-11-12 18:04:57 +08:00
};
class OSGTEXT_EXPORT PixmapFont:public RasterFont
{
public:
2001-11-12 18:04:57 +08:00
PixmapFont() {}
PixmapFont(const PixmapFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
RasterFont(font,copyop) {}
2001-11-12 18:04:57 +08:00
PixmapFont(const std::string& font,
int point_size);
2001-11-12 18:04:57 +08:00
META_Font(osgText,PixmapFont);
protected:
virtual FTFont* createFontObj(void);
2001-11-12 18:04:57 +08:00
};
class OSGTEXT_EXPORT TextureFont:public RasterFont
{
public:
2001-11-12 18:04:57 +08:00
TextureFont() {}
TextureFont(const TextureFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
RasterFont(font,copyop) {}
TextureFont(const std::string& font,
int point_size);
2001-11-12 18:04:57 +08:00
TextureFont(const std::string& font,
int point_size,
int textureSize );
2001-11-12 18:04:57 +08:00
META_Font(osgText,TextureFont);
protected:
virtual FTFont* createFontObj(void);
2001-11-12 18:04:57 +08:00
};
class OSGTEXT_EXPORT OutlineFont:public VectorFont
{
public:
2001-11-12 18:04:57 +08:00
OutlineFont() {}
OutlineFont(const OutlineFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
VectorFont(font,copyop) {}
2001-11-12 18:04:57 +08:00
OutlineFont(const std::string& font,
int point_size,
double precision);
2001-11-12 18:04:57 +08:00
META_Font(osgText,OutlineFont);
protected:
virtual FTFont* createFontObj(void);
2001-11-12 18:04:57 +08:00
};
class OSGTEXT_EXPORT PolygonFont:public VectorFont
{
public:
PolygonFont() {}
PolygonFont(const PolygonFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
VectorFont(font,copyop) {}
2001-11-12 18:04:57 +08:00
PolygonFont(const std::string& font,
int point_size,
double precision);
PolygonFont(const char* font,
int point_size,
double precision);
META_Font(osgText,PolygonFont);
2001-11-12 18:04:57 +08:00
protected:
virtual FTFont* createFontObj(void);
};
}
2001-11-12 18:04:57 +08:00
#endif // OSGTEXT_FONT