From 371d84683f8eeecfc40ac65da8d13bd380982223 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 Mar 2003 15:36:52 +0000 Subject: [PATCH] Fixes to osgText for default parameter. --- include/osgText/Text | 21 +++++++++++++++ src/osgText/Text.cpp | 61 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 11 deletions(-) diff --git a/include/osgText/Text b/include/osgText/Text index 6b462e3e9..864b04e82 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -67,6 +67,27 @@ public: * which is converted to an internal TextString.*/ void setText(const std::string& text); + /** + * Types of string encodings supported + */ + enum Encoding + { + ENCODING_UNDEFINED, /// not using Unicode + ENCODING_ASCII = ENCODING_UNDEFINED,/// unsigned char ASCII + ENCODING_UTF8, /// 8-bit unicode transformation format + ENCODING_UTF16, /// 16-bit signature + ENCODING_UTF16_BE, /// 16-bit big-endian + ENCODING_UTF16_LE, /// 16-bit little-endian + ENCODING_UTF32, /// 32-bit signature + ENCODING_UTF32_BE, /// 32-bit big-endian + ENCODING_UTF32_LE, /// 32-bit little-endian + ENCODING_SIGNATURE, /// detect encoding from signature + }; + + /** Set the text using a Unicode encoded std::string, which is converted to an internal TextString. + * The encoding parameter specificies which Unicode encodeding is used in the std::string. */ + void setText(const std::string& text,Encoding encoding); + /** Set the text using a wchar_t string, * which is converted to an internal TextString.*/ void setText(const wchar_t* text); diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index cfc544e4c..841890f73 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -13,6 +13,7 @@ #include +#include #include #include "DefaultFont.h" @@ -75,7 +76,7 @@ void Text::setFontSize(unsigned int width, unsigned int height) } -void Text::setCharacterSize(float height,float ascpectRatio=1.0f) +void Text::setCharacterSize(float height,float ascpectRatio) { _characterHeight = height; _characterAspectRatio = ascpectRatio; @@ -96,6 +97,28 @@ void Text::setText(const std::string& text) computeGlyphRepresentation(); } +void Text::setText(const std::string& text,Encoding encoding) +{ + _text.clear(); + + if (text.empty()) return; + + + std::cerr << "Text::setText(const std::string& text,Encoding encoding) not implemented yet."<second; - - for(GlyphQuads::Coords::const_iterator citr = glyphquad._coords.begin(); - citr != glyphquad._coords.end(); - ++citr) + if (_axisAlignment==SCREEN) { - _bbox.expandBy(osg::Vec3(citr->x(),citr->y(),0.0f)*_matrix); + // build a sphere around the text box, centerd at the offset point. + float maxlength2 = (_textBB.corner(0)-_offset).length2(); + + float length2 = (_textBB.corner(1)-_offset).length2(); + maxlength2 = osg::maximum(maxlength2,length2); + + length2 = (_textBB.corner(2)-_offset).length2(); + maxlength2 = osg::maximum(maxlength2,length2); + + length2 = (_textBB.corner(3)-_offset).length2(); + maxlength2 = osg::maximum(maxlength2,length2); + + float radius = sqrtf(maxlength2); + osg::Vec3 center(_position); + + _bbox.set(center.x()-radius,center.y()-radius,center.z()-radius, + center.x()+radius,center.y()+radius,center.z()+radius); + } + else + { + _bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*_matrix); + _bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*_matrix); + _bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*_matrix); + _bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*_matrix); } }