Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::TextFace Class Reference

#include <OSGTextFace.h>

Inheritance diagram for osg::TextFace:

osg::MemoryObject osg::TextPixmapFace osg::TextTXFFace osg::TextVectorFace List of all members.

Public Types

enum  Style { STYLE_PLAIN, STYLE_BOLD, STYLE_ITALIC, STYLE_BOLDITALIC }

Public Member Functions

const std::string getFamily () const
Style getStyle () const
Real32 getHoriAscent () const
Real32 getVertAscent () const
Real32 getHoriDescent () const
Real32 getVertDescent () const
virtual const TextGlyphgetGlyph (TextGlyph::Index glyphIndex)=0
virtual void layout (const std::string &utf8Text, const TextLayoutParam &param, TextLayoutResult &result)
virtual void layout (const std::wstring &text, const TextLayoutParam &param, TextLayoutResult &result)=0
virtual void layout (const std::vector< std::string > &lines, const TextLayoutParam &param, TextLayoutResult &result)
virtual void layout (const std::vector< std::wstring > &lines, const TextLayoutParam &param, TextLayoutResult &result)
void calculateBoundingBox (const TextLayoutResult &layoutResult, Vec2f &lowerLeft, Vec2f &upperRight)
Reference Counting
*void addRef (void)
void subRef (void)
Int32 getRefCount (void)

Static Public Member Functions

static void convertUTF8ToUnicode (const std::string &utf8Text, std::wstring &text)

Protected Member Functions

 TextFace ()
virtual ~TextFace ()
void justifyLine (const TextLayoutParam &param, const std::vector< UInt32 > &spaceIndices, Vec2f &currPos, TextLayoutResult &layoutResult) const
void adjustLineOrigin (const TextLayoutParam &param, const Vec2f &currPos, TextLayoutResult &layoutResult) const

Protected Attributes

std::string _family
Style _style
Real32 _horiAscent
Real32 _vertAscent
Real32 _horiDescent
Real32 _vertDescent

Private Member Functions

 TextFace (const TextFace &)
const TextFaceoperator= (const TextFace &)

Detailed Description

Abstract base class of all faces.
Author:
Patrick Dähne

Definition at line 69 of file OSGTextFace.h.


Member Enumeration Documentation

enum osg::TextFace::Style
 

Defines the styles of a face

Enumerator:
STYLE_PLAIN 
STYLE_BOLD 
STYLE_ITALIC 
STYLE_BOLDITALIC 

Definition at line 75 of file OSGTextFace.h.

00076     {
00077         STYLE_PLAIN,
00078         STYLE_BOLD,
00079         STYLE_ITALIC,
00080         STYLE_BOLDITALIC
00081     };


Constructor & Destructor Documentation

osg::TextFace::TextFace  )  [inline, protected]
 

Creates a new TextFace object.

Definition at line 61 of file OSGTextFace.inl.

00062 : _family(), _style(STYLE_PLAIN),
00063   _horiAscent(0.f), _vertAscent(0.f),
00064   _horiDescent(0.f), _vertDescent(0.f)
00065 {}

osg::TextFace::~TextFace  )  [protected, virtual]
 

Destroys the TextFace object.

Definition at line 65 of file OSGTextFace.cpp.

00065 {}

osg::TextFace::TextFace const TextFace  )  [private]
 

Copy constructor (not implemented!)


Member Function Documentation

const std::string osg::TextFace::getFamily  )  const [inline]
 

Returns the actual font family of the face.

Returns:
The font family.

Definition at line 43 of file OSGTextFace.inl.

References _family.

00043 { return _family; }

TextFace::Style osg::TextFace::getStyle  )  const [inline]
 

Returns the actual style of the face.

Returns:
The style.

Definition at line 46 of file OSGTextFace.inl.

References _style.

00046 { return _style; }

Real32 osg::TextFace::getHoriAscent  )  const [inline]
 

Returns the ascent of the face for horizontal layout. The ascent is the distance from the baseline to the top of the face.

Returns:
The ascent for horizontal layout.

Definition at line 49 of file OSGTextFace.inl.

References _horiAscent.

00049 { return _horiAscent; }

Real32 osg::TextFace::getVertAscent  )  const [inline]
 

Returns the ascent of the face for vertical layout. The ascent is the distance from the baseline to the left side of the face. This value is usually negative!

Returns:
The ascent for vertical layout.

Definition at line 52 of file OSGTextFace.inl.

References _vertAscent.

00052 { return _vertAscent; }

Real32 osg::TextFace::getHoriDescent  )  const [inline]
 

Returns the descent of the face for horizontal layout. The descent is the distance from the baseline to the bottom of the face. This value is usually negative!

Returns:
The descent for horizontal layout.

Definition at line 55 of file OSGTextFace.inl.

References _horiDescent.

00055 { return _horiDescent; }

Real32 osg::TextFace::getVertDescent  )  const [inline]
 

Returns the descent of the face for vertical layout. The descent is the distance from the baseline to the right side of the face.

Returns:
The descent for vertical layout.

Definition at line 58 of file OSGTextFace.inl.

References _vertDescent.

00058 { return _vertDescent; }

virtual const TextGlyph& osg::TextFace::getGlyph TextGlyph::Index  glyphIndex  )  [pure virtual]
 

Returns information about a glyph.

Parameters:
glyphIndex The index of the glyph. Use the layout method to get the glyph indices corresponding to a character string.
Returns:
A glyph object containing information about the glyph.

Implemented in osg::TextPixmapFace, osg::TextTXFFace, and osg::TextVectorFace.

Referenced by calculateBoundingBox().

virtual void osg::TextFace::layout const std::string &  utf8Text,
const TextLayoutParam param,
TextLayoutResult result
[virtual]
 

Lays out one line of text.

Parameters:
utf8Text The UTF8 encoded text.
param Contains parameters that affect the layout process.
result Gets filled with the layout results.

Reimplemented in osg::TextTXFFace.

virtual void osg::TextFace::layout const std::wstring &  text,
const TextLayoutParam param,
TextLayoutResult result
[pure virtual]
 

Lays out one line of text.

Parameters:
text The text.
param Contains parameters that affect the layout process.
result Gets filled with the layout results.

Implemented in osg::TextTXFFace.

virtual void osg::TextFace::layout const std::vector< std::string > &  lines,
const TextLayoutParam param,
TextLayoutResult result
[virtual]
 

Lays out multiple lines of text.

Parameters:
lines The vector of UTF8 encoded lines.
param Contains parameters that affect the layout process.
result Gets filled with the layout results.

Reimplemented in osg::TextTXFFace.

virtual void osg::TextFace::layout const std::vector< std::wstring > &  lines,
const TextLayoutParam param,
TextLayoutResult result
[virtual]
 

Lays out multiple lines of text.

Parameters:
lines The vector of text lines.
param Contains parameters that affect the layout process.
result Gets filled with the layout results.

Reimplemented in osg::TextTXFFace.

void osg::TextFace::calculateBoundingBox const TextLayoutResult layoutResult,
Vec2f lowerLeft,
Vec2f upperRight
 

Calculates the bounding box of a text after layout.

Parameters:
layoutResult The results of the layout operation
lowerLeft After returning from the method, contains the lower left position of the bounding box
upperRight After returning from the method, contains the lower left position of the bounding box

Definition at line 243 of file OSGTextFace.cpp.

References getGlyph(), osg::TextGlyph::getHeight(), osg::TextLayoutResult::getNumGlyphs(), osg::TextGlyph::getWidth(), osg::TextLayoutResult::indices, osg::TextLayoutResult::positions, osg::VecStorage2< ValueTypeT >::setValues(), osg::VecStorage2< ValueTypeT >::x(), and osg::VecStorage2< ValueTypeT >::y().

Referenced by osg::TextPixmapFace::makeImage().

00244 {
00245     // Initialize bounding box
00246     lowerLeft.setValues(FLT_MAX, FLT_MAX);
00247     upperRight.setValues(-FLT_MAX, -FLT_MAX);
00248 
00249     UInt32 i, numGlyphs = layoutResult.getNumGlyphs();
00250     for (i = 0; i < numGlyphs; ++i)
00251     {
00252         const TextGlyph &glyph = getGlyph(layoutResult.indices[i]);
00253         Real32 width = glyph.getWidth();
00254         Real32 height = glyph.getHeight();
00255         // Don't handle invisible glyphs
00256         if ((width <= 0.f) || (height <= 0.f))
00257             continue;
00258 
00259         // Calculate coodinates
00260         const Vec2f &pos = layoutResult.positions[i];
00261         Real32 left = pos.x();
00262         Real32 right = left + glyph.getWidth();
00263         Real32 top = pos.y();
00264         Real32 bottom = top - glyph.getHeight();
00265 
00266         // Adjust bounding box
00267         if (lowerLeft[0] > left)
00268             lowerLeft[0] = left;
00269         if (upperRight[0] < right)
00270             upperRight[0] = right;
00271         if (upperRight[1] < top)
00272             upperRight[1] = top;
00273         if (lowerLeft[1] > bottom)
00274             lowerLeft[1] = bottom;
00275     }
00276 }

