Bitmap: Draw line feed and carriage return as whitespace

This commit is contained in:
Jonas Kulla 2014-08-17 03:07:53 +02:00
parent 858c40591b
commit 9311aff017
1 changed files with 21 additions and 0 deletions

View File

@ -798,10 +798,28 @@ void Bitmap::drawText(int x, int y,
drawText(IntRect(x, y, width, height), str, align); drawText(IntRect(x, y, width, height), str, align);
} }
static std::string fixupString(const char *str)
{
std::string s(str);
/* RMXP actually draws LF as a "missing gylph" box,
* but since we might have accidentally converted CRs
* to LFs when editing scripts on a Unix OS, treat them
* as white space too */
for (size_t i = 0; i < s.size(); ++i)
if (s[i] == '\r' || s[i] == '\n')
s[i] = ' ';
return s;
}
void Bitmap::drawText(const IntRect &rect, const char *str, int align) void Bitmap::drawText(const IntRect &rect, const char *str, int align)
{ {
GUARD_MEGA; GUARD_MEGA;
std::string fixed = fixupString(str);
str = fixed.c_str();
if (*str == '\0') if (*str == '\0')
return; return;
@ -1029,6 +1047,9 @@ IntRect Bitmap::textSize(const char *str)
TTF_Font *font = p->font->getSdlFont(); TTF_Font *font = p->font->getSdlFont();
std::string fixed = fixupString(str);
str = fixed.c_str();
int w, h; int w, h;
TTF_SizeUTF8(font, str, &w, &h); TTF_SizeUTF8(font, str, &w, &h);