Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function FormatLine( str, font, size )
- if( not str ) then return; end
- local start = 1;
- local c = 1;
- surface.SetFont( font );
- local endstr = "";
- local n = 0;
- local lastspace = 0;
- local lastspacemade = 0;
- while( string.len( str ) > c ) do
- local sub = string.sub( str, start, c );
- if( string.sub( str, c, c ) == " " ) then
- lastspace = c;
- end
- if( surface.GetTextSize( sub ) >= size and lastspace ~= lastspacemade ) then
- local sub2;
- if( lastspace == 0 ) then
- lastspace = c;
- lastspacemade = c;
- end
- if( lastspace > 1 ) then
- sub2 = string.sub( str, start, lastspace - 1 );
- c = lastspace;
- else
- sub2 = string.sub( str, start, c );
- end
- endstr = endstr .. sub2 .. "\n";
- lastspace = c + 1;
- lastspacemade = lastspace;
- start = c + 1;
- n = n + 1;
- end
- c = c + 1;
- end
- if( start < string.len( str ) ) then
- endstr = endstr .. string.sub( str, start );
- end
- return endstr, n;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement