From David Callu, added support of 3D text to osgText and associated plugins.

This commit is contained in:
Robert Osfield
2007-12-10 15:15:56 +00:00
parent 9b56dbe83a
commit f69a48e552
27 changed files with 3427 additions and 798 deletions

View File

@@ -25,6 +25,7 @@
#include <osg/TexEnv>
#include <osgDB/ReaderWriter>
#include <osgText/Export>
#include <osgText/KerningType>
#include <OpenThreads/Mutex>
@@ -32,12 +33,7 @@ namespace osgText {
class Font;
class Text;
enum KerningType
{
KERNING_DEFAULT, //default locked to integer kerning values
KERNING_UNFITTED, //use floating point value for kerning
KERNING_NONE //no kerning
};
/** Read a font from specified file. The filename may contain a path.
* It will search for the font file in the following places in this order:
@@ -179,8 +175,6 @@ protected:
typedef std::pair< unsigned int, unsigned int > SizePair;
typedef std::map< SizePair, GlyphMap > SizeGlyphMap;
mutable FontMutex _serializeFontCallsMutex;
osg::ref_ptr<osg::TexEnv> _texenv;
osg::ref_ptr<osg::StateSet> _stateset;
SizeGlyphMap _sizeGlyphMap;

284
include/osgText/Font3D Normal file
View File

@@ -0,0 +1,284 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
*/
#ifndef OSGTEXT_FONT3D
#define OSGTEXT_FONT3D 1
#include <string>
#include <istream>
#include <osg/Vec2>
#include <osg/Geometry>
#include <osgDB/ReaderWriter>
#include <osgText/Export>
#include <osgText/KerningType>
#include <OpenThreads/Mutex>
namespace osgText {
class Font3D;
class Text3D;
/** Read a font from specified file. The filename may contain a path.
* It will search for the font file in the following places in this order:
* - In the current directory
* - All paths defined in OSG_FILE_PATH or OSGFILEPATH environment variable
* - Filename with path stripped: In the current directory
* - Filename with path stripped: All paths defined in OSG_FILE_PATH or OSGFILEPATH
*
* Then the file will be searched in OS specific directories in the following order:
* - Again in the current directory
* - Windows: In C:/winnt/fonts
* - Windows: In C:/windows/fonts
* - Windows: In the fonts directory of the windows install directory
* - Other OS: In /usr/share/fonts/ttf
* - Other OS: In /usr/share/fonts/ttf/western
* - Other OS: In /usr/share/fonts/ttf/decoratives
*
* If the given file could not be found, the path part will be stripped and
* the file will be searched again in the OS specific directories.
*/
extern OSGTEXT_EXPORT Font3D* readFont3DFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0);
/** read a font from specified stream.*/
extern OSGTEXT_EXPORT Font3D* readFont3DStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
extern OSGTEXT_EXPORT std::string findFont3DFile(const std::string& str);
/** 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*/
class OSGTEXT_EXPORT Font3D : public osg::Object
{
// declare the interface to a font.
public:
// forward declare nested classes.
class Glyph3D;
class Font3DImplementation;
public:
Font3D(Font3DImplementation* implementation=0);
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 Font3D*>(obj)!=NULL; }
virtual const char* className() const { return "Font3D"; }
virtual const char* libraryName() const { return "osgText"; }
virtual std::string getFileName() const;
/** Set the pixel width and height hint.*/
// virtual void setFontResolution(unsigned int width, unsigned int height, unsigned int depth);
unsigned int getFontWidth() const { return _width; }
unsigned int getFontHeight() const { return _height; }
unsigned int getFontDepth() const { return _depth; }
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType);
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
virtual Glyph3D* getGlyph(unsigned int charcode);
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
virtual bool hasVertical() const;
/** Return the scale to apply on the glyph to have a charactere size equal to 1 */
virtual float getScale() const { return _implementation->getScale(); };
// make Text a friend to allow it add and remove its entry in the Font's _textList.
friend class Font3DImplementation;
void setImplementation(Font3DImplementation* implementation);
Font3DImplementation* getImplementation();
const Font3DImplementation* getImplementation() const;
/** Set whether to use a mutex to ensure ref() and unref() */
virtual void setThreadSafeRefUnref(bool threadSafe);
typedef OpenThreads::Mutex Font3DMutex;
/** Get the mutex that enables the serialization of calls to this font.*/
static Font3DMutex* getSerializeFontCallsMutex();
protected:
virtual ~Font3D();
// void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph);
void addGlyph(unsigned int charcode, Glyph3D* glyph);
// current active size of font
unsigned int _depth;
unsigned int _width;
unsigned int _height;
// unsigned int _margin;
// float _marginRatio;
typedef std::map<char, osg::ref_ptr<Glyph3D> > Glyph3DMap;
Glyph3DMap _glyph3DMap;
osg::ref_ptr<Font3DImplementation> _implementation;
// declare the nested classes.
public:
class Font3DImplementation : public osg::Referenced
{
public:
Font3DImplementation():
osg::Referenced(true) {}
virtual std::string getFileName() const = 0;
/** Set the pixel width and height hint.*/
// virtual void setFontResolution(unsigned int width, unsigned int height, unsigned int depth) = 0;
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
virtual Glyph3D* getGlyph(unsigned int charcode) = 0;
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType) = 0;
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
virtual bool hasVertical() const = 0;
virtual float getScale() const = 0;
void setFontWidth(unsigned int width) { _facade->_width = width; }
void setFontHeight(unsigned int height) { _facade->_height = height; }
void setFontDepth(unsigned int depth) { _facade->_depth = depth; }
// void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph3D* glyph)
// {
// _facade->addGlyph(width, height, charcode, glyph);
// }
//
// void addGlyph(unsigned int charcode, Glyph3D* glyph)
// {
// _facade->addGlyph(charcode, glyph);
// }
Font3D* _facade;
};
class OSGTEXT_EXPORT Glyph3D : public osg::Referenced
{
public:
Glyph3D(unsigned int glyphCode):
_glyphCode(glyphCode),
_horizontalBearing(0,0),
_horizontalAdvance(0),
_verticalBearing(0,0),
_verticalAdvance(0)
{}
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
// virtual int compare(const osg::StateAttribute& rhs) const;
//
// virtual void apply(osg::State& state) const;
unsigned int getGlyphCode() const { return _glyphCode; }
void setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; }
const osg::Vec2 & getHorizontalBearing() const { return _horizontalBearing; }
void setHorizontalAdvance(float advance) { _horizontalAdvance=advance; }
float getHorizontalAdvance() const { return _horizontalAdvance; }
void setVerticalBearing(const osg::Vec2& bearing) { _verticalBearing=bearing; }
const osg::Vec2& getVerticalBearing() const { return _verticalBearing; }
void setVerticalAdvance(float advance) { _verticalAdvance=advance; }
float getVerticalAdvance() const { return _verticalAdvance; }
void setBoundingBox(osg::BoundingBox & bb) { _bb=bb; }
const osg::BoundingBox & getBoundingBox() const { return _bb; }
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
virtual void setThreadSafeRefUnref(bool threadSafe);
/** Get the PrimitiveSetList for the front face. */
osg::Geometry::PrimitiveSetList & getFrontPrimitiveSetList() { return _frontPrimitiveSetList; }
/** Get the PrimitiveSetList for the wall face. */
osg::Geometry::PrimitiveSetList & getWallPrimitiveSetList() { return _wallPrimitiveSetList; }
/** Get et the PrimitiveSetList for the back face. */
osg::Geometry::PrimitiveSetList & getBackPrimitiveSetList() { return _backPrimitiveSetList; }
/** Set the VertexArray of the glyph. */
void setVertexArray(osg::Vec3Array * va) { _vertexArray = va; }
/** Get the VertexArray of the glyph. */
osg::Vec3Array * getVertexArray() { return _vertexArray.get(); }
/** Get the NormalArray for the wall face. */
osg::Vec3Array * getNormalArray() { return _normalArray.get(); }
float getHorizontalWidth() { return (-_horizontalBearing.x() + _horizontalAdvance); }
float getHorizontalHeight() { return (-_horizontalBearing.y() + _bb.yMax()); }
float getVerticalWidth() { return (-_verticalBearing.x() + _bb.xMax()); }
float getVerticalHeight() { return (-_verticalBearing.y() + _verticalAdvance); }
void setWidth(float width) { _width = width; }
float getWidth() { return _width; }
void setHeight(float height) { _height = height; }
float getHeight() { return _height; }
protected:
virtual ~Glyph3D() {}
unsigned int _glyphCode;
osg::Vec2 _horizontalBearing;
float _horizontalAdvance;
osg::Vec2 _verticalBearing;
float _verticalAdvance;
osg::BoundingBox _bb;
// osg::Vec2 _advance;
float _width;
float _height;
osg::ref_ptr<osg::Vec3Array> _vertexArray;
osg::ref_ptr<osg::Vec3Array> _normalArray;
osg::Geometry::PrimitiveSetList _frontPrimitiveSetList;
osg::Geometry::PrimitiveSetList _wallPrimitiveSetList;
osg::Geometry::PrimitiveSetList _backPrimitiveSetList;
};
};
}
#endif

