mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-09 02:38:46 +00:00
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).
This commit is contained in:
parent
882dda5e2f
commit
220603b50f
@ -41,6 +41,7 @@ Version 1.9.9+svn:
|
||||
* 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,
|
||||
|
@ -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 gray_inactive(const std::string &str)
|
||||
|
||||
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();
|
||||
|
18
src/text.cpp
18
src/text.cpp
@ -24,6 +24,8 @@
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "tstring.hpp"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
@ -66,6 +68,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)
|
||||
context_(pango_font_map_create_context(pango_cairo_font_map_get_default())),
|
||||
|
13
src/text.hpp
13
src/text.hpp
@ -33,6 +33,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.
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user