Added osgText::Paragraph which is a subclass from Geode which composes a

list of text drawables as a paragraph block, handles breaking of text into
individual lines automatically.

Changed the osg::Node::setUserData so that the data type has to be an
osg::Referenced, and removes the dependancy on osg::MemoryAdapter.  I have
done this since it simplifies the OSG side of the interface and makes it
less like that the user might abuse the memory managment of the data. It
does however mean that user data will have by subclassed from Referenced,
and therefor may require users to have their own adapter to do this.
However, this little nuasance is worth the extra cleaness and robustness
afforded by going the osg::Referenced route.
This commit is contained in:
Robert Osfield 2001-11-09 15:06:01 +00:00
parent e35f5ec286
commit 7290f793f1
7 changed files with 43 additions and 525 deletions

View File

@ -165,6 +165,14 @@ SOURCE=..\..\src\osgText\FTVectoriser.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgText\Font.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgText\Paragraph.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgText\Text.cpp
# End Source File
# Begin Source File
@ -257,6 +265,14 @@ SOURCE=..\..\src\osgText\FTVectoriser.h
# End Source File
# Begin Source File
SOURCE=..\..\include\osgText\Font
# End Source File
# Begin Source File
SOURCE=..\..\include\osgText\Paragraph
# End Source File
# Begin Source File
SOURCE=..\..\include\osgText\Text
# End Source File
# Begin Source File

View File

@ -8,7 +8,6 @@
#include <osg/Object>
#include <osg/StateSet>
#include <osg/BoundingSphere>
#include <osg/MemoryAdapter>
#include <osg/NodeCallback>
#include <osg/ref_ptr>
@ -120,27 +119,19 @@ class SG_EXPORT Node : public Object
/**
* Set user data. See MemoryAdapter documentation for details
* of how to specify memory management of _userData.
* Set user data, data must be subclased from Referenced to allow
* automatic memory handling. If you own data isn't directly
* subclassed from Referenced then create and adapter object
* which points to your own objects and handles the memory addressing.
*/
inline void setUserData(void* data,MemoryAdapter* ma=0L)
{
if (_userData && _memoryAdapter.valid()) _memoryAdapter->unref_data(_userData);
_userData = data;
_memoryAdapter = ma;
if (_userData && _memoryAdapter.valid()) _memoryAdapter->ref_data(_userData);
}
inline void setUserData(osg::Referenced* obj) { _userData = obj; }
/** Get user data.*/
inline void* getUserData() { return _userData; }
inline Referenced* getUserData() { return _userData.get(); }
/** Get const user data.*/
inline const void* getUserData() const { return _userData; }
inline const Referenced* getUserData() const { return _userData.get(); }
/** Get the memory adapter associated with _userData.*/
inline MemoryAdapter* getMemoryAdapter() { return _memoryAdapter.get(); }
/** Get the const memory adapter associated with _userData.*/
inline const MemoryAdapter* getMemoryAdapter() const { return _memoryAdapter.get(); }
typedef unsigned int NodeMask;
/** Set the node mask. Note, node mask is will be replaced by TraversalMask.*/
@ -223,8 +214,7 @@ class SG_EXPORT Node : public Object
int _numChildrenWithCullingDisabled;
void setNumChildrenWithCullingDisabled(const int num);
void* _userData;
ref_ptr<MemoryAdapter> _memoryAdapter;
osg::ref_ptr<Referenced> _userData;
NodeMask _nodeMask;

View File

@ -23,214 +23,17 @@
#include <string>
#include <osg/GL>
#include <osg/Object>
#include <osg/Drawable>
#include <osg/Vec3>
#include <osg/Vec2>
// http://homepages.paradise.net.nz/henryj/code/
#include <osgText/Export>
class FTFont;
#include <osgText/Font>
namespace osgText {
///////////////////////////////////////////////////////////////////////////////
// Font - FontBaseClass
class OSGTEXT_EXPORT Font : public osg::Object
{
public:
Font();
virtual bool open(const std::string& font);
virtual bool create(int pointSize, const unsigned int res = 72 );
virtual bool create();
virtual void output(const char* text);
virtual bool isOk(void) const { return _init; }
virtual bool isCreated(void) const { return isOk() && _created; }
virtual float getWidth(const char* text) const;
virtual int getHeight() const;
virtual int getDescender() const;
virtual int getAscender() const;
int getPointSize(void) const { return _pointSize; }
const std::string& getFontName();
FTFont* getFont(void) { return _font; }
protected:
virtual ~Font();
virtual void clear();
virtual FTFont* createFontObj(void)=0;
bool init(const std::string& font);
bool _init;
bool _created;
FTFont* _font;
std::string _fontName;
int _pointSize;
int _res;
};
// Font
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// RasterFont
class OSGTEXT_EXPORT RasterFont:public Font
{
public:
RasterFont():Font(){;}
RasterFont(const std::string& font):Font(){;}
protected:
};
// RasterFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// VectorFont
class OSGTEXT_EXPORT VectorFont:public Font
{
public:
VectorFont():Font(){;}
VectorFont(const std::string& font):Font(){;}
protected:
double _precision;
};
// VectorFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// BitmapFont
class OSGTEXT_EXPORT BitmapFont:public RasterFont
{
public:
BitmapFont() {;}
BitmapFont(const std::string& font,
int point_size);
META_Object(BitmapFont);
protected:
virtual FTFont* createFontObj(void);
};
// BitmapFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PixmapFont
class OSGTEXT_EXPORT PixmapFont:public RasterFont
{
public:
PixmapFont() {;}
PixmapFont(const std::string& font,
int point_size);
META_Object(PixmapFont);
protected:
virtual FTFont* createFontObj(void);
};
// PixmapFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// TextureFont
class OSGTEXT_EXPORT TextureFont:public RasterFont
{
public:
TextureFont() {;}
TextureFont(const std::string& font,
int point_size);
META_Object(TextureFont);
protected:
virtual FTFont* createFontObj(void);
};
// PixmapFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// OutlineFont
class OSGTEXT_EXPORT OutlineFont:public VectorFont
{
public:
OutlineFont() {;}
OutlineFont(const std::string& font,
int point_size,
double precision);
META_Object(OutlineFont);
protected:
virtual FTFont* createFontObj(void);
};
// OutlineFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PolygonFont
class OSGTEXT_EXPORT PolygonFont:public VectorFont
{
public:
PolygonFont() {;}
PolygonFont(const std::string& font,
int point_size,
double precision);
META_Object(PolygonFont);
protected:
virtual FTFont* createFontObj(void);
};
// PolygonFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Text
class OSGTEXT_EXPORT Text:public osg::Drawable
class OSGTEXT_EXPORT Text : public osg::Drawable
{
public:
@ -278,8 +81,8 @@ public:
void setBoundingBox(int mode);
int getBoundingBox() const { return _boundingBoxType; }
void setAlignement(int alignement);
int getAlignement() const { return _alignement; }
void setAlignment(int alignment);
int getAlignment() const { return _alignment; }
void setFont(Font* font);
Font* getFont() { return _font.get(); }
@ -291,9 +94,9 @@ public:
virtual void drawImmediateMode(osg::State& state);
virtual void drawBoundingBox(void);
virtual void drawAlignement(void);
virtual void drawAlignment(void);
const osg::Vec3& getAlignementPos() const { return _alignementPos; };
const osg::Vec3& getAlignmentPos() const { return _alignmentPos; };
protected:
@ -313,25 +116,25 @@ protected:
virtual void setDefaults(void);
virtual const bool computeBound(void) const;
virtual void calcBounds(osg::Vec3* min,osg::Vec3* max) const;
void initAlignement(osg::Vec3* min,osg::Vec3* max);
bool initAlignement(void);
void initAlignment(osg::Vec3* min,osg::Vec3* max);
bool initAlignment(void);
osg::ref_ptr<Font> _font;
bool _init;
bool _initAlignement;
bool _initAlignment;
std::string _text;
int _fontType;
int _alignement;
int _alignment;
int _drawMode;
int _boundingBoxType;
osg::Vec3 _pos;
osg::Vec3 _alignementPos;
osg::Vec3 _alignmentPos;
};
// Text
///////////////////////////////////////////////////////////////////////////////
};
#endif // _OSG_TEXT_H
#endif // OSGTEXT_TEXT

View File

