#include <OSGTextPixmapFace.h>
Inheritance diagram for osg::TextPixmapFace:

Public Types | |
| enum | Style { STYLE_PLAIN, STYLE_BOLD, STYLE_ITALIC, STYLE_BOLDITALIC } |
Public Member Functions | |
| UInt32 | getSize () const |
| virtual const TextGlyph & | getGlyph (TextGlyph::Index glyphIndex) |
| const TextPixmapGlyph & | getPixmapGlyph (TextGlyph::Index glyphIndex) |
| ImagePtr | makeImage (const TextLayoutResult &layoutResult, Vec2f &offset) |
| 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 ¶m, TextLayoutResult &result) |
| virtual void | layout (const std::wstring &text, const TextLayoutParam ¶m, TextLayoutResult &result)=0 |
| virtual void | layout (const std::vector< std::string > &lines, const TextLayoutParam ¶m, TextLayoutResult &result) |
| virtual void | layout (const std::vector< std::wstring > &lines, const TextLayoutParam ¶m, TextLayoutResult &result) |
| void | calculateBoundingBox (const TextLayoutResult &layoutResult, Vec2f &lowerLeft, Vec2f &upperRight) |
Static Public Member Functions | |
| static TextPixmapFace * | create (const std::string &family, Style style=STYLE_PLAIN, UInt32 size=32) |
| static void | convertUTF8ToUnicode (const std::string &utf8Text, std::wstring &text) |
Protected Types | |
| typedef std::map< TextGlyph::Index, TextPixmapGlyph * > | GlyphMap |
Protected Member Functions | |
| TextPixmapFace () | |
| virtual | ~TextPixmapFace () |
| virtual std::auto_ptr< TextPixmapGlyph > | createGlyph (TextGlyph::Index glyphIndex)=0 |
| void | justifyLine (const TextLayoutParam ¶m, const std::vector< UInt32 > &spaceIndices, Vec2f &currPos, TextLayoutResult &layoutResult) const |
| void | adjustLineOrigin (const TextLayoutParam ¶m, const Vec2f &currPos, TextLayoutResult &layoutResult) const |
Protected Attributes | |
| UInt32 | _size |
| GlyphMap | _glyphMap |
| std::string | _family |
| Style | _style |
| Real32 | _horiAscent |
| Real32 | _vertAscent |
| Real32 | _horiDescent |
| Real32 | _vertDescent |
Static Protected Attributes | |
| static TextPixmapGlyph | _emptyGlyph |
Private Member Functions | |
| TextPixmapFace (const TextPixmapFace &) | |
| const TextPixmapFace & | operator= (const TextPixmapFace &) |
// Includes #include "OSGTextPixmapFace.h" #include "OSGTextLayoutParam.h" #include "OSGTextLayoutResult.h" // Try to create a new %TextPixmapFace object. The create // method returns 0 in case of an error TextPixmapFace *face = TextPixmapFace::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 texture using the layout information returned // from the previous call to the layout method. Real32 offset; // This is the offset from the coordinate origin to the // upper left corner of the texture (in pixels). ImagePtr img = face->makeImage(layoutResult, offset); // We do not need the pixmap face anymore, so decrement // the reference counter. Do not use the face object anymore! subRefP(face);
Definition at line 111 of file OSGTextPixmapFace.h.
|
|
Defines a map of glyphs Definition at line 172 of file OSGTextPixmapFace.h. |
|
|
Defines the styles of a face Definition at line 75 of file OSGTextFace.h. 00076 { 00077 STYLE_PLAIN, 00078 STYLE_BOLD, 00079 STYLE_ITALIC, 00080 STYLE_BOLDITALIC 00081 };
|
|
|
Creates a new TextPixmapFace object. Definition at line 46 of file OSGTextPixmapFace.inl.
|
|
|
Destroys the TextPixmapFace object. Definition at line 71 of file OSGTextPixmapFace.cpp. References _glyphMap. 00072 { 00073 // Delete all glyphs in the glyph cache 00074 GlyphMap::iterator it; 00075 for (it = _glyphMap.begin(); it != _glyphMap.end(); ++it) 00076 { 00077 assert(it->second != 0); 00078 delete it->second; 00079 } 00080 }
|
|
|
Copy constructor (not implemented!) |
|
|
Returns the actual size of the face in pixels.
Definition at line 43 of file OSGTextPixmapFace.inl. References _size. 00043 { return _size; }
|
|
|
Returns information about a glyph.
Implements osg::TextFace. Definition at line 87 of file OSGTextPixmapFace.cpp. References getPixmapGlyph(). 00088 { 00089 return getPixmapGlyph(glyphIndex); 00090 }
|
|
|
Returns information about a glyph.
Definition at line 97 of file OSGTextPixmapFace.cpp. References _emptyGlyph, _glyphMap, createGlyph(), and osg::TextGlyph::INVALID_INDEX. Referenced by getGlyph(), and makeImage(). 00098 { 00099 if (glyphIndex == TextGlyph::INVALID_INDEX) 00100 return _emptyGlyph; 00101 00102 // Try to find the glyph in the map of glyphs 00103 GlyphMap::const_iterator it = _glyphMap.find(glyphIndex); 00104 if (it != _glyphMap.end()) 00105 { 00106 assert(it->second != 0); 00107 return *(it->second); 00108 } 00109 00110 // We did not find the glyph, so we have to create it 00111 auto_ptr<TextPixmapGlyph> glyph = createGlyph(glyphIndex); 00112 00113 // We could not create the glyph, return the empty glyph 00114 if (glyph.get() == 0) 00115 return _emptyGlyph; 00116 00117 // Put the glyph into the glyph cache 00118 _glyphMap.insert(GlyphMap::value_type(glyphIndex, glyph.get())); 00119 00120 // Return the glyph 00121 return *(glyph.release()); 00122 }
|
|
||||||||||||
|
Creates a texture image with the result of a layout operation. The format of the texture image is GL_INTENSITY.
Definition at line 129 of file OSGTextPixmapFace.cpp. References osg::beginEditCP(), osg::TextFace::calculateBoundingBox(), osg::ImageBase::create(), osg::endEditCP(), osg::TextLayoutResult::getNumGlyphs(), getPixmapGlyph(), osg::TextLayoutResult::indices, osg::Image::OSG_I_PF, osg::osgceil(), osg::TextLayoutResult::positions, osg::TextPixmapGlyph::putPixmap(), osg::VecStorage2< ValueTypeT >::setValues(), osg::VecStorage2< ValueTypeT >::x(), and osg::VecStorage2< ValueTypeT >::y(). 00130 { 00131 Vec2f lowerLeft, upperRight; 00132 calculateBoundingBox(layoutResult, lowerLeft, upperRight); 00133 offset.setValues(lowerLeft.x(), upperRight.y()); 00134 00135 ImagePtr imagePtr = Image::create(); 00136 beginEditCP(imagePtr); 00137 { 00138 UInt32 width = static_cast<UInt32>(osgceil(upperRight.x() - lowerLeft.x())); 00139 UInt32 height = static_cast<UInt32>(osgceil(upperRight.y() - lowerLeft.y())); 00140 imagePtr->set(Image::OSG_I_PF, width, height); 00141 imagePtr->clear(); 00142 UInt8 *buffer = imagePtr->getData(); 00143 00144 // Put the glyphs into the texture 00145 UInt32 i, numGlyphs = layoutResult.getNumGlyphs(); 00146 for (i = 0; i < numGlyphs; ++i) 00147 { 00148 const TextPixmapGlyph &glyph = getPixmapGlyph(layoutResult.indices[i]); 00149 const Vec2f &pos = layoutResult.positions[i]; 00150 Int32 x = static_cast<Int32>(pos.x() - lowerLeft.x() + 0.5f); 00151 Int32 y = static_cast<Int32>(pos.y() - lowerLeft.y() + 0.5f); 00152 glyph.putPixmap(x, y, buffer, width, height); 00153 } 00154 } 00155 endEditCP(imagePtr); 00156 00157 return imagePtr; 00158 }
|
|
||||||||||||||||
|
Tries to create a pixmap face.
Definition at line 165 of file OSGTextPixmapFace.cpp. References osg::TextFaceFactory::createPixmapFace(), and osg::TextFaceFactory::the(). 00166 { return TextFaceFactory::the().createPixmapFace(family, style, size); }
|
|
|
Creates a new Glyph object. This method has to be implemented by descendants of the TextPixmapFace class.
Referenced by getPixmapGlyph(). |
|
|
Copy operator (not implemented!) |
|
|
Returns the actual font family of the face.
Definition at line 43 of file OSGTextFace.inl. References osg::TextFace::_family. 00043 { return _family; }
|
|
|
Returns the actual style of the face.
Definition at line 46 of file OSGTextFace.inl. References osg::TextFace::_style. 00046 { return _style; }
|
|
|
Returns the ascent of the face for horizontal layout. The ascent is the distance from the baseline to the top of the face.
Definition at line 49 of file OSGTextFace.inl. References osg::TextFace::_horiAscent. 00049 { return _horiAscent; }
|
|
|
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!
Definition at line 52 of file OSGTextFace.inl. References osg::TextFace::_vertAscent. 00052 { return _vertAscent; }
|
|
|
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!
Definition at line 55 of file OSGTextFace.inl. References osg::TextFace::_horiDescent. 00055 { return _horiDescent; }
|
|
|
Returns the descent of the face for vertical layout. The descent is the distance from the baseline to the right side of the face.
Definition at line 58 of file OSGTextFace.inl. References osg::TextFace::_vertDescent. 00058 { return _vertDescent; }
|
|
||||||||||||||||
|
Lays out one line of text.
Reimplemented in osg::TextTXFFace. |
|
||||||||||||||||
|
Lays out one line of text.
Implemented in osg::TextTXFFace. |
|
||||||||||||||||
|
Lays out multiple lines of text.
Reimplemented in osg::TextTXFFace. |
|
||||||||||||||||
|
Lays out multiple lines of text.
Reimplemented in osg::TextTXFFace. |
|
||||||||||||||||
|
Calculates the bounding box of a text after layout.
Definition at line 243 of file OSGTextFace.cpp. References osg::TextFace::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 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 }
|
|
||||||||||||
|
Converts a UTF8 encoded string to a unicode string.
Referenced by osg::TextTXFParam::setCharacters(). |
|
||||||||||||||||||||
|
Justifies one line of text.
|
|
||||||||||||||||
|
Adjusts the positions of glyphs, depending on the alignment.
Definition at line 402 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, 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 }
|
|
|
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 }
|
|
|
Definition at line 69 of file OSGMemoryObject.cpp. References osg::MemoryObject::_refCount.
|
|
|
Definition at line 77 of file OSGMemoryObject.cpp. References osg::MemoryObject::_refCount. 00078 { 00079 return _refCount; 00080 }
|
|
|
The size of the face in pixels Definition at line 169 of file OSGTextPixmapFace.h. Referenced by getSize(). |
|
|
The map of glyphs Definition at line 175 of file OSGTextPixmapFace.h. Referenced by getPixmapGlyph(), and ~TextPixmapFace(). |
|
|
An empty glyph Definition at line 64 of file OSGTextPixmapFace.cpp. Referenced by getPixmapGlyph(). |
|
|
The font family of the face Definition at line 201 of file OSGTextFace.h. Referenced by osg::TextFace::getFamily(). |
|
|
The style of the face Definition at line 204 of file OSGTextFace.h. Referenced by osg::TextFace::getStyle(). |
|
|
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(). |
|
|
The ascent of the font for vertical layout Definition at line 210 of file OSGTextFace.h. Referenced by osg::TextFace::getVertAscent(). |
|
|
The descent of the font for horizontal layout Definition at line 213 of file OSGTextFace.h. Referenced by osg::TextFace::getHoriDescent(). |
|
|
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(). |
1.4.3