Bitmap: Draw line feed and carriage return as whitespace
This commit is contained in:
parent
858c40591b
commit
9311aff017
|
@ -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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue