#include <OSGTextPixmapFace.h>

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, UInt32 border=1) |
| 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) |
Reference Counting | |
| void | addRef (void) |
| void | subRef (void) |
| Int32 | getRefCount (void) |
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.
typedef std::map<TextGlyph::Index, TextPixmapGlyph*> osg::TextPixmapFace::GlyphMap [protected] |
Defines a map of glyphs
Definition at line 173 of file OSGTextPixmapFace.h.
enum osg::TextFace::Style [inherited] |
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 };
| osg::TextPixmapFace::TextPixmapFace | ( | ) | [inline, protected] |
| osg::TextPixmapFace::~TextPixmapFace | ( | ) | [protected, virtual] |
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 }
| osg::TextPixmapFace::TextPixmapFace | ( | const TextPixmapFace & | ) | [private] |
Copy constructor (not implemented!)
| UInt32 osg::TextPixmapFace::getSize | ( | void | ) | const [inline] |
Returns the actual size of the face in pixels.
Definition at line 43 of file OSGTextPixmapFace.inl.
References _size.
00043 { return _size; }
| const TextGlyph & osg::TextPixmapFace::getGlyph | ( | TextGlyph::Index | glyphIndex | ) | [virtual] |
Returns information about a glyph.
| glyphIndex | The index of the glyph. Use the layout method to get the glyph indices corresponding to a character string. |
Implements osg::TextFace.
Definition at line 87 of file OSGTextPixmapFace.cpp.
References getPixmapGlyph().
00088 { 00089 return getPixmapGlyph(glyphIndex); 00090 }
| const TextPixmapGlyph & osg::TextPixmapFace::getPixmapGlyph | ( | TextGlyph::Index | glyphIndex | ) |
Returns information about a glyph.
| glyphIndex | The index of the glyph. Use the layout method to get the glyph indices corresponding to a character string. |
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 }
| ImagePtr osg::TextPixmapFace::makeImage | ( | const TextLayoutResult & | layoutResult, | |
| Vec2f & | offset, | |||
| UInt32 | border = 1 | |||
| ) |
Creates a texture image with the result of a layout operation. The format of the texture image is GL_INTENSITY.
| layoutResult | The result of a layout operation. | |
| offset | Gets filled with the offset of the upper left corner of the image from the coordinate origin. | |
| border | The number of clear pixels around the text |
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_A_PF, osg::osgceil(), osg::TextLayoutResult::positions, and osg::TextPixmapGlyph::putPixmap().
00130 { 00131 Vec2f lowerLeft, upperRight; 00132 calculateBoundingBox(layoutResult, lowerLeft, upperRight); 00133 offset.setValues(lowerLeft.x() - border, upperRight.y() + border); 00134 00135 ImagePtr imagePtr = Image::create(); 00136 beginEditCP(imagePtr); 00137 { 00138 UInt32 width = static_cast<UInt32>(osgceil(upperRight.x() - lowerLeft.x())) + (border << 1); 00139 UInt32 height = static_cast<UInt32>(osgceil(upperRight.y() - lowerLeft.y())) + (border << 1); 00140 imagePtr->set(Image::OSG_A_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) + border; 00151 Int32 y = static_cast<Int32>(pos.y() - lowerLeft.y() + 0.5f) + border; 00152 glyph.putPixmap(x, y, buffer, width, height); 00153 } 00154 } 00155 endEditCP(imagePtr); 00156 00157 return imagePtr; 00158 }
| TextPixmapFace * osg::TextPixmapFace::create | ( | const std::string & | family, | |
| Style | style = STYLE_PLAIN, |
|||
| UInt32 | size = 32 | |||
| ) | [static] |
Tries to create a pixmap face.
| family | The font family of the face (Arial, Courier etc.) | |
| style | The style of the face (bold, italic etc.) | |
| size | The size of the pixmap font in pixels. |
Definition at line 165 of file OSGTextPixmapFace.cpp.
References osg::TextFaceFactory::createPixmapFace(), and osg::TextFaceFactory::the().
00166 { return TextFaceFactory::the().createPixmapFace(family, style, size); }
| virtual std::auto_ptr<TextPixmapGlyph> osg::TextPixmapFace::createGlyph | ( | TextGlyph::Index | glyphIndex | ) | [protected, pure virtual] |
Creates a new Glyph object. This method has to be implemented by descendants of the TextPixmapFace class.
| glyphIndex | The index of the glyph. |
Referenced by getPixmapGlyph().
| const TextPixmapFace& osg::TextPixmapFace::operator= | ( | const TextPixmapFace & | ) | [private] |
Copy operator (not implemented!)
| const std::string osg::TextFace::getFamily | ( | void | ) | const [inline, inherited] |
Returns the actual font family of the face.
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.
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.
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!
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!
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.
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.
| 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.
| 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.
| 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.
| 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.
| 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 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.
| 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.
| 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.
| 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 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.
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 }
| 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] |
| Int32 MemoryObject::getRefCount | ( | void | ) | [inherited] |
Definition at line 77 of file OSGMemoryObject.cpp.
References osg::MemoryObject::_refCount.
00078 { 00079 return _refCount; 00080 }
UInt32 osg::TextPixmapFace::_size [protected] |
The size of the face in pixels
Definition at line 170 of file OSGTextPixmapFace.h.
Referenced by getSize().
GlyphMap osg::TextPixmapFace::_glyphMap [protected] |
The map of glyphs
Definition at line 176 of file OSGTextPixmapFace.h.
Referenced by getPixmapGlyph(), and ~TextPixmapFace().
TextPixmapGlyph osg::TextPixmapFace::_emptyGlyph [static, protected] |
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().
1.5.5