From d226e3ec68c5d7d39926ef966d4a3935369361c0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 27 Jan 2004 11:50:32 +0000 Subject: [PATCH] From Nick, added VectorUInt in osgText/String hack to get around VS's stoopid compiler bugs. From Robert, removed an #if #else #endif block, for code clarity. --- include/osgText/String | 21 ++++- src/osgText/String.cpp | 2 +- src/osgText/Text.cpp | 202 ----------------------------------------- 3 files changed, 21 insertions(+), 204 deletions(-) diff --git a/include/osgText/String b/include/osgText/String index c3cfb4310..2cee89a82 100644 --- a/include/osgText/String +++ b/include/osgText/String @@ -25,7 +25,26 @@ namespace osgText { class Text; -class OSGTEXT_EXPORT String : public osg::Referenced, public std::vector +#ifndef _MSC_VER + +typedef std::vector VectorUInt; + +#else // _MSC_VER + +class VectorUInt: public std::vector { + typedef std::vector inherited; +public: + VectorUInt(): inherited() {} + explicit VectorUInt(size_type n): inherited(n) {} + VectorUInt(const VectorUInt ©): inherited(copy) {} + //VectorUInt(value_type *beg_, value_type *end_): inherited(beg_, end_) {} + template + VectorUInt(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {} +}; + +#endif + +class OSGTEXT_EXPORT String : public osg::Referenced, public VectorUInt { public: diff --git a/src/osgText/String.cpp b/src/osgText/String.cpp index bab1c03a3..5eb32d755 100644 --- a/src/osgText/String.cpp +++ b/src/osgText/String.cpp @@ -237,7 +237,7 @@ unsigned int getNextCharacter(look_ahead_iterator& charString,String::Encoding e String::String(const String& str): osg::Referenced(), - std::vector(str) + VectorUInt(str) { } diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 58c5e9278..d1dcf504d 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -346,7 +346,6 @@ String::iterator Text::computeLastCharacterOnLine(osg::Vec2 cursor, String::iter } -#if 1 void Text::computeGlyphRepresentation() { Font* activefont = getActiveFont(); @@ -559,207 +558,6 @@ void Text::computeGlyphRepresentation() computePositions(); } -#else - - void Text::computeGlyphRepresentation() - { - Font* activefont = getActiveFont(); - if (!activefont) return; - - _textureGlyphQuadMap.clear(); - - if (_text.empty()) - { - _textBB.set(0,0,0,0,0,0);//no size text - computePositions(); //to reset the origin - return; - } - - osg::Vec2 startOfLine(0.0f,0.0f); - osg::Vec2 cursor(startOfLine); - osg::Vec2 local(0.0f,0.0f); - - unsigned int previous_charcode = 0; - bool horizontal = _layout!=VERTICAL; - bool kerning = true; - - activefont->setSize(_fontWidth,_fontHeight); - - float hr = _characterHeight/(float)activefont->getHeight(); - float wr = hr/_characterAspectRatio; - - for(String::iterator itr=_text.begin(); - itr!=_text.end(); - ++itr) - { - unsigned int charcode = *itr; - - if (charcode=='\n') - { - if (horizontal) startOfLine.y() -= _characterHeight; - else startOfLine.x() += _characterHeight; - cursor = startOfLine; - previous_charcode = 0; - continue; - } - - - Font::Glyph* glyph = activefont->getGlyph(charcode); - if (glyph) - { - - float width = (float)(glyph->s()-2*activefont->getGlyphImageMargin()) * wr; - float height = (float)(glyph->t()-2*activefont->getGlyphImageMargin()) * hr; - #ifdef TREES_CODE_FOR_MAKING_SPACES_EDITABLE - if (width == 0.0f) width = glyph->getHorizontalAdvance() * wr; - if (height == 0.0f) height = glyph->getVerticalAdvance() * hr; - #endif - if (_layout==RIGHT_TO_LEFT) - { - cursor.x() -= glyph->getHorizontalAdvance() * wr; - } - - // adjust cursor position w.r.t any kerning. - if (kerning && previous_charcode) - { - switch(_layout) - { - case LEFT_TO_RIGHT: - { - osg::Vec2 delta(activefont->getKerning(previous_charcode,charcode,_kerningType)); - cursor.x() += delta.x() * wr; - cursor.y() += delta.y() * hr; - break; - } - case RIGHT_TO_LEFT: - { - osg::Vec2 delta(activefont->getKerning(charcode,previous_charcode,_kerningType)); - cursor.x() -= delta.x() * wr; - cursor.y() -= delta.y() * hr; - break; - } - case VERTICAL: - break; // no kerning when vertical. - } - } - - local = cursor; - - - osg::Vec2 bearing(horizontal?glyph->getHorizontalBearing():glyph->getVerticalBearing()); - local.x() += bearing.x() * wr; - local.y() += bearing.y() * hr; - - // check to see if we are still within line if not move to next line. - switch(_layout) - { - case LEFT_TO_RIGHT: - { - if (_maximumWidth>0.0f) - { - if (local.x()+width>_maximumWidth) - { - startOfLine.y() -= _characterHeight; - cursor = startOfLine; - previous_charcode = 0; - - local = cursor; - local.x() += bearing.x() * wr; - local.y() += bearing.y() * hr; - } - } - break; - } - case RIGHT_TO_LEFT: - { - if (_maximumWidth>0.0f) - { - if (local.x()<-_maximumWidth) - { - startOfLine.y() -= _characterHeight; - cursor = startOfLine; - previous_charcode = 0; - - local = cursor; - local.x() += bearing.x() * wr; - local.y() += bearing.y() * hr; - } - ; } - break; - } - case VERTICAL: - if (_maximumHeight>0.0f) - { - if (local.y()<-_maximumHeight) - { - startOfLine.x() += _characterHeight/_characterAspectRatio; - cursor = startOfLine; - previous_charcode = 0; - - local = cursor; - local.x() += bearing.x() * wr; - local.y() += bearing.y() * hr; - } - } - break; - } - - GlyphQuads& glyphquad = _textureGlyphQuadMap[glyph->getTexture()->getStateSet()]; - - glyphquad._glyphs.push_back(glyph); - - // set up the coords of the quad - glyphquad._coords.push_back(local+osg::Vec2(0.0f,height)); - glyphquad._coords.push_back(local+osg::Vec2(0.0f,0.0f)); - glyphquad._coords.push_back(local+osg::Vec2(width,0.0f)); - glyphquad._coords.push_back(local+osg::Vec2(width,height)); - - // set up the tex coords of the quad - const osg::Vec2& mintc = glyph->getMinTexCoord(); - const osg::Vec2& maxtc = glyph->getMaxTexCoord(); - - glyphquad._texcoords.push_back(osg::Vec2(mintc.x(),maxtc.y())); - glyphquad._texcoords.push_back(osg::Vec2(mintc.x(),mintc.y())); - glyphquad._texcoords.push_back(osg::Vec2(maxtc.x(),mintc.y())); - glyphquad._texcoords.push_back(osg::Vec2(maxtc.x(),maxtc.y())); - - // move the cursor onto the next character. - switch(_layout) - { - case LEFT_TO_RIGHT: cursor.x() += glyph->getHorizontalAdvance() * wr; break; - case VERTICAL: cursor.y() -= glyph->getVerticalAdvance() *hr; break; - case RIGHT_TO_LEFT: break; // nop. - } - } - - previous_charcode = charcode; - } - - _textBB.init(); - - for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin(); - titr!=_textureGlyphQuadMap.end(); - ++titr) - { - const GlyphQuads& glyphquad = titr->second; - - for(GlyphQuads::Coords2::const_iterator citr = glyphquad._coords.begin(); - citr != glyphquad._coords.end(); - ++citr) - { - _textBB.expandBy(osg::Vec3(citr->x(),citr->y(),0.0f)); - } - } - - if (!_textureGlyphQuadMap.empty()) - { - setStateSet(const_cast((*_textureGlyphQuadMap.begin()).first.get())); - } - - computePositions(); - } - -#endif void Text::computePositions() { for(unsigned int i=0;i<_autoTransformCache.size();++i)