← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1525680 into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1525680 into lp:widelands.

Commit message:
Richtext and rt_render can now handle  . Shifted handling of < and > from parser to renderer.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1525680 in widelands: "Implement support for  "
  https://bugs.launchpad.net/widelands/+bug/1525680

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1525680/+merge/283793

We can now handle   in addition to < and > in texts. Some translations need this (see attached bug).

For testing, see that the <parent> directory is still displayed correctly. You can also hack Lua files to add the tags.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1525680 into lp:widelands.
=== modified file 'src/graphic/richtext.cc'
--- src/graphic/richtext.cc	2015-11-28 11:04:12 +0000
+++ src/graphic/richtext.cc	2016-01-25 12:32:56 +0000
@@ -19,6 +19,8 @@
 
 #include "graphic/richtext.h"
 
+#include <boost/algorithm/string/replace.hpp>
+
 #include "base/rect.h"
 #include "graphic/font.h"
 #include "graphic/font_handler.h"
@@ -34,6 +36,14 @@
 
 namespace {
 int32_t const h_space = 3;
+
+// TODO(GunChleoc): This function is mirrored in rt_render. Keep them identical.
+void replace_entities(std::string* text) {
+	boost::replace_all(*text, "&gt;", ">");
+	boost::replace_all(*text, "&lt;", "<");
+	boost::replace_all(*text, "&nbsp;", " ");
+}
+
 } // namespace
 
 /**
@@ -85,7 +95,8 @@
 			std::string previous_word;
 			for (std::vector<std::string>::iterator source_it = words.begin();
 				  source_it != words.end(); ++source_it) {
-				const std::string& word = *source_it;
+				std::string& word = *source_it;
+				replace_entities(&word);
 				if (source_it != words.end()) {
 					if (i18n::has_rtl_character(word.c_str()) || i18n::has_rtl_character(previous_word.c_str())) {
 						it = result_words.insert(result_words.begin(), word);
@@ -99,7 +110,8 @@
 				}
 			}
 		} else {
-			for (const std::string& word: words) {
+			for (std::string& word: words) {
+				replace_entities(&word);
 				result_words.push_back(word);
 			}
 		}

=== modified file 'src/graphic/text/rt_parse.cc'
--- src/graphic/text/rt_parse.cc	2015-10-04 09:19:55 +0000
+++ src/graphic/text/rt_parse.cc	2016-01-25 12:32:56 +0000
@@ -25,7 +25,6 @@
 #include <vector>
 
 #include <SDL.h>
-#include <boost/algorithm/string.hpp>
 #include <boost/format.hpp>
 
 #include "graphic/text/rt_errors_impl.h"
@@ -142,8 +141,6 @@
 			if (!tc.text_allowed) {
 				throw SyntaxErrorImpl(line, col, "no text, as only tags are allowed here", text, ts.peek(100));
 			}
-			boost::replace_all(text, "&gt;", ">");
-			boost::replace_all(text, "&lt;", "<");
 			m_childs.push_back(new Child(text));
 		}
 

=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc	2016-01-18 19:35:25 +0000
+++ src/graphic/text/rt_render.cc	2016-01-25 12:32:56 +0000
@@ -27,6 +27,7 @@
 
 #include <SDL.h>
 #include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
 #include <boost/format.hpp>
 
 #include "base/log.h"
@@ -47,6 +48,17 @@
 
 using namespace std;
 
+namespace {
+
+// TODO(GunChleoc): This function is mirrored in richtext. Keep them identical.
+void replace_entities(std::string* text) {
+	boost::replace_all(*text, "&gt;", ">");
+	boost::replace_all(*text, "&lt;", "<");
+	boost::replace_all(*text, "&nbsp;", " ");
+}
+
+} // namespace
+
 namespace RT {
 
 static const uint16_t INFINITE_WIDTH = 65535; // 2^16-1
@@ -726,6 +738,7 @@
 
 			word = ts.till_any_or_end(" \t\n\r");
 			if (!word.empty()) {
+				replace_entities(&word);
 				bool word_is_bidi = i18n::has_rtl_character(word.c_str());
 				word = i18n::make_ligatures(word.c_str());
 				if (word_is_bidi || i18n::has_rtl_character(previous_word.c_str())) {
@@ -766,6 +779,7 @@
 			}
 			word = ts.till_any_or_end(" \t\n\r");
 			if (!word.empty()) {
+				replace_entities(&word);
 				word = i18n::make_ligatures(word.c_str());
 				if (i18n::has_cjk_character(word.c_str())) {
 					std::vector<std::string> units = i18n::split_cjk_word(word.c_str());


Follow ups