Browse Source

Additional cleanup for WordWrapString()

pull/6706/head
staphen 2 years ago committed by Anders Jenbo
parent
commit
61e51f2349
  1. 11
      Source/engine/render/text_render.cpp

11
Source/engine/render/text_render.cpp

@ -583,7 +583,6 @@ std::string WordWrapString(std::string_view text, unsigned width, GameFontTables
const char *processedEnd = text.data();
std::string_view::size_type lastBreakablePos = std::string_view::npos;
std::size_t lastBreakableLen;
bool lastBreakableKeep = false;
unsigned lineWidth = 0;
CurrentFont currentFont;
@ -623,15 +622,13 @@ std::string WordWrapString(std::string_view text, unsigned width, GameFontTables
if (IsWhitespace(codepoint)) {
lastBreakablePos = remaining.data() - begin - codepointLen;
lastBreakableLen = codepointLen;
lastBreakableKeep = false;
continue;
}
if (lineWidth - spacing <= width) {
if (IsBreakAllowed(codepoint, nextCodepoint)) {
lastBreakablePos = remaining.data() - begin - codepointLen;
lastBreakableLen = codepointLen;
lastBreakableKeep = true;
lastBreakablePos = remaining.data() - begin;
lastBreakableLen = 0;
}
continue; // String is still within the limit, continue to the next symbol
@ -640,14 +637,10 @@ std::string WordWrapString(std::string_view text, unsigned width, GameFontTables
if (lastBreakablePos == std::string_view::npos) { // Single word longer than width
lastBreakablePos = remaining.data() - begin - codepointLen;
lastBreakableLen = 0;
lastBreakableKeep = false;
}
// Break line and continue to next line
const char *end = &text[lastBreakablePos];
if (lastBreakableKeep) {
end += lastBreakableLen;
}
output.append(processedEnd, end);
output += '\n';

Loading…
Cancel
Save