Author: mordante
Date: Sun Oct 23 19:49:04 2011
New Revision: 51593
URL: http://svn.gna.org/viewcvs/wesnoth?rev=51593&view=rev
Log:
Disable pango formatting of unit names.
Since the markup is used it does so by escaping the markup characters in
the unit name. (Fixes bug #17788).
Modified:
trunk/changelog
trunk/src/reports.cpp
trunk/src/text.cpp
trunk/src/text.hpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=51593&r1=51592&r2=51593&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun Oct 23 19:49:04 2011
@@ -41,6 +41,7 @@
* Added option in advanced preferences that allows the twelve-hour clock
format to be used
* Reenabled "delay shroud updates"
+ * Chanaged: Disable pango markup in unit names (bug #17788)
* WML engine:
* Readded the liminal alignment
* Added four-difficulty versions of certain macros: QUANTITY4,
Modified: trunk/src/reports.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/reports.cpp?rev=51593&r1=51592&r2=51593&view=diff
==============================================================================
--- trunk/src/reports.cpp (original)
+++ trunk/src/reports.cpp Sun Oct 23 19:49:04 2011
@@ -29,6 +29,7 @@
#include "reports.hpp"
#include "resources.hpp"
#include "team.hpp"
+#include "text.hpp"
#include "tod_manager.hpp"
#include "unit.hpp"
#include "whiteboard/manager.hpp"
@@ -138,12 +139,21 @@
static config unit_name(unit *u)
{
- if (!u) return report();
+ if (!u) {
+ return report();
+ }
+
+ /*
+ * The name needs to be escaped, it might be set by the user and using
+ * markup. Also names often contain a forbidden single quote.
+ */
+ const std::string& name = font::escape_text(u->name());
std::ostringstream str, tooltip;
- str << "<b>" << u->name() << "</b>";
- tooltip << _("Name: ") << "<b>" << u->name() << "</b>";
+ str << "<b>" << name << "</b>";
+ tooltip << _("Name: ") << "<b>" << name << "</b>";
return text_report(str.str(), tooltip.str());
}
+
REPORT_GENERATOR(unit_name)
{
unit *u = get_visible_unit();
Modified: trunk/src/text.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/text.cpp?rev=51593&r1=51592&r2=51593&view=diff
==============================================================================
--- trunk/src/text.cpp (original)
+++ trunk/src/text.cpp Sun Oct 23 19:49:04 2011
@@ -23,6 +23,8 @@
#include "font.hpp"
#include "serialization/string_utils.hpp"
#include "tstring.hpp"
+
+#include <boost/foreach.hpp>
#include <cassert>
#include <cstring>
@@ -65,6 +67,22 @@
const unsigned ttext::STYLE_BOLD = TTF_STYLE_BOLD;
const unsigned ttext::STYLE_ITALIC = TTF_STYLE_ITALIC;
const unsigned ttext::STYLE_UNDERLINE = TTF_STYLE_UNDERLINE;
+
+std::string escape_text(const std::string& text)
+{
+ std::string result;
+ BOOST_FOREACH(const char c, text) {
+ switch(c) {
+ case '&': result += "&"; break;
+ case '<': result += "<"; break;
+ case '>': result += ">"; break;
+ case '\'': result += "'"; break;
+ case '"': result += """; break;
+ default: result += c;
+ }
+ }
+ return result;
+}
ttext::ttext() :
#if PANGO_VERSION_CHECK(1,22,0)
Modified: trunk/src/text.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/text.hpp?rev=51593&r1=51592&r2=51593&view=diff
==============================================================================
--- trunk/src/text.hpp (original)
+++ trunk/src/text.hpp Sun Oct 23 19:49:04 2011
@@ -32,6 +32,19 @@
} // namespace gui2;
namespace font {
+
+/**
+ * Escapses the markup characters in a text.
+ *
+ * The markups escaped are the ones used in the pango markup. The special
+ * characters are @code <>'"&@endcode. They escaping is the same as for HTML.
+ *
+ * @param text The text to escape.
+ *
+ * @returns The escaped text.
+ */
+std::string escape_text(const std::string& text);
+
// add background color and also font markup.
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits