Add RTL support to breakText

This commit is contained in:
Alayan 2018-10-14 18:14:05 +02:00
parent de2d24a571
commit fec0216492
2 changed files with 17 additions and 2 deletions

@ -912,13 +912,21 @@ namespace StringUtils
/** Breaks the text so that each line is smaller than max_width with the current settings.
* The result is put into output, a vector of strings, with each line having its own string */
// TODO : try to get rid of the complications induced by wchar
void breakText(const std::wstring& input, std::vector<std::wstring> &output, unsigned int max_width, irr::gui::IGUIFont* font)
void breakText(const std::wstring& input, std::vector<std::wstring> &output,
unsigned int max_width, irr::gui::IGUIFont* font, bool right_to_left)
{
output.clear();
// We need to use a wstring to get wchar_t later
std::wstring work_copy = input;
// For right to left, we reverse the order of the wchars.
// Then, we apply the same operation at the end on the line strings.
// As we don't break on multi-wchar symbols,
// the second reverse step will put them back in the correct order.
if (right_to_left)
std::reverse(work_copy.begin(), work_copy.end());
wchar_t c;
unsigned int index = 0;
// The index of the last character to include before the linebreak
@ -1022,6 +1030,13 @@ namespace StringUtils
index = 0;
}
} // While(true) - active until the whole string has been broken and copied
if (right_to_left)
{
for (unsigned int i=0;i<output.size();i++)
{
std::reverse(output[i].begin(), output[i].end());
}
}
} // breakText
/* This function checks if a char is suitable to break lines.

@ -248,7 +248,7 @@ namespace StringUtils
std::string findAndReplace(const std::string& source, const std::string& find, const std::string& replace);
std::string removeWhitespaces(const std::string& input);
void breakText(const std::wstring& input, std::vector<std::wstring> &output,
unsigned int max_width, irr::gui::IGUIFont* font);
unsigned int max_width, irr::gui::IGUIFont* font, bool right_to_left=false);
bool breakable (wchar_t c);
bool partOfLongUnicodeChar (wchar_t c);