static void osg::TextFace::convertUTF8ToUnicode const std::string &  utf8Text,
std::wstring &  text
[static]
 

Converts a UTF8 encoded string to a unicode string.

Parameters:
utf8Text The UTF8 encoded text string.
text A string that gets filled with the unicode version of the UTF8 encoded string.

Referenced by osg::TextTXFParam::setCharacters().

void osg::TextFace::justifyLine const TextLayoutParam param,
const std::vector< UInt32 > &  spaceIndices,
Vec2f currPos,
TextLayoutResult layoutResult
const [protected]
 

Justifies one line of text.

Parameters:
param The current layout parameters
spaceIndices The indices of space characters in the line
currPos The position on the base line behind the last character
layoutResult The glyph positions that get justified by this method.

void osg::TextFace::adjustLineOrigin const TextLayoutParam param,
const Vec2f currPos,
TextLayoutResult layoutResult
const [protected]
 

Adjusts the positions of glyphs, depending on the alignment.

Parameters:
param The current layout parameters
currPos The position on the base line behind the last character
layoutResult The glyph positions that gets adjusted by this method.

Definition at line 402 of file OSGTextFace.cpp.

References _horiAscent, _vertDescent, osg::TextLayoutParam::ALIGN_BEGIN, osg::TextLayoutParam::ALIGN_END, osg::TextLayoutParam::ALIGN_FIRST, osg::TextLayoutParam::ALIGN_MIDDLE, osg::TextLayoutParam::horizontal, osg::TextLayoutParam::leftToRight, osg::TextLayoutParam::majorAlignment, osg::TextLayoutParam::minorAlignment, osg::TextLayoutResult::positions, osg::TextLayoutParam::topToBottom, osg::VecStorage2< ValueTypeT >::x(), and osg::VecStorage2< ValueTypeT >::y().

00405 {
00406     Vec2f offset;
00407     if (param.horizontal == true)
00408     {
00409         switch (param.minorAlignment)
00410         {
00411             default:
00412             case TextLayoutParam::ALIGN_FIRST:  offset[1] = 0.f; break;
00413             case TextLayoutParam::ALIGN_BEGIN:  offset[1] = -_horiAscent; break;
00414             case TextLayoutParam::ALIGN_MIDDLE: offset[1] = -(_horiAscent + _horiDescent) / 2.f; break;
00415             case TextLayoutParam::ALIGN_END:    offset[1] = -_horiDescent; break;
00416         }
00417         if (param.leftToRight == true)
00418         {
00419             switch (param.majorAlignment)
00420             {
00421                 default:
00422                 case TextLayoutParam::ALIGN_FIRST:
00423                 case TextLayoutParam::ALIGN_BEGIN:
00424                     if (currPos.x() < 0)
00425                         offset[0] = -currPos.x();
00426                     break;
00427                 case TextLayoutParam::ALIGN_MIDDLE:
00428                     offset[0] = -currPos.x() / 2.f;
00429                     break;
00430                 case TextLayoutParam::ALIGN_END:
00431                     if (currPos.x() > 0)
00432                         offset[0] = -currPos.x();
00433                     break;
00434             }
00435         }
00436         else // leftToRight == false
00437         {
00438             switch (param.majorAlignment)
00439             {
00440                 default:
00441                 case TextLayoutParam::ALIGN_FIRST:
00442                 case TextLayoutParam::ALIGN_BEGIN:
00443                     if (currPos.x() > 0)
00444                         offset[0] = -currPos.x();
00445                     break;
00446                 case TextLayoutParam::ALIGN_MIDDLE:
00447                     offset[0] = -currPos.x() / 2.f;
00448                     break;
00449                 case TextLayoutParam::ALIGN_END:
00450                     if (currPos.x() < 0)
00451                         offset[0] = -currPos.x();
00452                     break;
00453             }
00454         }
00455     }
00456     else // param.horizontal == false
00457     {
00458         switch (param.minorAlignment)
00459         {
00460             default:
00461             case TextLayoutParam::ALIGN_FIRST:  offset[0] = 0.f; break;
00462             case TextLayoutParam::ALIGN_BEGIN:  offset[0] = -_vertAscent; break;
00463             case TextLayoutParam::ALIGN_MIDDLE: offset[0] = -(_vertAscent + _vertDescent) / 2.f; break;
00464             case TextLayoutParam::ALIGN_END:    offset[0] = -_vertDescent; break;
00465         }
00466         if (param.topToBottom == true)
00467         {
00468             switch (param.majorAlignment)
00469             {
00470                 default:
00471                 case TextLayoutParam::ALIGN_FIRST:
00472                 case TextLayoutParam::ALIGN_BEGIN:
00473                     if (currPos.y() > 0)
00474                         offset[1] = -currPos.y();
00475                     break;
00476                 case TextLayoutParam::ALIGN_MIDDLE:
00477                     offset[1] = -currPos.y() / 2.f;
00478                     break;
00479                 case TextLayoutParam::ALIGN_END:
00480                     if (currPos.y() < 0)
00481                         offset[1] = -currPos.y();
00482                     break;
00483             }
00484         }
00485         else // TopToBottom == false
00486         {
00487             switch (param.majorAlignment)
00488             {
00489                 default:
00490                 case TextLayoutParam::ALIGN_FIRST:
00491                 case TextLayoutParam::ALIGN_BEGIN:
00492                     if (currPos.y() < 0)
00493                         offset[1] = -currPos.y();
00494                     break;
00495                 case TextLayoutParam::ALIGN_MIDDLE:
00496                     offset[1] = -currPos.y() / 2.f;
00497                     break;
00498                 case TextLayoutParam::ALIGN_END:
00499                     if (currPos.y() > 0)
00500                         offset[1] = -currPos.y();
00501                     break;
00502             }
00503         }
00504     }
00505 
00506     // Adjust all glyph positions
00507     if ((offset.x() != 0.f) || (offset.y() != 0.f))
00508     {
00509         vector<Vec2f>::iterator it;
00510         for (it = layoutResult.positions.begin(); it != layoutResult.positions.end(); ++it)
00511             *it += offset;
00512     }
00513 }

const TextFace& osg::TextFace::operator= const TextFace  )  [private]
 

Copy operator (not implemented!)

void MemoryObject::addRef void   )  [inherited]
 

Definition at line 64 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

Referenced by osg::SharedObjectHandler::getSharedObject(), and osg::SharedObjectHandler::initialize().

00065 {
00066     _refCount++;
00067 }

void MemoryObject::subRef void   )  [inherited]
 

Definition at line 69 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00070 {
00071     _refCount--;
00072 
00073     if(_refCount <= 0)
00074         delete this;
00075 }

Int32 MemoryObject::getRefCount void   )  [inherited]
 

Definition at line 77 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00078 {
00079     return _refCount;
00080 }


Member Data Documentation

std::string osg::TextFace::_family [protected]
 

The font family of the face

Definition at line 201 of file OSGTextFace.h.

Referenced by getFamily().

Style osg::TextFace::_style [protected]
 

The style of the face

Definition at line 204 of file OSGTextFace.h.

Referenced by getStyle().

Real32 osg::TextFace::_horiAscent [protected]
 

The ascent of the font for horizontal layout

Definition at line 207 of file OSGTextFace.h.

Referenced by adjustLineOrigin(), and getHoriAscent().

Real32 osg::TextFace::_vertAscent [protected]
 

The ascent of the font for vertical layout

Definition at line 210 of file OSGTextFace.h.

Referenced by getVertAscent().

Real32 osg::TextFace::_horiDescent [protected]
 

The descent of the font for horizontal layout

Definition at line 213 of file OSGTextFace.h.

Referenced by getHoriDescent().

Real32 osg::TextFace::_vertDescent [protected]
 

The descent of the font for vertical layout

Definition at line 216 of file OSGTextFace.h.

Referenced by adjustLineOrigin(), and getVertDescent().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:23:02 2005 for OpenSG by  doxygen 1.4.3