View File

@@ -0,0 +1,26 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
*/
#ifndef OSGTEXT_KERNINGTYPE
#define OSGTEXT_KERNINGTYPE
namespace osgText
{
enum KerningType
{
KERNING_DEFAULT, //default locked to integer kerning values
KERNING_UNFITTED, //use floating point value for kerning
KERNING_NONE //no kerning
};
}
#endif /*OSGTEXT_KERNINGTYPE*/

View File

@@ -14,16 +14,17 @@
#ifndef OSGTEXT_TEXT
#define OSGTEXT_TEXT 1
#include <osg/Drawable>
#include <osg/Quat>
#include <osgText/TextBase>
#include <osgText/Font>
#include <osgText/String>
namespace osgText {
class OSGTEXT_EXPORT Text : public osg::Drawable
class OSGTEXT_EXPORT Text : public osgText::TextBase
{
public:
@@ -50,179 +51,14 @@ public:
const Font* getFont() const { return _font.get(); }
/** Set the Font reference width and height resolution in texels.
* Note, the size may not be supported by current font,
* the closest supported font size will be selected.*/
void setFontResolution(unsigned int width, unsigned int height);
unsigned int getFontWidth() const { return _fontWidth; }
unsigned int getFontHeight() const { return _fontHeight; }
/** Set the text using a osgText::String.*/
void setText(const String& text);
/** Set the text using a std::string,
* which is converted to an internal TextString.*/
void setText(const std::string& text);
/** Set the text using a Unicode encoded std::string, which is converted to an internal TextString.
* The encoding parameter specificies which Unicode encodeding is used in the std::string. */
void setText(const std::string& text,String::Encoding encoding);
/** Set the text using a wchar_t string,
* which is converted to an internal TextString.*/
void setText(const wchar_t* text);
/** Get the text string.
* Note, if you modify the string you must call Text::update() for
* the internal glyph reprentation to be updated.*/
String& getText() { return _text; }
/** Get the const text string.*/
const String& getText() const { return _text; }
/** update internal glyph respresnetation used for rendering,
* and bounding volume.*/
void update() { computeGlyphRepresentation(); }
/** Set the rendered character size in object coordinates.*/
void setCharacterSize(float height,float aspectRatio=1.0f);
float getCharacterHeight() const { return _characterHeight; }
float getCharacterAspectRatio() const { return _characterAspectRatio; }
enum CharacterSizeMode
{
OBJECT_COORDS, /// default
SCREEN_COORDS, /// internally scale the characters to be constant screen size.
OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT /// text that behavaves like OBJECT_COORDS sized text when a long distance way, but has its screen sized capped automatically when the viewer gets near.
};
/** Set how the CharacterSize value relates to the final rendered character.*/
void setCharacterSizeMode(CharacterSizeMode mode) { _characterSizeMode = mode; }
/** Get the CharacterSizeMode.*/
CharacterSizeMode getCharacterSizeMode() const { return _characterSizeMode; }
/** Set the maximum width of the text box.
* With horizontal layouts any characters which do not fit are wrapped around.
* 0 or negative values indicate that no maximum width is set, lines can be as long as
* they need be to fit thre required text*/
void setMaximumWidth(float maximumWidth);
/** Get the maximim width of the text box.*/
float getMaximumWidth() const { return _maximumWidth; }
/** Set the maximum height of the text box.
* With horizontal layouts any characters which do not fit are wrapped around.
* 0 or negative values indicate that no maximum height is set, lines can be as long as
* they need be to fit the required text*/
void setMaximumHeight(float maximumHeight);
/** Get the maximum height of the text box.*/
float getMaximumHeight() const { return _maximumHeight; }
/** Set the line spacing of the text box, given as a percentage of
* the character height. The default value is 0 for backward
* compatibility. For longer paragraphs of text, a value of at
* least 25% (i.e. set line spacing to 0.25) is recommended. */
void setLineSpacing(float lineSpacing);
/** Get the line spacing of the text box. */
float getLineSpacing() const { return _lineSpacing; }
/** Set the position of text.*/
void setPosition(const osg::Vec3& pos);
/** Get the position of text.*/
const osg::Vec3& getPosition() const { return _position; }
enum AlignmentType
{
LEFT_TOP,
LEFT_CENTER,
LEFT_BOTTOM,
CENTER_TOP,
CENTER_CENTER,
CENTER_BOTTOM,
RIGHT_TOP,
RIGHT_CENTER,
RIGHT_BOTTOM,
LEFT_BASE_LINE,
CENTER_BASE_LINE,
RIGHT_BASE_LINE,
LEFT_BOTTOM_BASE_LINE,
CENTER_BOTTOM_BASE_LINE,
RIGHT_BOTTOM_BASE_LINE,
BASE_LINE = LEFT_BASE_LINE /// default.
};
void setAlignment(AlignmentType alignment);
AlignmentType getAlignment() const { return _alignment; }
enum AxisAlignment
{
XY_PLANE,
REVERSED_XY_PLANE,
XZ_PLANE,
REVERSED_XZ_PLANE,
YZ_PLANE,
REVERSED_YZ_PLANE,
SCREEN,
USER_DEFINED_ROTATION
};
void setAxisAlignment(AxisAlignment axis);
AxisAlignment getAxisAlignment() const { return _axisAlignment; }
void setRotation(const osg::Quat& quat);
const osg::Quat& getRotation() const { return _rotation; }
void setAutoRotateToScreen(bool autoRotateToScreen);
bool getAutoRotateToScreen() const { return _autoRotateToScreen; }
enum Layout
{
LEFT_TO_RIGHT, /// default
RIGHT_TO_LEFT,
VERTICAL
};
void setLayout(Layout layout);
Layout getLayout() const { return _layout; }
void setColor(const osg::Vec4& color);
const osg::Vec4& getColor() const { return _color; }
enum DrawModeMask
{
TEXT = 1, /// default
BOUNDINGBOX = 2,
ALIGNMENT = 4
};
void setDrawMode(unsigned int mode);
unsigned int getDrawMode() const { return _drawMode; }
enum BackdropType
{
DROP_SHADOW_BOTTOM_RIGHT = 0, // usually the type of shadow you see
@@ -417,13 +253,7 @@ public:
const osg::Vec4& getColorGradientTopRight() const { return _colorGradientTopRight; }
void setKerningType(KerningType kerningType) { _kerningType = kerningType; }
KerningType getKerningType() const { return _kerningType; }
/** Get the number of wrapped lines - only valid after computeGlyphRepresentation() has been called, returns 0 otherwise */
unsigned int getLineCount() const { return _lineCount; }
/** Draw the text.*/
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
@@ -454,9 +284,9 @@ public:
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* state=0) const;
// make Font a friend to allow it set the _font to 0 if the font is
// forcefully unloaded.
friend class Font;
// // make Font a friend to allow it set the _font to 0 if the font is
// // forcefully unloaded.
// friend class Font;
public:
// internal structures, variable and methods used for rendering of characters.
@@ -510,7 +340,6 @@ public:
return _textureGlyphQuadMap;
}
virtual osg::BoundingBox computeBound() const;
protected:
@@ -523,26 +352,7 @@ protected:
// members which have public access.
osg::ref_ptr<Font> _font;
unsigned int _fontWidth;
unsigned int _fontHeight;
float _characterHeight;
float _characterAspectRatio;
CharacterSizeMode _characterSizeMode;
float _maximumWidth;
float _maximumHeight;
float _lineSpacing;
String _text;
osg::Vec3 _position;
AlignmentType _alignment;
AxisAlignment _axisAlignment;
osg::Quat _rotation;
bool _autoRotateToScreen;
Layout _layout;
osg::Vec4 _color;
unsigned int _drawMode;
KerningType _kerningType;
unsigned int _lineCount;
// iternal map used for rendering. Set up by the computeGlyphRepresentation() method.
mutable TextureGlyphQuadMap _textureGlyphQuadMap;
@@ -551,31 +361,9 @@ protected:
// internal caches of the positioning of the text.
struct AutoTransformCache
{
AutoTransformCache():
_traversalNumber(-1),
_width(0),
_height(0) {}
int _traversalNumber;
int _width;
int _height;
osg::Vec3 _transformedPosition;
osg::Matrix _modelview;
osg::Matrix _projection;
osg::Matrix _matrix;
};
mutable osg::buffered_object<AutoTransformCache> _autoTransformCache;
mutable osg::Vec3 _offset;
mutable osg::Vec3 _normal;
mutable osg::BoundingBox _textBB;
bool computeAverageGlyphWidthAndHeight(float& avg_width, float& avg_height) const;
void computePositions();
void computePositions(unsigned int contextID) const;
virtual void computePositions(unsigned int contextID) const;
void computeBackdropPositions(unsigned int contextID) const;
void computeBackdropBoundingBox() const;

292
include/osgText/TextBase Normal file
View File

@@ -0,0 +1,292 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
*/
#ifndef OSGTEXT_TEXTBASE
#define OSGTEXT_TEXTBASE 1
#include <osg/Drawable>
#include <osgText/String>
#include <osgText/KerningType>
namespace osgText {
class OSGTEXT_EXPORT TextBase : public osg::Drawable
{
public:
TextBase();
TextBase(const TextBase& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
//virtual osg::Object* cloneType() const { return new Text(); }
//virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TextBase*>(obj)!=NULL; }
virtual const char* className() const { return "TextBase"; }
virtual const char* libraryName() const { return "osgText"; }
/** Set the Font reference width and height resolution in texels.
* Note, the size may not be supported by current font,
* the closest supported font size will be selected.*/
void setFontResolution(unsigned int width, unsigned int height);
unsigned int getFontWidth() const { return _fontWidth; }
unsigned int getFontHeight() const { return _fontHeight; }
/** Set the text using a osgText::String.*/
void setText(const String& text);
/** Set the text using a std::string,
* which is converted to an internal TextString.*/
void setText(const std::string& text);
/** Set the text using a Unicode encoded std::string, which is converted to an internal TextString.
* The encoding parameter specificies which Unicode encodeding is used in the std::string. */
void setText(const std::string& text,String::Encoding encoding);
/** Set the text using a wchar_t string,
* which is converted to an internal TextString.*/
void setText(const wchar_t* text);
/** Get the text string.
* Note, if you modify the string you must call Text::update() for
* the internal glyph reprentation to be updated.*/
String& getText() { return _text; }
/** Get the const text string.*/
const String& getText() const { return _text; }
/** update internal glyph respresentation used for rendering,
* and bounding volume.*/
void update() { computeGlyphRepresentation(); }
/** Set the rendered character size in object coordinates.*/
void setCharacterSize(float height,float aspectRatio=1.0f);
float getCharacterHeight() const { return _characterHeight; }
float getCharacterAspectRatio() const { return _characterAspectRatio; }
enum CharacterSizeMode
{
OBJECT_COORDS, /// default
SCREEN_COORDS, /// internally scale the characters to be constant screen size.
OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT /// text that behavaves like OBJECT_COORDS sized text when a long distance way, but has its screen sized capped automatically when the viewer gets near.
};
/** Set how the CharacterSize value relates to the final rendered character.*/
void setCharacterSizeMode(CharacterSizeMode mode) { _characterSizeMode = mode; }
/** Get the CharacterSizeMode.*/
CharacterSizeMode getCharacterSizeMode() const { return _characterSizeMode; }
/** Set the maximum width of the text box.
* With horizontal layouts any characters which do not fit are wrapped around.
* 0 or negative values indicate that no maximum width is set, lines can be as long as
* they need be to fit thre required text*/
void setMaximumWidth(float maximumWidth);
/** Get the maximim width of the text box.*/
float getMaximumWidth() const { return _maximumWidth; }
/** Set the maximum height of the text box.
* With horizontal layouts any characters which do not fit are wrapped around.
* 0 or negative values indicate that no maximum height is set, lines can be as long as
* they need be to fit the required text*/
void setMaximumHeight(float maximumHeight);
/** Get the maximum height of the text box.*/
float getMaximumHeight() const { return _maximumHeight; }
/** Set the line spacing of the text box, given as a percentage of
* the character height. The default value is 0 for backward
* compatibility. For longer paragraphs of text, a value of at
* least 25% (i.e. set line spacing to 0.25) is recommended. */
void setLineSpacing(float lineSpacing);
/** Get the line spacing of the text box. */
float getLineSpacing() const { return _lineSpacing; }
/** Set the position of text.*/
void setPosition(const osg::Vec3& pos);
/** Get the position of text.*/
const osg::Vec3& getPosition() const { return _position; }
enum AlignmentType
{
LEFT_TOP,
LEFT_CENTER,
LEFT_BOTTOM,
CENTER_TOP,
CENTER_CENTER,
CENTER_BOTTOM,
RIGHT_TOP,
RIGHT_CENTER,
RIGHT_BOTTOM,
LEFT_BASE_LINE,
CENTER_BASE_LINE,
RIGHT_BASE_LINE,
LEFT_BOTTOM_BASE_LINE,
CENTER_BOTTOM_BASE_LINE,
RIGHT_BOTTOM_BASE_LINE,
BASE_LINE = LEFT_BASE_LINE /// default.
};
void setAlignment(AlignmentType alignment);
AlignmentType getAlignment() const { return _alignment; }
enum AxisAlignment
{
XY_PLANE,
REVERSED_XY_PLANE,
XZ_PLANE,
REVERSED_XZ_PLANE,
YZ_PLANE,
REVERSED_YZ_PLANE,
SCREEN,
USER_DEFINED_ROTATION
};
void setAxisAlignment(AxisAlignment axis);
AxisAlignment getAxisAlignment() const { return _axisAlignment; }
void setRotation(const osg::Quat& quat);
const osg::Quat& getRotation() const { return _rotation; }
void setAutoRotateToScreen(bool autoRotateToScreen);
bool getAutoRotateToScreen() const { return _autoRotateToScreen; }
enum Layout
{
LEFT_TO_RIGHT, /// default
RIGHT_TO_LEFT,
VERTICAL
};
void setLayout(Layout layout);
Layout getLayout() const { return _layout; }
enum DrawModeMask
{
TEXT = 1, /// default
BOUNDINGBOX = 2,
ALIGNMENT = 4
};
void setDrawMode(unsigned int mode);
unsigned int getDrawMode() const { return _drawMode; }
void setKerningType(KerningType kerningType) { _kerningType = kerningType; }
KerningType getKerningType() const { return _kerningType; }
/** Get the number of wrapped lines - only valid after computeGlyphRepresentation() has been called, returns 0 otherwise */
unsigned int getLineCount() const { return _lineCount; }
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
virtual void setThreadSafeRefUnref(bool threadSafe);
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize);
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* state=0) const;
virtual osg::BoundingBox computeBound() const;
protected:
virtual ~TextBase();
void positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cursor, unsigned int linelength);
void computePositions();
String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
virtual void computePositions(unsigned int contextID) const = 0;
virtual void computeGlyphRepresentation() = 0;
// members which have public access.
unsigned int _fontWidth;
unsigned int _fontHeight;
float _characterHeight;
float _characterAspectRatio;
CharacterSizeMode _characterSizeMode;
float _maximumWidth;
float _maximumHeight;
float _lineSpacing;
String _text;
osg::Vec3 _position;
AlignmentType _alignment;
AxisAlignment _axisAlignment;
osg::Quat _rotation;
bool _autoRotateToScreen;
Layout _layout;
unsigned int _drawMode;
KerningType _kerningType;
unsigned int _lineCount;
// internal caches of the positioning of the text.
struct AutoTransformCache
{
AutoTransformCache():
_traversalNumber(-1),
_width(0),
_height(0) {}
int _traversalNumber;
int _width;
int _height;
osg::Vec3 _transformedPosition;
osg::Matrix _modelview;
osg::Matrix _projection;
osg::Matrix _matrix;
};
mutable osg::buffered_object<AutoTransformCache> _autoTransformCache;
mutable osg::Vec3 _offset;
mutable osg::Vec3 _normal;
mutable osg::BoundingBox _textBB;
};
}
#endif