Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable non-ascii chars for MovableText #1374

Merged
merged 2 commits into from
Jul 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/rviz/ogre_helpers/movable_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <OgreHardwareBufferManager.h>
#include <OgreFontManager.h>
#include <OgreFont.h>
#include <OgreUTFString.h>

#include <sstream>

Expand Down Expand Up @@ -115,6 +116,8 @@ void MovableText::setFontName(const String &fontName)
throw Exception(Exception::ERR_ITEM_NOT_FOUND, "Could not find font "
+ fontName, "MovableText::setFontName");

// to support non-ascii letters, setup the codepoint range before loading
mpFont->addCodePointRange(std::make_pair<Ogre::Font::CodePoint>(0, 999));
mpFont->load();
if (!mpMaterial.isNull())
{
Expand Down Expand Up @@ -218,17 +221,17 @@ void MovableText::showOnTop(bool show)

void MovableText::_setupGeometry()
{
Ogre::UTFString::utf32string utfCaption(Ogre::UTFString(mCaption).asUTF32());

assert(mpFont);
assert(!mpMaterial.isNull());

unsigned int vertexCount = 0;

//count letters to determine how many vertices are needed
std::string::iterator i = mCaption.begin();
std::string::iterator iend = mCaption.end();
for ( ; i != iend; ++i )
for (auto ch : utfCaption)
{
if ((*i != ' ') && (*i != '\n'))
if ((ch != ' ') && (ch != '\n'))
{
vertexCount += 6;
}
Expand All @@ -241,7 +244,7 @@ void MovableText::_setupGeometry()
mUpdateColors = true;
}

if (mCaption.empty())
if (utfCaption.empty())
{
return;
}
Expand Down Expand Up @@ -298,11 +301,9 @@ void MovableText::_setupGeometry()
float total_height = mCharHeight;
float total_width = 0.0f;
float current_width = 0.0f;
i = mCaption.begin();
iend = mCaption.end();
for ( ; i != iend; ++i )
for (auto ch : utfCaption)
{
if (*i == '\n')
if (ch == '\n')
{
total_height += mCharHeight + mLineSpacing;

Expand All @@ -312,13 +313,13 @@ void MovableText::_setupGeometry()
}
current_width = 0.0;
}
else if (*i == ' ')
else if (ch == ' ')
{
current_width += spaceWidth;
}
else
{
current_width += mpFont->getGlyphAspectRatio(*i) * mCharHeight * 2.0;
current_width += mpFont->getGlyphAspectRatio(ch) * mCharHeight * 2.0;
}
}

Expand Down Expand Up @@ -360,12 +361,13 @@ void MovableText::_setupGeometry()
Ogre::Vector3 min(9999999.0f), max(-9999999.0f), currPos(0.0f);
Ogre::Real maxSquaredRadius = -99999999.0f;
float largestWidth = 0.0f;
for (i = mCaption.begin(); i != iend; ++i)
auto iend = utfCaption.end();
for (auto i = utfCaption.begin(); i != iend; ++i)
{
if (newLine)
{
len = 0.0f;
for (String::iterator j = i; j != iend && *j != '\n'; j++)
for (auto j = i; j != iend && *j != '\n'; j++)
{
if (*j == ' ')
len += spaceWidth;
Expand Down