44 std::vector<Common::UString> lines;
46 split(text, lines, maxWidth, maxHeight);
52 std::vector<Common::UString> lines;
54 return split(text, lines, maxWidth);
70 float maxWidth,
float maxHeight,
bool trim)
const {
79 if (maxHeight <= 0.0f)
86 float wordLength = 0.0f;
87 float lineLength = 0.0f;
95 std::vector<Common::UString> tokens;
99 for (std::vector<Common::UString>::iterator t = tokens.begin(); t != tokens.end(); ++t) {
104 if (((t->size() == 11) && t->beginsWith(
"<c") && t->endsWith(
">")) ||
123 if ((lineLength + wordLength) > maxWidth) {
127 if (!
addLine(lines, currentLine, maxHeight))
130 length =
MAX(length, lineLength);
135 currentLine += lineColor;
140 currentLine += currentWord;
141 lineLength += wordLength;
143 lineColor = wordColor;
151 if ((wordLength + charWidth) > maxWidth) {
155 if (!currentLine.
empty()) {
156 if (!
addLine(lines, currentLine, maxHeight))
161 if (!
addLine(lines, lineColor + currentWord, maxHeight))
164 length =
MAX(length,
MAX(lineLength, wordLength));
172 lineColor = wordColor;
173 currentLine += lineColor;
180 if (!
addLine(lines, currentLine, maxHeight))
183 length =
MAX(length, lineLength);
191 currentLine += lineColor;
195 wordLength += charWidth;
204 if (!currentWord.
empty()) {
207 if ((lineLength + wordLength) > maxWidth &&
addLine(lines, currentLine, maxHeight)) {
210 length =
MAX(length, lineLength);
215 currentLine += lineColor;
220 currentLine += currentWord;
221 lineLength += wordLength;
224 if (!currentLine.
empty() &&
addLine(lines, currentLine, maxHeight)) {
226 length =
MAX(length, lineLength);
231 for (std::vector<Common::UString>::iterator l = lines.begin(); l != lines.end(); ++l)
238 return split(line, line, maxWidth, maxHeight, trim);
242 std::vector<Common::UString> sLines;
244 float width =
split(line, sLines, maxWidth, maxHeight, trim);
247 for (std::vector<Common::UString>::const_iterator l = sLines.begin(); l != sLines.end(); ++l) {
267 float maxHeight)
const {
269 if ((lines.size() + 1) *
getHeight() <= maxHeight) {
270 lines.push_back(newLine);
A class holding an UTF-8 string.
float getLineWidth(const Common::UString &text) const
Return the width of this string.
virtual float getLineSpacing() const
Return the size of space between lines.
size_t getLineCount(const Common::UString &text, float maxWidth=0.0f, float maxHeight=0.0f) const
Return the number of lines this text spans.
float split(const Common::UString &line, std::vector< Common::UString > &lines, float maxWidth=0.0f, float maxHeight=0.0f, bool trim=true) const
bool addLine(std::vector< Common::UString > &lines, const Common::UString &newLine, float maxHeight) const
utf8::iterator< std::string::const_iterator > iterator
Utility templates and functions.
static void splitTextTokens(const UString &text, std::vector< UString > &tokens)
bool empty() const
Is the string empty?
virtual void buildChars(const Common::UString &str)
Build all necessary characters to display this string.
virtual float getHeight() const =0
Return the height of a character.
void clear()
Clear the string's contents.
virtual float getWidth(uint32 c) const =0
Return the width of a character.
static bool isSpace(uint32 c)
Is the character an ASCII space character?