35{
36 auto pFontDef = m_pFontDef;
37
38 if ( a_wszText && a_wszText[ 0 ] != '\0' && pFontDef )
39 {
40 auto pTextBuffer = a_wszText;
41
42 do
43 {
44 auto pTextBuffer2 = pTextBuffer;
45
46 while ( *pTextBuffer2 != L'\0' && std::iswspace( *pTextBuffer2 ) != 0 )
47 {
48 if ( *pTextBuffer2 == L'\n' ) break;
49 pTextBuffer2++;
50 }
51
52 auto wChar = *pTextBuffer2;
53
54 if ( wChar == L'\n' )
55 {
56 pTextBuffer = pTextBuffer2 + 1;
57 }
58 else
59 {
60 if ( wChar == L'\0' ) return;
61
65 auto pTextBuffer3 = pTextBuffer2;
66
67 do {
68 if ( pFontDef->ui16MinCharacter <= wChar && ( wChar <= pFontDef->ui16MaxCharacter ) )
69 {
70 TINT iCharIndex = pFontDef->pCharactersMap[ wChar - pFontDef->ui16MinCharacter ];
71
72 if ( iCharIndex >= 0 )
73 {
74 auto& pCharData = pFontDef->pCharactersData[ iCharIndex ];
75 fWidth1 += ( pFontDef->iLetterSpacing + pCharData.iRightPadding + pCharData.iLeftPadding + pCharData.ui8CharWidth ) * a_fScale;
76 }
77 }
78
79 if ( wChar == L'\n' )
80 {
81 fWidth2 = fWidth1;
82 pTextBuffer = pTextBuffer3;
83 break;
84 }
85
86 if ( std::iswspace( wChar ) != 0 && *pTextBuffer3 != L'\xA0' )
87 {
88 fWidth2 = fWidth1;
89 pTextBuffer = pTextBuffer3;
90 }
91
92 wChar = pTextBuffer3[ 1 ];
93 if ( wChar == L'\0' ) break;
94 pTextBuffer3++;
95
96 }
while ( fWidth1 < a_fWidth || pTextBuffer ==
TNULL );
97
98 if ( pTextBuffer3[ 1 ] == L'\0' )
99 {
100 pTextBuffer = pTextBuffer3 + 1;
101 fWidth2 = fWidth1;
102 }
103
105
107 fPosX = a_fX;
109 fPosX = ( a_fWidth - fWidth2 ) * 0.5f + a_fX;
111 fPosX = ( a_fWidth - fWidth2 ) + a_fX;
112 else
113 fPosX = a_fX;
114
115 DrawTextSingleLine( pTextBuffer2, pTextBuffer - pTextBuffer2, fPosX, a_fY, a_uiColour, a_fScale, a_fnCallback );
116 }
117
118 a_fY += ( pFontDef->uiLineHeight + pFontDef->uiLinesMargin ) * a_fScale;
119
120 } while ( *pTextBuffer != L'\0' );
121 }
122}
void DrawTextSingleLine(const TWCHAR *a_wszText, TINT a_iTextLength, TFLOAT a_fX, TFLOAT a_fY, TUINT32 a_uiColour, TFLOAT a_fScale, void *a_fnCallback=nullptr)