MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / wrapString

Method wrapString

Engine/source/gfx/gFont.cpp:555–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

553}
554
555void GFont::wrapString(const UTF8 *txt, U32 lineWidth, Vector<U32> &startLineOffset, Vector<U32> &lineLen)
556{
557 // TODO: Is this error still true?
558 //Con::errorf("GFont::wrapString(): Not yet converted to be UTF-8 safe");
559
560 startLineOffset.clear();
561 lineLen.clear();
562
563 if (!txt || !txt[0] || lineWidth < getCharWidth('W')) //make sure the line width is greater then a single character
564 return;
565
566 U32 len = dStrlen(txt);
567
568 U32 startLine;
569
570 for (U32 i = 0; i < len;)
571 {
572 U32 wide = 0;
573 startLine = i;
574 startLineOffset.push_back(startLine);
575
576 // loop until the string is too large
577 bool needsNewLine = false;
578 U32 lineStrWidth = 0;
579 for (; i < len; i++)
580 {
581 if( txt[ i ] == '\n' )
582 {
583 needsNewLine = true;
584 break;
585 }
586 else if(isValidChar(txt[i]))
587 {
588 lineStrWidth += getCharInfo(txt[i]).xIncrement;
589 if(txt[i] < 0) // symbols which code > 127
590 {
591 wide++; i++;
592 }
593 if( lineStrWidth > lineWidth )
594 {
595 needsNewLine = true;
596 break;
597 }
598 }
599 }
600
601 if (!needsNewLine)
602 {
603 // we are done!
604 lineLen.push_back(i - startLine - wide);
605 return;
606 }
607
608 S32 j;
609
610 // Did we hit a hardwrap (newline character) in the string.
611 bool hardwrap = ( txt[i] == '\n' );
612

Callers 2

defaultTooltipRenderMethod · 0.80
onPreRenderMethod · 0.80

Calls 4

dIsspaceFunction · 0.85
dStrlenFunction · 0.50
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected