#include <OSGTextTXFFace.h>

Public Types | |
| enum | Style { STYLE_PLAIN, STYLE_BOLD, STYLE_ITALIC, STYLE_BOLDITALIC } |
Public Member Functions | |
| Real32 | getScale () const |
| const TextTXFParam & | getParam () const |
| ImagePtr | getTexture () const |
| virtual const TextGlyph & | getGlyph (TextGlyph::Index glyphIndex) |
| const TextTXFGlyph & | getTXFGlyph (TextGlyph::Index glyphIndex) |
| virtual void | layout (const std::string &utf8Text, const TextLayoutParam ¶m, TextLayoutResult &result) |
| virtual void | layout (const std::wstring &text, const TextLayoutParam ¶m, TextLayoutResult &result) |
| 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 | fillGeo (GeometryPtr &geoPtr, const TextLayoutResult &layoutResult, Real32 scale=1.f, Vec2f offset=Vec2f(0, 0), Color3f color=Color3f(-1,-1,-1)) |
| void | addToGeom (GeometryPtr &geoPtr, const TextLayoutResult &layoutResult, Real32 scale=1.f, Vec2f offset=Vec2f(0, 0), Color3f color=Color3f(-1,-1,-1)) |
| GeometryPtr | makeGeo (const TextLayoutResult &layoutResult, Real32 scale=1.f, Vec2f offset=Vec2f(0, 0), Color3f color=Color3f(-1,-1,-1)) |
| NodePtr | makeNode (const TextLayoutResult &layoutResult, Real32 scale=1.f, Vec2f offset=Vec2f(0, 0), Color3f color=Color3f(-1,-1,-1)) |
| bool | writeToStream (std::ostream &os) const |
| bool | writeToFile (const std::string &filename) const |
| const std::string | getFamily () const |
| Style | getStyle () const |
| Real32 | getHoriAscent () const |
| Real32 | getVertAscent () const |
| Real32 | getHoriDescent () const |
| Real32 | getVertDescent () const |
| 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 TextTXFFace * | create (const std::string &family, Style style=STYLE_PLAIN, const TextTXFParam ¶m=TextTXFParam()) |
| static TextTXFFace * | createFromStream (std::istream &is, const std::string &family=std::string(), Style style=STYLE_PLAIN) |
| static TextTXFFace * | createFromFile (const std::string &filename) |
| static void | convertUTF8ToUnicode (const std::string &utf8Text, std::wstring &text) |
Protected Types | |
| typedef std::map < TextGlyph::Index, TextTXFGlyph * > | GlyphMap |
Protected Member Functions | |
| TextTXFFace () | |
| virtual | ~TextTXFFace () |
| void | prepareTexture (const TextTXFParam ¶m) |
| 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 | |
| Real32 | _scale |
| TextTXFParam | _param |
| ImagePtr | _texture |
| GlyphMap | _glyphMap |
| std::string | _family |
| Style | _style |
| Real32 | _horiAscent |
| Real32 | _vertAscent |
| Real32 | _horiDescent |
| Real32 | _vertDescent |
Private Member Functions | |
| TextTXFFace (const TextTXFFace &) | |
| const TextTXFFace & | operator= (const TextTXFFace &) |
Static Private Attributes | |
| static TextTXFGlyph | _emptyGlyph |
// Includes #include "OSGTextTXFFace.h" #include "OSGTextLayoutParam.h" #include "OSGTextLayoutResult.h" // Try to create a new %TextTXFFace object. The create // method returns 0 in case of an error TextTXFFace *face = TextTXFFace::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 GeometryPtr geo = face->makeGeo(layoutResult, scale); // Get the texture. You have to map this texture onto the // geometry we created above. ImagePtr img = face->getTexture(); // We do not need the TXF face anymore, so decrement // the reference counter. Do not use the face object anymore! subRefP(face);
Definition at line 120 of file OSGTextTXFFace.h.
typedef std::map<TextGlyph::Index, TextTXFGlyph*> osg::TextTXFFace::GlyphMap [protected] |
Defines a map of glyphs
Definition at line 308 of file OSGTextTXFFace.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::TextTXFFace::TextTXFFace | ( | ) | [inline, protected] |
| osg::TextTXFFace::~TextTXFFace | ( | ) | [protected, virtual] |
Destroys the TextTXFFace object.
Definition at line 74 of file OSGTextTXFFace.cpp.
References _glyphMap, _texture, and osg::subRefCP().
00075 { 00076 // Delete all glyphs in the glyph cache 00077 GlyphMap::iterator it; 00078 for (it = _glyphMap.begin(); it != _glyphMap.end(); ++it) 00079 { 00080 assert(it->second != 0); 00081 delete it->second; 00082 } 00083 00084 // Delete the texture 00085 subRefCP(_texture); 00086 }
| osg::TextTXFFace::TextTXFFace | ( | const TextTXFFace & | ) | [private] |
Copy constructor (not implemented!)
| Real32 osg::TextTXFFace::getScale | ( | void | ) | const [inline] |
Returns the scaling factor.
Definition at line 43 of file OSGTextTXFFace.inl.
References _scale.
Referenced by osg::SimpleStatisticsForeground::draw().
00043 { return _scale; }
| const TextTXFParam & osg::TextTXFFace::getParam | ( | ) | const [inline] |
Returns the parameters of the face.
Definition at line 46 of file OSGTextTXFFace.inl.
References _param.
Referenced by osg::SimpleStatisticsForeground::draw().
00046 { return _param; }
| ImagePtr osg::TextTXFFace::getTexture | ( | ) | const [inline] |
Returns the texture that contains all glyphs.
Definition at line 49 of file OSGTextTXFFace.inl.
References _texture.
Referenced by osg::SimpleStatisticsForeground::initText().
00049 { return _texture; }
| const TextGlyph & osg::TextTXFFace::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 93 of file OSGTextTXFFace.cpp.
References getTXFGlyph().
00094 { 00095 return getTXFGlyph(glyphIndex); 00096 }
| const TextTXFGlyph & osg::TextTXFFace::getTXFGlyph | ( | 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 103 of file OSGTextTXFFace.cpp.
References _emptyGlyph, _glyphMap, and osg::TextGlyph::INVALID_INDEX.
Referenced by addToGeom(), osg::SimpleStatisticsForeground::drawCharacters(), osg::GraphicStatisticsForeground::drawString(), and getGlyph().
00104 { 00105 // Try to find the glyph in the map of glyphs 00106 GlyphMap::const_iterator it = _glyphMap.find(glyphIndex); 00107 if (it != _glyphMap.end()) 00108 { 00109 assert(it->second != 0); 00110 return *(it->second); 00111 } 00112 00113 // We did not find the glyph in the map of glyphs, 00114 // so try to convert uppercase letters to lowercase 00115 // letters and vice versa 00116 if (glyphIndex > 255) 00117 glyphIndex = TextGlyph::INVALID_INDEX; 00118 else if (isupper(glyphIndex)) 00119 glyphIndex = tolower(glyphIndex); 00120 else if (islower(glyphIndex)) 00121 glyphIndex = toupper(glyphIndex); 00122 else 00123 glyphIndex = TextGlyph::INVALID_INDEX; 00124 it = _glyphMap.find(glyphIndex); 00125 if (it != _glyphMap.end()) 00126 { 00127 assert(it->second != 0); 00128 return *(it->second); 00129 } 00130 00131 return _emptyGlyph; 00132 }
| virtual void osg::TextTXFFace::layout | ( | const std::string & | utf8Text, | |
| const TextLayoutParam & | param, | |||
| TextLayoutResult & | result | |||
| ) | [virtual] |
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 from osg::TextFace.
Referenced by osg::SimpleStatisticsForeground::draw(), and osg::GraphicStatisticsForeground::drawString().
| virtual void osg::TextTXFFace::layout | ( | const std::wstring & | text, | |
| const TextLayoutParam & | param, | |||
| TextLayoutResult & | result | |||
| ) | [virtual] |
Lays out one line of text.
| text | The text. | |
| param | Contains parameters that affect the layout process. | |
| result | Gets filled with the layout results. |
Implements osg::TextFace.
| virtual void osg::TextTXFFace::layout | ( | const std::vector< std::string > & | lines, | |
| const TextLayoutParam & | param, | |||
| TextLayoutResult & | result | |||
| ) | [virtual] |
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 from osg::TextFace.
| virtual void osg::TextTXFFace::layout | ( | const std::vector< std::wstring > & | lines, | |
| const TextLayoutParam & | param, | |||
| TextLayoutResult & | result | |||
| ) | [virtual] |
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 from osg::TextFace.
| void osg::TextTXFFace::fillGeo | ( | GeometryPtr & | geoPtr, | |
| const TextLayoutResult & | layoutResult, | |||
| Real32 | scale = 1.f, |
|||
| Vec2f | offset = Vec2f(0,0), |
|||
| Color3f | color = Color3f(-1,-1,-1) | |||
| ) |
Fills a geometry with a new text.
| geoPtr | The geometry that gets filled with the new text. | |
| layoutResult | The result of a layout operation. | |
| scale | The size of the glyphs. | |
| offset | Amount to offset the positions in the layout. | |
| color | The color to use for the text. If not specified, then we will not add color container. |
Definition at line 139 of file OSGTextTXFFace.cpp.
References addToGeom(), osg::FCPtr< BasePtrTypeT, FieldContainerTypeT >::dcast(), and osg::NullFC.
Referenced by makeGeo().
00141 { 00142 // cast the field containers down to the needed type and create them 00143 // when they have the wrong type 00144 GeoPositions3fPtr posPtr = GeoPositions3fPtr::dcast(geoPtr->getPositions()); 00145 if (posPtr != NullFC) 00146 posPtr->clear(); 00147 00148 // Clear out any existing data and then add to the geom 00149 GeoNormals3fPtr normalPtr = GeoNormals3fPtr::dcast(geoPtr->getNormals()); 00150 if (normalPtr != NullFC) 00151 normalPtr->clear(); 00152 00153 GeoTexCoords2fPtr texPtr = GeoTexCoords2fPtr::dcast(geoPtr->getTexCoords()); 00154 if (texPtr != NullFC) 00155 texPtr->clear(); 00156 00157 GeoColors3fPtr colorPtr = GeoColors3fPtr::dcast(geoPtr->getColors()); 00158 if (NullFC != colorPtr) 00159 colorPtr->clear(); 00160 00161 GeoPLengthsUI32Ptr lensPtr = GeoPLengthsUI32Ptr::dcast(geoPtr->getLengths()); 00162 if (lensPtr != NullFC) 00163 lensPtr->clear(); 00164 00165 GeoPTypesUI8Ptr typesPtr = GeoPTypesUI8Ptr::dcast(geoPtr->getTypes()); 00166 if (typesPtr != NullFC) 00167 typesPtr->clear(); 00168 00169 geoPtr->setIndices(NullFC); 00170 geoPtr->setSecondaryColors(NullFC); 00171 geoPtr->setTexCoords1(NullFC); 00172 geoPtr->setTexCoords2(NullFC); 00173 geoPtr->setTexCoords3(NullFC); 00174 geoPtr->getIndexMapping().clear(); 00175 00176 addToGeom(geoPtr,layoutResult,scale,offset,color); 00177 }
| void osg::TextTXFFace::addToGeom | ( | GeometryPtr & | geoPtr, | |
| const TextLayoutResult & | layoutResult, | |||
| Real32 | scale = 1.f, |
|||
| Vec2f | offset = Vec2f(0,0), |
|||
| Color3f | color = Color3f(-1,-1,-1) | |||
| ) |
Adds geometry for new text to an existing text geometry.
| geoPtr | The geometry that gets filled with the new text. | |
| layoutResult | The result of a layout operation. | |
| scale | The size of the glyphs. | |
| offset | Amount to offset the positions in the layout. | |
| color | The color to use for the text. |
Definition at line 179 of file OSGTextTXFFace.cpp.
References osg::beginEditCP(), osg::TextTXFGlyph::COORD_BOTTOM, osg::TextTXFGlyph::COORD_LEFT, osg::TextTXFGlyph::COORD_RIGHT, osg::TextTXFGlyph::COORD_TOP, osg::GeoProperty< GeoPropertyDesc >::create(), osg::FCPtr< BasePtrTypeT, FieldContainerTypeT >::dcast(), osg::endEditCP(), osg::GeoProperty< GeoPropertyDesc >::GeoPropDataFieldMask, osg::TextTXFGlyph::getHeight(), osg::TextLayoutResult::getNumGlyphs(), osg::TextTXFGlyph::getTexCoord(), getTXFGlyph(), osg::TextTXFGlyph::getWidth(), osg::TextLayoutResult::indices, osg::NullFC, and osg::TextLayoutResult::positions.
Referenced by fillGeo().
00181 { 00182 beginEditCP(geoPtr); 00183 00184 // cast the field containers down to the needed type and create them 00185 // when they have the wrong type 00186 GeoPositions3fPtr posPtr = GeoPositions3fPtr::dcast(geoPtr->getPositions()); 00187 GeoNormals3fPtr normalPtr = GeoNormals3fPtr::dcast(geoPtr->getNormals()); 00188 GeoTexCoords2fPtr texPtr = GeoTexCoords2fPtr::dcast(geoPtr->getTexCoords()); 00189 GeoColors3fPtr colorPtr = GeoColors3fPtr::dcast(geoPtr->getColors()); 00190 GeoPLengthsUI32Ptr lensPtr = GeoPLengthsUI32Ptr::dcast(geoPtr->getLengths()); 00191 GeoPTypesUI8Ptr typesPtr = GeoPTypesUI8Ptr::dcast(geoPtr->getTypes()); 00192 00193 // Create color buffer: If Null container AND color is set && we have not potentially added text before 00194 if ((NullFC == colorPtr) && (color != OSG::Color3f(-1,-1,-1)) && 00195 ((NullFC == posPtr) && (NullFC == texPtr)) ) 00196 { 00197 colorPtr = GeoColors3f::create(); 00198 geoPtr->setColors(colorPtr); 00199 } 00200 bool use_colors(NullFC != colorPtr); 00201 00202 if (posPtr == NullFC) 00203 { 00204 posPtr = GeoPositions3f::create(); 00205 geoPtr->setPositions(posPtr); 00206 } 00207 00208 if (normalPtr == NullFC) 00209 { 00210 normalPtr = GeoNormals3f::create(); 00211 geoPtr->setNormals(normalPtr); 00212 } 00213 00214 if (texPtr == NullFC) 00215 { 00216 texPtr = GeoTexCoords2f::create(); 00217 geoPtr->setTexCoords(texPtr); 00218 } 00219 00220 if (lensPtr == NullFC) 00221 { 00222 lensPtr = GeoPLengthsUI32::create(); 00223 geoPtr->setLengths(lensPtr); 00224 } 00225 00226 if (typesPtr == NullFC) 00227 { 00228 typesPtr = GeoPTypesUI8::create(); 00229 geoPtr->setTypes(typesPtr); 00230 } 00231 00232 UInt32 numGlyphs = layoutResult.getNumGlyphs(); 00233 if (numGlyphs == 0) 00234 { 00235 endEditCP(geoPtr); 00236 return; 00237 } 00238 00239 beginEditCP(posPtr, GeoPositions3f::GeoPropDataFieldMask); 00240 beginEditCP(normalPtr, GeoNormals3f::GeoPropDataFieldMask); 00241 beginEditCP(texPtr, GeoTexCoords2f::GeoPropDataFieldMask); 00242 if(NullFC != colorPtr) 00243 { beginEditCP(colorPtr, GeoIndicesUI32::GeoPropDataFieldMask); } 00244 beginEditCP(lensPtr, GeoPLengthsUI32::GeoPropDataFieldMask); 00245 beginEditCP(typesPtr, GeoPTypesUI8::GeoPropDataFieldMask); 00246 00247 OSG::Vec3f normal(0.f, 0.f, 1.f); // normal to use for each glyph 00248 00249 typesPtr->push_back(GL_QUADS); 00250 unsigned num_glyphs_added(0); 00251 00252 for (UInt32 i = 0; i < numGlyphs; ++i) 00253 { 00254 TextGlyph::Index glyphIndex = layoutResult.indices[i]; 00255 const TextTXFGlyph &glyph = getTXFGlyph(glyphIndex); 00256 Real32 width = glyph.getWidth(); 00257 Real32 height = glyph.getHeight(); 00258 // No need to draw invisible glyphs 00259 if ((width <= 0.f) || (height <= 0.f)) 00260 continue; 00261 else 00262 num_glyphs_added += 1; 00263 00264 // Calculate coordinates 00265 Vec2f pos = layoutResult.positions[i]; 00266 Real32 posLeft = (pos.x() * scale) + offset.x(); 00267 Real32 posTop = (pos.y() * scale) + offset.y(); 00268 Real32 posRight = ((pos.x() + width) * scale) + offset.x(); 00269 Real32 posBottom = ((pos.y() - height) * scale) + offset.y(); 00270 00271 // Calculate texture coordinates 00272 Real32 texCoordLeft = glyph.getTexCoord(TextTXFGlyph::COORD_LEFT); 00273 Real32 texCoordTop = glyph.getTexCoord(TextTXFGlyph::COORD_TOP); 00274 Real32 texCoordRight = glyph.getTexCoord(TextTXFGlyph::COORD_RIGHT); 00275 Real32 texCoordBottom = glyph.getTexCoord(TextTXFGlyph::COORD_BOTTOM); 00276 00277 // lower left corner 00278 posPtr->push_back(Vec3f(posLeft, posBottom, 0.f)); 00279 texPtr->push_back(Vec2f(texCoordLeft, texCoordBottom)); 00280 normalPtr->push_back(normal); 00281 if(use_colors) colorPtr->push_back(color); 00282 00283 // lower right corner 00284 posPtr->push_back(Vec3f(posRight, posBottom, 0.f)); 00285 texPtr->push_back(Vec2f(texCoordRight, texCoordBottom)); 00286 normalPtr->push_back(normal); 00287 if(use_colors) colorPtr->push_back(color); 00288 00289 // upper right corner 00290 posPtr->push_back(Vec3f(posRight, posTop, 0.f)); 00291 texPtr->push_back(Vec2f(texCoordRight, texCoordTop)); 00292 normalPtr->push_back(normal); 00293 if(use_colors) colorPtr->push_back(color); 00294 00295 // upper left corner 00296 posPtr->push_back(Vec3f(posLeft, posTop, 0.f)); 00297 texPtr->push_back(Vec2f(texCoordLeft, texCoordTop)); 00298 normalPtr->push_back(normal); 00299 if(use_colors) colorPtr->push_back(color); 00300 } 00301 lensPtr->push_back(num_glyphs_added*4); 00302 00303 endEditCP(typesPtr, GeoPTypesUI8::GeoPropDataFieldMask); 00304 endEditCP(lensPtr, GeoPLengthsUI32::GeoPropDataFieldMask); 00305 endEditCP(texPtr, GeoTexCoords2f::GeoPropDataFieldMask); 00306 endEditCP(normalPtr, GeoNormals3f::GeoPropDataFieldMask); 00307 endEditCP(posPtr, GeoPositions3f::GeoPropDataFieldMask); 00308 if(NullFC != colorPtr) 00309 { endEditCP(colorPtr, GeoIndicesUI32::GeoPropDataFieldMask); } 00310 00311 endEditCP(geoPtr); 00312 }
| GeometryPtr osg::TextTXFFace::makeGeo | ( | const TextLayoutResult & | layoutResult, | |
| Real32 | scale = 1.f, |
|||
| Vec2f | offset = Vec2f(0,0), |
|||
| Color3f | color = Color3f(-1,-1,-1) | |||
| ) |
Creates a new text geometry.
| layoutResult | The result of a layout operation. | |
| scale | The size of the glyphs. | |
| offset | Amount to offset the positions in the layout. | |
| color | The color to use for the text. |
Definition at line 319 of file OSGTextTXFFace.cpp.
References osg::GeometryBase::create(), and fillGeo().
Referenced by makeNode().
00321 { 00322 GeometryPtr geo = Geometry::create(); 00323 fillGeo(geo, layoutResult, scale, offset, color); 00324 return geo; 00325 }
| NodePtr osg::TextTXFFace::makeNode | ( | const TextLayoutResult & | layoutResult, | |
| Real32 | scale = 1.f, |
|||
| Vec2f | offset = Vec2f(0,0), |
|||
| Color3f | color = Color3f(-1,-1,-1) | |||
| ) |
Creates a new node with a text geometry.
| layoutResult | The result of a layout operation. | |
| scale | The size of the glyphs. | |
| offset | Amount to offset the positions in the layout. | |
| color | The color to use for the text. |
Definition at line 332 of file OSGTextTXFFace.cpp.
References osg::beginEditCP(), osg::Node::CoreFieldMask, osg::Node::create(), osg::endEditCP(), and makeGeo().
00334 { 00335 GeometryPtr geo = makeGeo(layoutResult, scale, offset, color); 00336 NodePtr node = Node::create(); 00337 beginEditCP(node, Node::CoreFieldMask); 00338 node->setCore(geo); 00339 endEditCP(node, Node::CoreFieldMask); 00340 return node; 00341 }
| static TextTXFFace* osg::TextTXFFace::create | ( | const std::string & | family, | |
| Style | style = STYLE_PLAIN, |
|||
| const TextTXFParam & | param = TextTXFParam() | |||
| ) | [static] |
Tries to create a TXF face.
| family | The font family of the face (Arial, Courier etc.) | |
| style | The style of the face (bold, italic etc.) | |
| param | Parameters that affect the creation of the TXF face. |
Referenced by osg::SimpleStatisticsForeground::initText().
| static TextTXFFace* osg::TextTXFFace::createFromStream | ( | std::istream & | is, | |
| const std::string & | family = std::string(), |
|||
| Style | style = STYLE_PLAIN | |||
| ) | [static] |
| static TextTXFFace* osg::TextTXFFace::createFromFile | ( | const std::string & | filename | ) | [static] |
| bool osg::TextTXFFace::writeToStream | ( | std::ostream & | os | ) | const |
Writes a TXF face to an output stream.
| is | The output stream. |
| bool osg::TextTXFFace::writeToFile | ( | const std::string & | filename | ) | const |
Writes a TXF face to a TXF file.
| filename | The name of the TXF file. |
| void osg::TextTXFFace::prepareTexture | ( | const TextTXFParam & | param | ) | [protected] |
Calculates the positions of the glyphs on the texture
Definition at line 792 of file OSGTextTXFFace.cpp.
References _glyphMap, _texture, osg::addRefCP(), osg::beginEditCP(), osg::ImageBase::create(), osg::endEditCP(), osg::TextTXFParam::gap, osg::TextTXFGlyph::getPixmapHeight(), osg::TextTXFGlyph::getPixmapWidth(), osg::Image::OSG_A_PF, osg::osgnextpower2(), and osg::TextTXFParam::textureWidth.
00793 { 00794 // Sort characters by height and calculate the area necessary 00795 // to keep all characters 00796 typedef multimap<UInt32, TextTXFGlyph*, greater<UInt32> > HeightMap; 00797 HeightMap heightMap; 00798 UInt32 area = 0, maxWidth = 0; 00799 GlyphMap::iterator gmIt; 00800 for (gmIt = _glyphMap.begin(); gmIt != _glyphMap.end(); ++gmIt) 00801 { 00802 TextTXFGlyph *glyph = gmIt->second; 00803 heightMap.insert(HeightMap::value_type(glyph->getPixmapHeight(), glyph)); 00804 if (maxWidth < glyph->getPixmapWidth()) 00805 maxWidth = glyph->getPixmapWidth(); 00806 area += (glyph->getPixmapWidth() + param.gap) * (glyph->getPixmapHeight() + param.gap); 00807 } 00808 00809 UInt32 textureSize; 00810 if (param.textureWidth == 0) 00811 { 00812 // Try to make a good guess about the optimal width of the texture 00813 textureSize = static_cast<UInt32>(ceil(sqrt(static_cast<Real32>(area)))); 00814 } 00815 else 00816 textureSize = param.textureWidth; 00817 maxWidth += param.gap << 1; 00818 if (textureSize < maxWidth) 00819 textureSize = maxWidth; 00820 UInt32 textureWidth = osgnextpower2(textureSize); 00821 00822 // Calculate the positions of the glyphs in the texture 00823 HeightMap::iterator hmIt = heightMap.begin(); 00824 UInt32 xpos = param.gap, ypos = param.gap, heightOfRow = 0; 00825 while (hmIt != heightMap.end()) 00826 { 00827 HeightMap::iterator hmIt3; 00828 // Does the next glyph fit into the line? 00829 if (xpos + hmIt->second->getPixmapWidth() + param.gap > textureWidth) 00830 { 00831 // No, so lets try to find another glyph 00832 HeightMap::iterator hmIt2 = hmIt; 00833 for (++hmIt2; hmIt2 != heightMap.end(); ++hmIt2) 00834 { 00835 if (xpos + hmIt2->second->getPixmapWidth() + param.gap <= textureWidth) 00836 break; 00837 } 00838 if (hmIt2 == heightMap.end()) 00839 { 00840 // There is no other glyph 00841 xpos = param.gap; 00842 ypos += heightOfRow + param.gap; 00843 heightOfRow = 0; 00844 hmIt3 = hmIt; 00845 ++hmIt; 00846 } 00847 else // There is another glyph that fits 00848 hmIt3 = hmIt2; 00849 } 00850 else 00851 { 00852 // Yes, the glyph fits into the line 00853 hmIt3 = hmIt; 00854 ++hmIt; 00855 } 00856 hmIt3->second->_x = xpos; 00857 hmIt3->second->_y = ypos; 00858 xpos += hmIt3->second->getPixmapWidth() + param.gap; 00859 if (hmIt3->second->getPixmapHeight() > heightOfRow) 00860 heightOfRow = hmIt3->second->getPixmapHeight(); 00861 heightMap.erase(hmIt3); 00862 } 00863 ypos += heightOfRow; 00864 00865 // Calculate the height of the texture 00866 UInt32 textureHeight = osgnextpower2(static_cast<UInt32>(ypos)); 00867 00868 // Create the texture 00869 _texture = Image::create(); 00870 addRefCP(_texture); 00871 beginEditCP(_texture); 00872 { 00873 _texture->set(Image::OSG_A_PF, textureWidth, textureHeight); 00874 _texture->clear(); 00875 } 00876 endEditCP(_texture); 00877 00878 // Calculate the coordinates of all glyphs 00879 for (gmIt = _glyphMap.begin(); gmIt != _glyphMap.end(); ++gmIt) 00880 gmIt->second->calculateCoordinates(textureWidth, textureHeight); 00881 }
| const TextTXFFace& osg::TextTXFFace::operator= | ( | const TextTXFFace & | ) | [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; }
| 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 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.
| 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 }
Real32 osg::TextTXFFace::_scale [protected] |
The scale factor used to scale font metrics
Definition at line 299 of file OSGTextTXFFace.h.
Referenced by getScale().
TextTXFParam osg::TextTXFFace::_param [protected] |
The parameters of the face
Definition at line 302 of file OSGTextTXFFace.h.
Referenced by getParam().
ImagePtr osg::TextTXFFace::_texture [protected] |
The texture that contains all glyphs
Definition at line 305 of file OSGTextTXFFace.h.
Referenced by getTexture(), prepareTexture(), and ~TextTXFFace().
GlyphMap osg::TextTXFFace::_glyphMap [protected] |
The map of glyphs
Definition at line 311 of file OSGTextTXFFace.h.
Referenced by getTXFGlyph(), prepareTexture(), and ~TextTXFFace().
TextTXFGlyph osg::TextTXFFace::_emptyGlyph [static, private] |
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