MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / processText

Method processText

src/Interface/Text.cpp:347–456  ·  view source on GitHub ↗

* Takes care of any text post-processing like calculating * line metrics for alignment and wordwrapping if necessary. */

Source from the content-addressed store, hash-verified

345 * line metrics for alignment and wordwrapping if necessary.
346 */
347void Text::processText()
348{
349 if (_font == 0 || _lang == 0)
350 {
351 return;
352 }
353
354 std::wstring *str = &_text;
355
356 // Use a separate string for wordwrapping text
357 if (_wrap)
358 {
359 _wrappedText = _text;
360 str = &_wrappedText;
361 }
362
363 _lineWidth.clear();
364 _lineHeight.clear();
365
366 int width = 0, word = 0;
367 size_t space = 0;
368 bool start = true;
369 Font *font = _font;
370
371 // Go through the text character by character
372 for (size_t c = 0; c <= str->size(); ++c)
373 {
374 // End of the line
375 if (c == str->size() || Font::isLinebreak((*str)[c]))
376 {
377 // Add line measurements for alignment later
378 _lineWidth.push_back(width);
379 _lineHeight.push_back(font->getCharSize(L'\n').h);
380 width = 0;
381 word = 0;
382 start = true;
383
384 if (c == str->size())
385 break;
386 // \x02 marks start of small text
387 else if ((*str)[c] == 2)
388 font = _small;
389 }
390 // Keep track of spaces for wordwrapping
391 else if (Font::isSpace((*str)[c]) || Font::isSeparator((*str)[c]))
392 {
393 space = c;
394 width += font->getCharSize((*str)[c]).w;
395 word = 0;
396 start = false;
397 }
398 // Keep track of the width of the last line and word
399 else if ((*str)[c] != 1)
400 {
401 if (font->getChar((*str)[c]) == 0)
402 {
403 (*str)[c] = L'?';
404 }

Callers

nothing calls this directly

Calls 4

getCharSizeMethod · 0.80
getCharMethod · 0.80
getTextWrappingMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected