osg::TextVectorFace Class Reference

#include <OSGTextVectorFace.h>

Inheritance diagram for osg::TextVectorFace:
osg::TextFace osg::MemoryObject

List of all members.

Public Types

enum  Style { STYLE_PLAIN, STYLE_BOLD, STYLE_ITALIC, STYLE_BOLDITALIC }

Public Member Functions

virtual const TextGlyphgetGlyph (TextGlyph::Index glyphIndex)
const TextVectorGlyphgetVectorGlyph (TextGlyph::Index glyphIndex)
void fillGeo (GeometryPtr &geoPtr, const TextLayoutResult &layoutResult, Real32 scale=1.f, Real32 depth=0.f, UInt32 level=2, Real32 creaseAngle=Pi/4.f)
GeometryPtr makeGeo (const TextLayoutResult &layoutResult, Real32 scale=1.f, Real32 depth=0.f, UInt32 level=2, Real32 creaseAngle=Pi/4.f)
NodePtr makeNode (const TextLayoutResult &layoutResult, Real32 scale=1.f, Real32 depth=0.f, UInt32 level=2, Real32 creaseAngle=Pi/4.f)
const std::string getFamily () const
Style getStyle () const
Real32 getHoriAscent () const
Real32 getVertAscent () const
Real32 getHoriDescent () const
Real32 getVertDescent () const
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 TextVectorFacecreate (const std::string &family, Style style=STYLE_PLAIN)
static void convertUTF8ToUnicode (const std::string &utf8Text, std::wstring &text)

Protected Types

typedef std::map
< TextGlyph::Index,
TextVectorGlyph * > 
GlyphMap

Protected Member Functions

 TextVectorFace ()
virtual ~TextVectorFace ()
virtual std::auto_ptr
< TextVectorGlyph
createGlyph (TextGlyph::Index glyphIndex)=0
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

Real32 _scale
GlyphMap _glyphMap
std::string _family
Style _style
Real32 _horiAscent
Real32 _vertAscent
Real32 _horiDescent
Real32 _vertDescent

Static Protected Attributes

static TextVectorGlyph _emptyGlyph

Private Member Functions

 TextVectorFace (const TextVectorFace &)
const TextVectorFaceoperator= (const TextVectorFace &)

Detailed Description

Represents a vector face. A vector face allows to create texts as 3D objects. The following piece of code demonstrates how to create and use TextVectorFace objects.

 // Includes
 #include "OSGTextVectorFace.h"
 #include "OSGTextLayoutParam.h"
 #include "OSGTextLayoutResult.h"

 // Try to create a new %TextVectorFace object. The create
 // method returns 0 in case of an error
 TextVectorFace *face = TextVectorFace::create("SANS");
 if (face == 0)
   ; // error handling

 // Increment the reference counter of the face object.
 // Faces are cached, and we might not be the only one
 // using the face object
 addRefP(face);

 // Lay out a single line of text. There are lots of parameters
 // you can set in the layoutParam object, but for now we are
 // satisfied with the default values. See the documentation
 // of the TextLayoutParam class for more information.
 TextLayoutParam layoutParam;
 TextLayoutResult layoutResult;
 face->layout("Hello World!", layoutParam, layoutResult);

 // Create the geometry using the layout information returned
 // from the previous call to the layout method.
 Real32 scale = 2.f;  // This is the height of the glyphs
 Real32 depth = 0.5f; // This is the depth of the glyphs
 GeometryPtr geo = face->makeGeo(layoutResult, scale, depth);

 // We do not need the vector face anymore, so decrement
 // the reference counter. Do not use the face object anymore!
 subRefP(face);
Author:
Patrick Dähne

Definition at line 111 of file OSGTextVectorFace.h.


Member Typedef Documentation

Defines a map of glyphs

Definition at line 206 of file OSGTextVectorFace.h.


Member Enumeration Documentation

enum osg::TextFace::Style [inherited]

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::TextVectorFace::TextVectorFace (  )  [inline, protected]

Creates a new TextVectorFace object.

Definition at line 43 of file OSGTextVectorFace.inl.

00044 : TextFace(), _scale(), _glyphMap()
00045 {}

osg::TextVectorFace::~TextVectorFace (  )  [protected, virtual]

Destroys the TextVectorFace object.

Definition at line 72 of file OSGTextVectorFace.cpp.

References _glyphMap.

00073 {
00074     // Delete all glyphs in the glyph cache
00075     GlyphMap::iterator it;
00076     for (it = _glyphMap.begin(); it != _glyphMap.end(); ++it)
00077     {
00078         assert(it->second != 0);
00079         delete it->second;
00080     }
00081 }

osg::TextVectorFace::TextVectorFace ( const TextVectorFace  )  [private]

Copy constructor (not implemented!)


Member Function Documentation

const TextGlyph & osg::TextVectorFace::getGlyph ( TextGlyph::Index  glyphIndex  )  [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.

Implements osg::TextFace.

Definition at line 88 of file OSGTextVectorFace.cpp.

References getVectorGlyph().

00089 {
00090     return getVectorGlyph(glyphIndex);
00091 }

const TextVectorGlyph & osg::TextVectorFace::getVectorGlyph ( TextGlyph::Index  glyphIndex  ) 

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.

Definition at line 98 of file OSGTextVectorFace.cpp.

References _emptyGlyph, _glyphMap, createGlyph(), and osg::TextGlyph::INVALID_INDEX.

Referenced by fillGeo(), and getGlyph().

00099 {
00100     if (glyphIndex == TextGlyph::INVALID_INDEX)
00101         return _emptyGlyph;
00102 
00103     // Try to find the glyph in the map of glyphs
00104     GlyphMap::const_iterator it = _glyphMap.find(glyphIndex);
00105     if (it != _glyphMap.end())
00106     {
00107         assert(it->second != 0);
00108         return *(it->second);
00109     }
00110 
00111     // We did not find the glyph, so we have to create it
00112     auto_ptr<TextVectorGlyph> glyph = createGlyph(glyphIndex);
00113 
00114     // We could not create the glyph, return 0
00115     if (glyph.get() == 0)
00116         return _emptyGlyph;
00117 
00118     // Put the glyph into the glyph cache
00119     _glyphMap.insert(GlyphMap::value_type(glyphIndex, glyph.get()));
00120 
00121     // Return the glyph
00122     return *(glyph.release());
00123 }

void osg::TextVectorFace::fillGeo ( GeometryPtr geoPtr,
const TextLayoutResult layoutResult,
Real32  scale = 1.f,
Real32  depth = 0.f,
UInt32  level = 2,
Real32  creaseAngle = Pi / 4.f 
)

Fills a geometry with a new text.

Parameters:
geoPtr The geometry that gets filled with the new text.
layoutResult The result of a layout operation.
scale The size of the glyphs.
depth The depth of the VectorGlyphs. If depth is 0.f no backside will be generated.
level The level of detail. Usually between 0 and 10.
creaseAngle The angle (in radians) which determines how faceted the glyphs should be lighted. If the angle enclosed by two vertex normals in a point exceeds the creaseAngle both of the two normals will be attached to the point. Otherwise their mean is used.

Definition at line 130 of file OSGTextVectorFace.cpp.

References osg::beginEditCP(), osg::TextVectorGlyph::CCW, osg::TextVectorGlyph::PolygonOutline::contours, osg::TextVectorGlyph::PolygonOutline::coords, create(), osg::FCPtr< BasePtrTypeT, FieldContainerTypeT >::dcast(), osg::endEditCP(), osg::GeoProperty< GeoPropertyDesc >::GeoPropDataFieldMask, osg::TextVectorGlyph::getContourOrientations(), osg::TextVectorGlyph::getLines(), osg::TextVectorGlyph::getNormals(), osg::TextLayoutResult::getNumGlyphs(), getVectorGlyph(), osg::TextVectorGlyph::PolygonOutline::indices, osg::TextLayoutResult::indices, osg::Geometry::MapNormal, osg::Geometry::MapPosition, osg::Geometry::MapTexCoords, osg::NullFC, osg::TextLayoutResult::positions, and osg::TextVectorGlyph::PolygonOutline::types.

Referenced by makeGeo().

00133 {
00134     beginEditCP(geoPtr);
00135 
00136     // cast the field containers down to the needed type and create them
00137     // when they have the wrong type
00138     GeoPositions3fPtr posPtr = GeoPositions3fPtr::dcast(geoPtr->getPositions());
00139     if (posPtr == NullFC)
00140     {
00141         posPtr = GeoPositions3f::create();
00142         geoPtr->setPositions(posPtr);
00143     }
00144     else
00145         posPtr->clear();
00146     GeoNormals3fPtr normalsPtr = GeoNormals3fPtr::dcast(geoPtr->getNormals());
00147     if (normalsPtr == NullFC)
00148     {
00149         normalsPtr = GeoNormals3f::create();
00150         geoPtr->setNormals(normalsPtr);
00151     }
00152     else
00153         normalsPtr->clear();
00154     GeoTexCoords2fPtr texPtr = GeoTexCoords2fPtr::dcast(geoPtr->getTexCoords());
00155     if (texPtr == NullFC)
00156     {
00157         texPtr = GeoTexCoords2f::create();
00158         geoPtr->setTexCoords(texPtr);
00159     }
00160     else
00161         texPtr->clear();
00162     GeoPLengthsUI32Ptr lensPtr = GeoPLengthsUI32Ptr::dcast(geoPtr->getLengths());
00163     if (lensPtr == NullFC)
00164     {
00165         lensPtr = GeoPLengthsUI32::create();
00166         geoPtr->setLengths(lensPtr);
00167     }
00168     else
00169         lensPtr->clear();
00170     GeoIndicesUI32Ptr indicesPtr = GeoIndicesUI32Ptr::dcast(geoPtr->getIndices());
00171     if (indicesPtr == NullFC)
00172     {
00173         indicesPtr = GeoIndicesUI32::create();
00174         geoPtr->setIndices(indicesPtr);
00175     }
00176     else
00177         indicesPtr->clear();
00178     GeoPTypesUI8Ptr typesPtr = GeoPTypesUI8Ptr::dcast(geoPtr->getTypes());
00179     if (typesPtr == NullFC)
00180     {
00181         typesPtr = GeoPTypesUI8::create();
00182         geoPtr->setTypes(typesPtr);
00183     }
00184     else
00185         typesPtr->clear();
00186 
00187     geoPtr->setColors(NullFC);
00188     geoPtr->setSecondaryColors(NullFC);
00189     geoPtr->setTexCoords1(NullFC);
00190     geoPtr->setTexCoords2(NullFC);
00191     geoPtr->setTexCoords3(NullFC);
00192     geoPtr->editMFIndexMapping()->clear();
00193 
00194     UInt32 numGlyphs = layoutResult.getNumGlyphs();
00195     if (numGlyphs == 0)
00196     {
00197         endEditCP(geoPtr);
00198         return;
00199     }
00200 
00201     // the interleaved multi-index blocks have the layout
00202     // Position | Normal | TexCoord
00203     geoPtr->editMFIndexMapping()->push_back(Geometry::MapPosition);
00204     geoPtr->editMFIndexMapping()->push_back(Geometry::MapNormal);
00205     geoPtr->editMFIndexMapping()->push_back(Geometry::MapTexCoords);
00206 
00207     beginEditCP(posPtr, GeoPositions3f::GeoPropDataFieldMask);
00208     beginEditCP(normalsPtr, GeoNormals3f::GeoPropDataFieldMask);
00209     beginEditCP(texPtr, GeoTexCoords2f::GeoPropDataFieldMask);
00210     beginEditCP(lensPtr, GeoPLengthsUI32::GeoPropDataFieldMask);
00211     beginEditCP(indicesPtr, GeoIndicesUI32::GeoPropDataFieldMask);
00212     beginEditCP(typesPtr, GeoPTypesUI8::GeoPropDataFieldMask);
00213 
00214     // store the normal for the front face
00215     normalsPtr->push_back(Vec3f(0.f, 0.f, 1.f));
00216     if (depth > 0.f)
00217         // store the normal for the back face
00218         normalsPtr->push_back(Vec3f(0.f, 0.f, -1.f));
00219 
00220     UInt32 i;
00221     for (i = 0; i < numGlyphs; ++i)
00222     {
00223         const TextVectorGlyph &glyph = getVectorGlyph(layoutResult.indices[i]);
00224         const TextVectorGlyph::PolygonOutline &outline = glyph.getLines(level);
00225         const Vec2f &pos = layoutResult.positions[i];
00226 
00227         // add the front face to the geometry
00228 
00229         // store positions and texture coordinates
00230         UInt32 coordOffset = posPtr->size();
00231         UInt32 texCoordOffset = texPtr->size();
00232         Real32 coordZ = 0.5f * depth;
00233         vector<Vec2f>::const_iterator cIt;
00234         for (cIt = outline.coords.begin(); cIt != outline.coords.end(); ++cIt)
00235         {
00236             Vec2f coord = *cIt + pos;
00237             Vec2f texCoord = coord;
00238             coord *= scale;
00239             posPtr->push_back(Vec3f(coord.x(), coord.y(), coordZ));
00240             texCoord -= layoutResult.positions.front();
00241             texPtr->push_back(texCoord);
00242         }
00243 
00244         // Store types, lengths and indices
00245         vector<TextVectorGlyph::PolygonOutline::TypeIndex>::const_iterator tIt;
00246         UInt32 indexBegin = 0, indexEnd;
00247         for (tIt = outline.types.begin(); tIt != outline.types.end(); ++tIt)
00248         {
00249             typesPtr->push_back(tIt->first);
00250             indexEnd = tIt->second;
00251             assert(indexEnd >= indexBegin);
00252             lensPtr->push_back(indexEnd - indexBegin);
00253             UInt32 i;
00254             for (i = indexBegin; i < indexEnd; ++i)
00255             {
00256                 // the interleaved multi-index blocks have the layout
00257                 // Position | Normal | TexCoord
00258                 assert(i < outline.indices.size());
00259                 UInt32 index = outline.indices[i];
00260                 assert(coordOffset + index < posPtr->size());
00261                 indicesPtr->push_back(coordOffset + index);
00262                 indicesPtr->push_back(0);
00263                 assert(texCoordOffset + index < texPtr->size());
00264                 indicesPtr->push_back(texCoordOffset + index);
00265             }
00266             indexBegin = indexEnd;
00267         }
00268 
00269         // add the back and side faces only if depth > 0
00270         if (depth > 0.f)
00271         {
00272             // add the back face to the geometry
00273 
00274             // store positions
00275             // No need to store texture coordinates - we reuse the
00276             // texture coordinates from the front side
00277             UInt32 backCoordOffset = posPtr->size();
00278             coordZ = -0.5f * depth;
00279             for (cIt = outline.coords.begin(); cIt != outline.coords.end(); ++cIt)
00280             {
00281                 Vec2f coord = *cIt + pos;
00282                 coord *= scale;
00283                 posPtr->push_back(Vec3f(coord.x(), coord.y(), coordZ));
00284             }
00285 
00286             // Store types, lengths and indices
00287             // We have to flip all triangles to enable correct backface culling.
00288             // For GL_TRIANGLES, we simply flip the vertices.
00289             // For GL_TRIANGLE_FANs, we leave the first vertex at its place and flip the
00290             // remaining vertices.
00291             // For GL_TRIANGLE_STRIPs, things are more complicated. When the number of
00292             // vertices is uneven, we simply flip the vertices. When the number of
00293             // vertices is even, we have to add an additional vertex before we flip the
00294             // vertices.
00295             vector<TextVectorGlyph::PolygonOutline::TypeIndex>::const_iterator tIt;
00296             UInt32 indexBegin = 0, indexEnd;
00297             for (tIt = outline.types.begin(); tIt != outline.types.end(); ++tIt)
00298             {
00299                 typesPtr->push_back(tIt->first);
00300                 indexEnd = tIt->second;
00301                 assert(indexEnd >= indexBegin);
00302                 UInt32 len = indexEnd - indexBegin;
00303                 UInt32 i = indexEnd;
00304                 if (tIt->first == GL_TRIANGLE_FAN)
00305                 {
00306                     i = indexBegin;
00307                     ++indexBegin;
00308                 }
00309                 if ((tIt->first == GL_TRIANGLE_STRIP) && ((len & 1) == 0))
00310                 {
00311                     assert((indexEnd >= 2) && (indexEnd - 2 >= indexBegin));
00312                     i = indexEnd - 2;
00313                     ++len;
00314                 }
00315                 if (i != indexEnd)
00316                 {
00317                     // the interleaved multi-index blocks have the layout
00318                     // Position | Normal | TexCoord
00319                     assert(i < outline.indices.size());
00320                     UInt32 index = outline.indices[i];
00321                     assert(backCoordOffset + index < posPtr->size());
00322                     indicesPtr->push_back(backCoordOffset + index);
00323                     indicesPtr->push_back(1);
00324                     assert(texCoordOffset + index < texPtr->size());
00325                     indicesPtr->push_back(texCoordOffset + index);
00326                     i = indexEnd;
00327                 }
00328                 lensPtr->push_back(len);
00329                 while (true)
00330                 {
00331                     if (i <= indexBegin)
00332                         break;
00333                     --i;
00334 
00335                     // the interleaved multi-index blocks have the layout
00336                     // Position | Normal | TexCoord
00337                     assert(i < outline.indices.size());
00338                     UInt32 index = outline.indices[i];
00339                     assert(backCoordOffset + index < posPtr->size());
00340                     indicesPtr->push_back(backCoordOffset + index);
00341                     indicesPtr->push_back(1);
00342                     assert(texCoordOffset + index < texPtr->size());
00343                     indicesPtr->push_back(texCoordOffset + index);
00344                 }
00345                 indexBegin = indexEnd;
00346             }
00347 
00348             // Add the side faces to the geometry
00349             const TextVectorGlyph::Normals &normals = glyph.getNormals(level);
00350 
00351             // construct the multi index
00352             UInt32 start = 0, end, index = 0;
00353             vector<UInt32>::const_iterator iIt;
00354             vector<TextVectorGlyph::Orientation>::const_iterator oriIt = glyph.getContourOrientations().begin();
00355             for (iIt = outline.contours.begin(); iIt != outline.contours.end(); ++iIt, ++oriIt)
00356             {
00357                 assert(oriIt != glyph.getContourOrientations().end());
00358                 UInt32 contourCoordOffset, contourBackCoordOffset;
00359                 if (*oriIt == TextVectorGlyph::CCW)
00360                 {
00361                     contourCoordOffset = coordOffset;
00362                     contourBackCoordOffset = backCoordOffset;
00363                 }
00364                 else
00365                 {
00366                     contourCoordOffset = backCoordOffset;
00367                     contourBackCoordOffset = coordOffset;
00368                 }
00369 
00370                 end = *iIt;
00371 
00372                 // the side faces are stored as quads
00373                 GLenum mode = GL_QUAD_STRIP;
00374                 UInt32 len = 0;
00375 
00376                 UInt32 coordIndex, backCoordIndex;
00377                 UInt32 normalOffset, startNormalOffset = normalsPtr->size();
00378                 for (index = start; index < end; ++index)
00379                 {
00380                     normalOffset = normalsPtr->size() - 1;
00381                     assert(index < normals.size());
00382                     if (normals[index].edgeAngle > creaseAngle)
00383                     {
00384                         // We have an edge with two normals, so we need to
00385                         // add the vertices twice, but with different normals
00386                         // - but only when this is not the start index
00387                         if (index > start)
00388                         {
00389                             if ((mode == GL_QUAD_STRIP) && (len > 2))
00390                             {
00391                                 typesPtr->push_back(GL_QUAD_STRIP);
00392                                 assert(((len + 2) & 1) == 0);
00393                                 lensPtr->push_back(len + 2);
00394                                 len = 0;
00395                                 coordIndex = contourCoordOffset + index;
00396                                 backCoordIndex = contourBackCoordOffset + index;
00397                             }
00398                             else
00399                             {
00400                                 mode = GL_QUADS;
00401                                 len += 2;
00402                                 coordIndex = contourBackCoordOffset + index;
00403                                 backCoordIndex = contourCoordOffset + index;
00404                             }
00405 
00406                             // back
00407                             assert(backCoordIndex < posPtr->size());
00408                             indicesPtr->push_back(backCoordIndex);
00409                             assert(normalOffset < normalsPtr->size());
00410                             indicesPtr->push_back(normalOffset);
00411                             assert(texCoordOffset + index < texPtr->size());
00412                             indicesPtr->push_back(texCoordOffset + index);
00413                             // front
00414                             assert(coordIndex < posPtr->size());
00415                             indicesPtr->push_back(coordIndex);
00416                             assert(normalOffset < normalsPtr->size());
00417                             indicesPtr->push_back(normalOffset);
00418                             assert(texCoordOffset + index < texPtr->size());
00419                             indicesPtr->push_back(texCoordOffset + index);
00420                         }
00421 
00422                         const Vec2f &normal = normals[index].nextEdgeNormal;
00423                         normalsPtr->push_back(Vec3f(normal.x(), normal.y(), 0.f));
00424                     }
00425                     else
00426                     {
00427                         if (mode == GL_QUADS)
00428                         {
00429                             typesPtr->push_back(GL_QUADS);
00430                             mode = GL_QUAD_STRIP;
00431                             assert(len >= 6);
00432                             assert(((len - 2) & 3) == 0);
00433                             lensPtr->push_back(len - 2);
00434                             len = 2;
00435                         }
00436 
00437                         const Vec2f &normal = normals[index].meanEdgeNormal;
00438                         normalsPtr->push_back(Vec3f(normal.x(), normal.y(), 0.f));
00439                     }
00440                     ++normalOffset;
00441 
00442                     // back
00443                     assert(contourBackCoordOffset + index < posPtr->size());
00444                     indicesPtr->push_back(contourBackCoordOffset + index);
00445                     assert(normalOffset < normalsPtr->size());
00446                     indicesPtr->push_back(normalOffset);
00447                     assert(texCoordOffset + index < texPtr->size());
00448                     indicesPtr->push_back(texCoordOffset + index);
00449                     // front
00450                     assert(contourCoordOffset + index < posPtr->size());
00451                     indicesPtr->push_back(contourCoordOffset + index);
00452                     assert(normalOffset < normalsPtr->size());
00453                     indicesPtr->push_back(normalOffset);
00454                     assert(texCoordOffset + index < texPtr->size());
00455                     indicesPtr->push_back(texCoordOffset + index);
00456 
00457                     len += 2;
00458                 }
00459 
00460                 // We have to close the strip, so add the start vertices again
00461                 if (normals[start].edgeAngle <= creaseAngle)
00462                     normalOffset = startNormalOffset;
00463                 if (mode == GL_QUAD_STRIP)
00464                 {
00465                     coordIndex = contourCoordOffset + start;
00466                     backCoordIndex = contourBackCoordOffset + start;
00467                 }
00468                 else
00469                 {
00470                     coordIndex = contourBackCoordOffset + start;
00471                     backCoordIndex = contourCoordOffset + start;
00472                 }
00473 
00474                 // back
00475                 assert(backCoordIndex < posPtr->size());
00476                 indicesPtr->push_back(backCoordIndex);
00477                 assert(normalOffset < normalsPtr->size());
00478                 indicesPtr->push_back(normalOffset);
00479                 assert(texCoordOffset + start < texPtr->size());
00480                 indicesPtr->push_back(texCoordOffset + start);
00481                 // front
00482                 assert(coordIndex < posPtr->size());
00483                 indicesPtr->push_back(coordIndex);
00484                 assert(normalOffset < normalsPtr->size());
00485                 indicesPtr->push_back(normalOffset);
00486                 assert(texCoordOffset + start < texPtr->size());
00487                 indicesPtr->push_back(texCoordOffset + start);
00488 
00489                 len += 2;
00490 
00491                 // store the number of multi index blocks
00492                 typesPtr->push_back(mode);
00493                 assert((mode != GL_QUADS) || ((len & 3) == 0));
00494                 assert((mode != GL_QUAD_STRIP) || ((len & 1) == 0));
00495                 lensPtr->push_back(len);
00496 
00497                 start = end;
00498             }
00499         }
00500     }
00501 
00502     endEditCP(typesPtr, GeoPTypesUI8::GeoPropDataFieldMask);
00503     endEditCP(indicesPtr, GeoIndicesUI32::GeoPropDataFieldMask);
00504     endEditCP(lensPtr, GeoPLengthsUI32::GeoPropDataFieldMask);
00505     endEditCP(texPtr, GeoTexCoords2f::GeoPropDataFieldMask);
00506     endEditCP(normalsPtr, GeoNormals3f::GeoPropDataFieldMask);
00507     endEditCP(posPtr, GeoPositions3f::GeoPropDataFieldMask);
00508 
00509     endEditCP(geoPtr);
00510 }

GeometryPtr osg::TextVectorFace::makeGeo ( const TextLayoutResult layoutResult,
Real32  scale = 1.f,
Real32  depth = 0.f,
UInt32  level = 2,
Real32  creaseAngle = Pi / 4.f 
)

Creates a new text geometry.

Parameters:
layoutResult The result of a layout operation.
scale The size of the glyphs.
depth The depth of the VectorGlyphs. If depth is 0.f no backside will be generated.
level The level of detail. Usually between 0 and 10.
creaseAngle The angle (in radians) which determines how faceted the glyphs should be lighted. If the angle enclosed by two vertex normals in a point exceeds the creaseAngle both of the two normals will be attached to the point. Otherwise their mean is used.
Returns:
A new text geometry.

Definition at line 517 of file OSGTextVectorFace.cpp.

References create(), and fillGeo().

Referenced by makeNode().

00519 {
00520     GeometryPtr geo = Geometry::create();
00521     fillGeo(geo, layoutResult, scale, depth, level, creaseAngle);
00522     return geo;
00523 }

NodePtr osg::TextVectorFace::makeNode ( const TextLayoutResult layoutResult,
Real32  scale = 1.f,
Real32  depth = 0.f,
UInt32  level = 2,
Real32  creaseAngle = Pi / 4.f 
)

Creates a new node with a text geometry.

Parameters:
layoutResult The result of a layout operation.
scale The size of the glyphs.
depth The depth of the VectorGlyphs. If depth is 0.f no backside will be generated.
level The level of detail. Usually between 0 and 10.
creaseAngle The angle (in radians) which determines how faceted the glyphs should be lighted. If the angle enclosed by two vertex normals in a point exceeds the creaseAngle both of the two normals will be attached to the point. Otherwise their mean is used.
Returns:
A new node containing a text geometry.

Definition at line 530 of file OSGTextVectorFace.cpp.

References osg::beginEditCP(), osg::Node::CoreFieldMask, create(), osg::endEditCP(), and makeGeo().

00532 {
00533     GeometryPtr geo = makeGeo(layoutResult, scale, depth, level, creaseAngle);
00534     NodePtr node = Node::create();
00535     beginEditCP(node, Node::CoreFieldMask);
00536     node->setCore(geo);
00537     endEditCP(node, Node::CoreFieldMask);
00538     return node;
00539 }

TextVectorFace * osg::TextVectorFace::create ( const std::string &  family,
Style  style = STYLE_PLAIN 
) [static]

Tries to create a vector face.

Parameters:
family The font family of the face (Arial, Courier etc.)
style The style of the face (bold, italic etc.)
Returns:
The vector face object or 0 in case of an error.

Definition at line 546 of file OSGTextVectorFace.cpp.

References osg::TextFaceFactory::createVectorFace(), and osg::TextFaceFactory::the().

Referenced by fillGeo(), makeGeo(), and makeNode().

00547 { return TextFaceFactory::the().createVectorFace(family, style); }

virtual std::auto_ptr<TextVectorGlyph> osg::TextVectorFace::createGlyph ( TextGlyph::Index  glyphIndex  )  [protected, pure virtual]

Creates a new Glyph object. This method has to be implemented by descendants of the VectorFace class.

Parameters:
glyphIndex The index of the glyph.
Returns:
The glyph object or 0 when no glyph exists for the given glyph index.

Referenced by getVectorGlyph().

const TextVectorFace& osg::TextVectorFace::operator= ( const TextVectorFace  )  [private]

Copy operator (not implemented!)

Reimplemented from osg::TextFace.

const std::string osg::TextFace::getFamily ( void   )  const [inline, inherited]

Returns the actual font family of the face.

Returns:
The font family.

Definition at line 43 of file OSGTextFace.inl.

References osg::TextFace::_family.

00043 { return _family; }

TextFace::Style osg::TextFace::getStyle (  )  const [inline, inherited]

Returns the actual style of the face.

Returns:
The style.

Definition at line 46 of file OSGTextFace.inl.

References osg::TextFace::_style.

00046 { return _style; }

Real32 osg::TextFace::getHoriAscent (  )  const [inline, inherited]

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 osg::TextFace::_horiAscent.

00049 { return _horiAscent; }

Real32 osg::TextFace::getVertAscent (  )  const [inline, inherited]

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 osg::TextFace::_vertAscent.

00052 { return _vertAscent; }

Real32 osg::TextFace::getHoriDescent (  )  const [inline, inherited]

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 osg::TextFace::_horiDescent.

00055 { return _horiDescent; }

Real32 osg::TextFace::getVertDescent (  )  const [inline, inherited]

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 osg::TextFace::_vertDescent.

00058 { return _vertDescent; }

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

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, inherited]

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, inherited]

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, inherited]

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 
) [inherited]

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 osg::TextFace::getGlyph(), osg::TextGlyph::getHeight(), osg::TextLayoutResult::getNumGlyphs(), osg::TextGlyph::getWidth(), osg::TextLayoutResult::indices, and osg::TextLayoutResult::positions.

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, inherited]

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, inherited]

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, inherited]

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 404 of file OSGTextFace.cpp.

