From eb1004715f9fa6a7700ea5165a1316f377e0b8f6 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 26 May 2009 00:20:51 +0200 Subject: Guard against an issue where forced wrapping would never succeed In some situations, like when wrapping the "]." part after an item link, the attempt at forced-wrapping the text never succeeded. The additional guard "end > start" protects against these cases. Also made some small optimizations. Removed redundant c_str() calls, noticed by Octalot, and changed " " to ' ' for finding a space. --- src/gui/widgets/browserbox.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index e4f0774b..b1ae5eb7 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -386,7 +386,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) // Auto wrap mode if (mMode == AUTO_WRAP && - (x + font->getWidth(part.c_str()) + 10) > getWidth()) + (x + font->getWidth(part) + 10) > getWidth()) { bool forced = false; char const *hyphen = "~"; @@ -399,14 +399,14 @@ void BrowserBox::draw(gcn::Graphics *graphics) do { if (!forced) - end = row.rfind(" ", end); + end = row.rfind(' ', end); // Check if we have to (stupidly) force-wrap if (end == std::string::npos || end <= start) { forced = true; end = row.size(); - x += hyphenWidth * 2; // Account for the wrap-notifier + x += hyphenWidth; // Account for the wrap-notifier continue; } @@ -416,7 +416,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) end--; // And then to the last byte of the previous one part = row.substr(start, end - start + 1); - } while ((x + font->getWidth(part.c_str()) + 10) > getWidth()); + } while (end > start && (x + font->getWidth(part) + 10) > getWidth()); if (forced) { @@ -432,7 +432,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) wrappedLines++; } font->drawString(graphics, part, x, y); - x += font->getWidth(part.c_str()); + x += font->getWidth(part); } y += font->getHeight(); setHeight((mTextRows.size() + wrappedLines) * font->getHeight()); -- cgit v1.2.3-70-g09d2