summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gfx.cpp17
-rw-r--r--src/gfx_func.h1
2 files changed, 14 insertions, 4 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 042148b8b..2bda13967 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -327,9 +327,10 @@ static UChar *HandleBiDiAndArabicShapes(UChar *buffer)
* If the string is truncated, add three dots ('...') to show this.
* @param *str string that is checked and possibly truncated
* @param maxw maximum width in pixels of the string
+ * @param ignore_setxy whether to ignore SETX(Y) or not
* @return new width of (truncated) string
*/
-static int TruncateString(char *str, int maxw)
+static int TruncateString(char *str, int maxw, bool ignore_setxy)
{
int w = 0;
FontSize size = _cur_fontsize;
@@ -353,10 +354,10 @@ static int TruncateString(char *str, int maxw)
}
} else {
if (c == SCC_SETX) {
- w = *str;
+ if (!ignore_setxy) w = *str;
str++;
} else if (c == SCC_SETXY) {
- w = *str;
+ if (!ignore_setxy) w = *str;
str += 2;
} else if (c == SCC_TINYFONT) {
size = FS_SMALL;
@@ -446,7 +447,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
int initial_right = right;
int initial_top = top;
- if (truncate) TruncateString(str, right - left + 1);
+ if (truncate) TruncateString(str, right - left + 1, (align & SA_STRIP) == SA_STRIP);
/*
* To support SETX and SETXY properly with RTL languages we have to
@@ -480,6 +481,14 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
continue;
}
+ if (align & SA_STRIP) {
+ /* We do not want to keep the SETX(Y)!. It was already copied, so
+ * remove it and undo the incrementing of the pointer! */
+ *p-- = '\0';
+ loc += len + (c == SCC_SETXY ? 2 : 1);
+ continue;
+ }
+
if ((align & SA_MASK) != SA_LEFT) {
DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
diff --git a/src/gfx_func.h b/src/gfx_func.h
index c8ba4c0d6..6fe86ca68 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -100,6 +100,7 @@ enum StringAlignment {
SA_RIGHT, ///< Right align the text
SA_MASK = 3, ///< Mask for base alignment
SA_FORCE = 4, ///< Force the alignment, i.e. don't swap for RTL languages.
+ SA_STRIP = 8, ///< Strip the SETX/SETXY commands from the string
};
DECLARE_ENUM_AS_BIT_SET(StringAlignment);