References osg::TextFace::_horiAscent, osg::TextFace::_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, and osg::TextLayoutParam::topToBottom.

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

void MemoryObject::addRef ( void   )  [inherited]
void MemoryObject::subRef ( void   )  [inherited]

Definition at line 69 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

Referenced by osg::GroupMCastConnection::~GroupMCastConnection().

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

The scale factor used to scale font metrics

Definition at line 203 of file OSGTextVectorFace.h.

The map of glyphs

Definition at line 209 of file OSGTextVectorFace.h.

Referenced by getVectorGlyph(), and ~TextVectorFace().

An empty glyph

Definition at line 221 of file OSGTextVectorFace.h.

Referenced by getVectorGlyph().

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

The font family of the face

Definition at line 201 of file OSGTextFace.h.

Referenced by osg::TextFace::getFamily().

Style osg::TextFace::_style [protected, inherited]

The style of the face

Definition at line 204 of file OSGTextFace.h.

Referenced by osg::TextFace::getStyle().

Real32 osg::TextFace::_horiAscent [protected, inherited]

The ascent of the font for horizontal layout

Definition at line 207 of file OSGTextFace.h.

Referenced by osg::TextFace::adjustLineOrigin(), and osg::TextFace::getHoriAscent().

Real32 osg::TextFace::_vertAscent [protected, inherited]

The ascent of the font for vertical layout

Definition at line 210 of file OSGTextFace.h.

Referenced by osg::TextFace::getVertAscent().

Real32 osg::TextFace::_horiDescent [protected, inherited]

The descent of the font for horizontal layout

Definition at line 213 of file OSGTextFace.h.

Referenced by osg::TextFace::getHoriDescent().

Real32 osg::TextFace::_vertDescent [protected, inherited]

The descent of the font for vertical layout

Definition at line 216 of file OSGTextFace.h.

Referenced by osg::TextFace::adjustLineOrigin(), and osg::TextFace::getVertDescent().


The documentation for this class was generated from the following files:

Generated on 8 Feb 2010 for OpenSG by  doxygen 1.6.1