changeset 16298:1c8b845b9f2c draft

(svn r21006) -Fix (r21004): don't print the text direction character when ICU isn't linked and thus doesn't remove them
author rubidium <rubidium@openttd.org>
date Fri, 22 Oct 2010 12:15:58 +0000
parents 532a37dbc34d
children 5c920b2c2509
files src/gfx.cpp src/string_func.h
diffstat 2 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -380,7 +380,7 @@
 	ddd_w = ddd = GetCharacterWidth(size, '.') * 3;
 
 	for (ddd_pos = str; (c = Utf8Consume(const_cast<const char **>(&str))) != '\0'; ) {
-		if (IsPrintable(c)) {
+		if (IsPrintable(c) && !IsTextDirectionChar(c)) {
 			w += GetCharacterWidth(size, c);
 
 			if (w > maxw) {
@@ -437,7 +437,7 @@
 	for (;;) {
 		c = *str++;
 		if (c == 0) break;
-		if (IsPrintable(c)) {
+		if (IsPrintable(c) && !IsTextDirectionChar(c)) {
 			width += GetCharacterWidth(size, c);
 		} else {
 			switch (c) {
@@ -687,7 +687,7 @@
 			/* whitespace is where we will insert the line-break */
 			if (IsWhitespace(c)) last_space = str;
 
-			if (IsPrintable(c)) {
+			if (IsPrintable(c) && !IsTextDirectionChar(c)) {
 				int char_w = GetCharacterWidth(size, c);
 				w += char_w;
 				if (w > maxw) {
@@ -982,7 +982,7 @@
 	for (;;) {
 		c = Utf8Consume(&str);
 		if (c == 0) break;
-		if (IsPrintable(c)) {
+		if (IsPrintable(c) && !IsTextDirectionChar(c)) {
 			br.width += GetCharacterWidth(size, c);
 		} else {
 			switch (c) {
@@ -1081,7 +1081,7 @@
 		if (c == 0) {
 			return x;  // Nothing more to draw, get out. And here is the new x position
 		}
-		if (IsPrintable(c)) {
+		if (IsPrintable(c) && !IsTextDirectionChar(c)) {
 			if (x >= dpi->left + dpi->width) goto skip_char;
 			if (x + _max_char_width >= dpi->left) {
 				GfxMainBlitter(GetGlyph(params.fontsize, c), x, y, BM_COLOUR_REMAP);
@@ -1104,7 +1104,7 @@
 			params.SetFontSize(FS_SMALL);
 		} else if (c == SCC_BIGFONT) { // {BIGFONT}
 			params.SetFontSize(FS_LARGE);
-		} else {
+		} else if (!IsTextDirectionChar(c)) {
 			DEBUG(misc, 0, "[utf8] unknown string command character %d", c);
 		}
 	}
--- a/src/string_func.h
+++ b/src/string_func.h
@@ -224,6 +224,28 @@
 	return ret;
 }
 
+/**
+ * Is the given character a text direction character.
+ * @param c The character to test.
+ * @return true iff the character is used to influence
+ *         the text direction.
+ */
+static inline bool IsTextDirectionChar(WChar c)
+{
+	switch (c) {
+		case CHAR_TD_LRM:
+		case CHAR_TD_RLM:
+		case CHAR_TD_LRE:
+		case CHAR_TD_RLE:
+		case CHAR_TD_LRO:
+		case CHAR_TD_RLO:
+		case CHAR_TD_PDF:
+			return true;
+
+		default:
+			return false;
+	}
+}
 
 static inline bool IsPrintable(WChar c)
 {