(svn r18143) -Codechange: allow stripping/ignoring of SETX(Y) during DrawString

This commit is contained in:
rubidium 2009-11-17 15:25:40 +00:00
parent cbc12fdd86
commit e297f79b7f
2 changed files with 14 additions and 4 deletions

View File

@ -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...");

View File

@ -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);