MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / wordWrapText

Method wordWrapText

framework/font.cpp:154–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154std::list<UString> BitmapFont::wordWrapText(const UString &Text, int MaxWidth)
155{
156 int txtwidth;
157 auto lines = split(Text, "\n");
158 std::list<UString> wrappedLines;
159
160 for (const UString &str : lines)
161 {
162 txtwidth = getFontWidth(str);
163
164 if (txtwidth > MaxWidth)
165 {
166 auto remainingChunksVector = split(str, " ");
167 auto remainingChunks =
168 std::list<UString>(remainingChunksVector.begin(), remainingChunksVector.end());
169 UString currentLine;
170
171 while (!remainingChunks.empty())
172 {
173 UString currentTestLine;
174 if (currentLine != "")
175 currentTestLine = currentLine + " ";
176
177 auto &currentChunk = remainingChunks.front();
178 currentTestLine += currentChunk;
179
180 auto estimatedLength = getFontWidth(currentTestLine);
181
182 if (estimatedLength < MaxWidth)
183 {
184 currentLine = currentTestLine;
185 remainingChunks.pop_front();
186 }
187 else
188 {
189 if (currentLine == "")
190 {
191 LogWarning("No break in line \"%s\" found - this will probably overflow "
192 "the control",
193 currentTestLine);
194 currentLine = currentTestLine;
195 remainingChunks.pop_front();
196 }
197 else
198 {
199 wrappedLines.push_back(currentLine);
200 currentLine = "";
201 }
202 }
203 }
204 if (currentLine != "")
205 wrappedLines.push_back(currentLine);
206 }
207 else
208 {
209 wrappedLines.push_back(str);
210 }
211 }

Callers 1

onRenderMethod · 0.80

Calls 4

splitFunction · 0.85
endMethod · 0.80
emptyMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected