#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 |
Represents a TXF face. A TXF face is a texture containing a set of glyphs. It allows to take geometries consisting of small rectangles onto which one glyph of the texture is mapped, respectively. You can load TXF faces from TXF files, or you can create TXF faces from the faces installed on the system. The following piece of code demonstrates how to create and use TextTXFFace objects.
// 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().
| 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->editMFIndexMapping()->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, 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 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, 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 addToGeom(), makeGeo(), makeNode(), and prepareTexture().
| 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 793 of file OSGTextTXFFace.cpp.
References _glyphMap, _texture, osg::addRefCP(), osg::beginEditCP(), create(), osg::endEditCP(), osg::TextTXFParam::gap, osg::TextTXFGlyph::getPixmapHeight(), osg::TextTXFGlyph::getPixmapWidth(), osg::Image::OSG_A_PF, osg::osgnextpower2(), and osg::TextTXFParam::textureWidth.
00794 { 00795 // Sort characters by height and calculate the area necessary 00796 // to keep all characters 00797 typedef multimap<UInt32, TextTXFGlyph*, greater<UInt32> > HeightMap; 00798 HeightMap heightMap; 00799 UInt32 area = 0, maxWidth = 0; 00800 GlyphMap::iterator gmIt; 00801 for (gmIt = _glyphMap.begin(); gmIt != _glyphMap.end(); ++gmIt) 00802 { 00803 TextTXFGlyph *glyph = gmIt->second; 00804 heightMap.insert(HeightMap::value_type(glyph->getPixmapHeight(), glyph)); 00805 if (maxWidth < glyph->getPixmapWidth()) 00806 maxWidth = glyph->getPixmapWidth(); 00807 area += (glyph->getPixmapWidth() + param.gap) * (glyph->getPixmapHeight() + param.gap); 00808 } 00809 00810 UInt32 textureSize; 00811 if (param.textureWidth == 0) 00812 { 00813 // Try to make a good guess about the optimal width of the texture 00814 textureSize = static_cast<UInt32>(ceil(sqrt(static_cast<Real32>(area)))); 00815 } 00816 else 00817 textureSize = param.textureWidth; 00818 maxWidth += param.gap << 1; 00819 if (textureSize < maxWidth) 00820 textureSize = maxWidth; 00821 UInt32 textureWidth = osgnextpower2(textureSize); 00822 00823 // Calculate the positions of the glyphs in the texture 00824 HeightMap::iterator hmIt = heightMap.begin(); 00825 UInt32 xpos = param.gap, ypos = param.gap, heightOfRow = 0; 00826 while (hmIt != heightMap.end()) 00827 { 00828 HeightMap::iterator hmIt3; 00829 // Does the next glyph fit into the line? 00830 if (xpos + hmIt->second->getPixmapWidth() + param.gap > textureWidth) 00831 { 00832 // No, so lets try to find another glyph 00833 HeightMap::iterator hmIt2 = hmIt; 00834 for (++hmIt2; hmIt2 != heightMap.end(); ++hmIt2) 00835 { 00836 if (xpos + hmIt2->second->getPixmapWidth() + param.gap <= textureWidth) 00837 break; 00838 } 00839 if (hmIt2 == heightMap.end()) 00840 { 00841 // There is no other glyph 00842 xpos = param.gap; 00843 ypos += heightOfRow + param.gap; 00844 heightOfRow = 0; 00845 hmIt3 = hmIt; 00846 ++hmIt; 00847 } 00848 else // There is another glyph that fits 00849 hmIt3 = hmIt2; 00850 } 00851 else 00852 { 00853 // Yes, the glyph fits into the line 00854 hmIt3 = hmIt; 00855 ++hmIt; 00856 } 00857 hmIt3->second->_x = xpos; 00858 hmIt3->second->_y = ypos; 00859 xpos += hmIt3->second->getPixmapWidth() + param.gap; 00860 if (hmIt3->second->getPixmapHeight() > heightOfRow) 00861 heightOfRow = hmIt3->second->getPixmapHeight(); 00862 heightMap.erase(hmIt3); 00863 } 00864 ypos += heightOfRow; 00865 00866 // Calculate the height of the texture 00867 UInt32 textureHeight = osgnextpower2(static_cast<UInt32>(ypos)); 00868 00869 // Create the texture 00870 _texture = Image::create(); 00871 addRefCP(_texture); 00872 beginEditCP(_texture); 00873 { 00874 _texture->set(Image::OSG_A_PF, textureWidth, textureHeight); 00875 _texture->clear(); 00876 } 00877 endEditCP(_texture); 00878 00879 // Calculate the coordinates of all glyphs 00880 for (gmIt = _glyphMap.begin(); gmIt != _glyphMap.end(); ++gmIt) 00881 gmIt->second->calculateCoordinates(textureWidth, textureHeight); 00882 }
| const TextTXFFace& osg::TextTXFFace::operator= | ( | const TextTXFFace & | ) | [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.
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 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] |
Definition at line 64 of file OSGMemoryObject.cpp.
References osg::MemoryObject::_refCount.
Referenced by osg::SharedObjectHandler::getSharedObject(), and osg::SharedObjectHandler::initialize().
00065 { 00066 _refCount++; 00067 }
| void MemoryObject::subRef | ( | void | ) | [inherited] |
Definition at line 69 of file OSGMemoryObject.cpp.
References osg::MemoryObject::_refCount.
Referenced by osg::GroupMCastConnection::~GroupMCastConnection().
| 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.6.1