@ -11,7 +11,6 @@ using namespace osg;
Node::Node()
{
_bsphere_computed = false;
_userData = NULL;
_nodeMask = 0xffffffff;
_numChildrenRequiringAppTraversal = 0;
@ -24,7 +23,6 @@ Node::Node()
Node::~Node()
{
if (_userData && _memoryAdapter.valid()) _memoryAdapter->unref_data(_userData);
}

View File

@ -1,6 +1,5 @@
Notes
=====
Currently there is no read/write .osg support for osg::Lighting.
The support in Image.cpp is also not full functional and should be rewritten
in the future to support inline images. Currently osg::Images are supported

View File

@ -20,6 +20,8 @@ C++FILES = \
FTSize.cpp \
FTTextureGlyph.cpp \
FTVectoriser.cpp \
Font.cpp \
Paragraph.cpp \
Text.cpp \
Version.cpp
@ -35,8 +37,10 @@ LIB = ../../lib/lib$(TARGET_BASENAME).so
TARGET_LIB_FILES = lib$(TARGET_BASENAME).so
TARGET_INCLUDE_FILES = \
osgText/Export\
osgText/Version\
osgText/Text
osgText/Font\
osgText/Paragraph\
osgText/Text\
osgText/Version
C++FLAGS += -I ../../include -I /usr/include/freetype2 -I /usr/local/include/freetype2

View File

@ -28,298 +28,6 @@
using namespace osg;
using namespace osgText;
// define the default paths to look for fonts.
// note delimator is : for unix, ; for windows.
#if defined(__linux) || defined(__FreeBSD__) || defined (__sgi)
static char* s_FontFilePath = ".:/usr/share/fonts/ttf:/usr/share/fonts/ttf/western:/usr/share/fonts/ttf/decoratives";
#elif defined(WIN32)
static char* s_FontFilePath = ".;C:/windows/fonts";
#else
static char* s_FontFilePath = ".:";
#endif
std::string findFontFile(const std::string& str)
{
// try looking in OSGFILEPATH etc first for fonts.
char* filename = osgDB::findFile(str.c_str());
if (filename) return std::string(filename);
// else fallback into the standard font file paths.
if (s_FontFilePath)
{
filename = osgDB::findFileInPath(str.c_str(),s_FontFilePath);
if (filename) return std::string(filename);
}
return std::string();
}
///////////////////////////////////////////////////////////////////////////////
// Font
Font::
Font()
{
_init=false;
_font=NULL;
_created=false;
_pointSize=14;
_res=72;
}
bool Font::
init(const std::string& font)
{
_font=NULL;
_created=false;
open(font);
if(_font!=NULL)
return true;
else
return false;
}
Font::
~Font()
{
clear();
}
bool Font::
open(const std::string& font)
{
clear();
std::string filename = findFontFile(font);
if (filename.empty()) return false;
_font=createFontObj();
if( _font!=NULL && _font->Open(filename.c_str()) )
{
_init=true;
_fontName=font;
return true;
}
else
return false;
}
bool Font::
create(int pointSize,const unsigned int res)
{
_pointSize=pointSize;
_res=res;
return create();
}
bool Font::
create()
{
if(_init)
{
if(_font->FaceSize(_pointSize,_res))
{
_created=true;
return true;
}
else
return false;
}
else
return false;
}
void Font::
output(const char* text)
{
if(_created)
_font->render(text);
else
create(_pointSize);
}
void Font::
clear()
{
_init=false;
if(_font)
{
delete _font;
_font=NULL;
}
_fontName="";
}
float Font::
getWidth(const char* text) const
{
if(_init && _created)
return _font->Advance(text);
else
return -1;
}
int Font::
getHeight() const
{
if(_init && _created)
return _pointSize;
else
return -1;
}
int Font::
getDescender() const
{
if(_init && _created)
return _font->Descender();
else
return -1;
}
int Font::
getAscender() const
{
if(_init && _created)
return _font->Ascender();
else
return -1;
}
// Font
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// BitmapFont
BitmapFont::
BitmapFont(const std::string& font,
int point_size):
RasterFont()
{
if(init(font))
{
}
_pointSize=point_size;
}
FTFont* BitmapFont::
createFontObj(void)
{
return (FTFont*)(new FTGLBitmapFont);
}
// BitmapFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PixmapFont
PixmapFont::
PixmapFont(const std::string& font,
int point_size):
RasterFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
}
FTFont* PixmapFont::
createFontObj(void)
{
return (FTFont*)(new FTGLPixmapFont);
}
// PixmapFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PixmapFont
TextureFont::
TextureFont(const std::string& font,
int point_size):
RasterFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
}
FTFont* TextureFont::
createFontObj(void)
{
return (FTFont*)(new FTGLTextureFont);
}
// PixmapFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// _FTGLOutlineFont
OutlineFont::
OutlineFont(const std::string& font,
int point_size,
double precision):
VectorFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
_precision=precision;
}
FTFont* OutlineFont::
createFontObj(void)
{
return (FTFont*)(new FTGLOutlineFont);
}
// _FTGLOutlineFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PolygonFont
PolygonFont::
PolygonFont(const std::string& font,
int point_size,
double precision):
VectorFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
_precision=precision;
}
FTFont* PolygonFont::
createFontObj(void)
{
return (FTFont*)(new FTGLPolygonFont);
}
// PolygonFont
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Text
Text::