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

Method wrapString

Engine/source/gfx/gFont.cpp:554–653  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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