render method
Returns the resulting String with hyphens and linebreaks.
Implementation
WrapResult render() {
if (_tokenIter.isEmpty()) {
return WrapResult(_text, _style, _maxWidth, Size(0, 0), _lines);
}
final List<TextPartToken> line = [];
while (true) {
var token = _tokenIter.current();
// ------------------------------------------------------------
// NEWLINE
// ------------------------------------------------------------
if (token is NewlineToken) {
_lines.add(_cloneLineAndAddNewline(line));
line.clear();
} else
// ------------------------------------------------------------
// TABS AND SPACES
// ------------------------------------------------------------
if (token is TabsAndSpacesToken && line.isNotEmpty) {
if (_canAddNoHyphen([token], line)) {
line.add(token);
} else {
_lines.add(_cloneLineAndAddNewline(line));
line.clear();
}
} else
// ------------------------------------------------------------
// WORD
// ------------------------------------------------------------
if (token is WordToken) {
// print('ADING WORD TO LINE: $token');
bool trySuccess = _tryAddWordToLine(token, line);
if (trySuccess == false) {
// print('ADING WORD TO EMPTY LINE');
if (line.isNotEmpty) {
_lines.add(_cloneLineAndAddNewline(line));
line.clear();
}
trySuccess = _tryAddWordToLine(token, line);
if (trySuccess == false) {
// print('ADING WORD TO NEW EMPTY LINE -- FORCED');
if (line.isNotEmpty) {
_lines.add(_cloneLineAndAddNewline(line));
line.clear();
}
line.add(token);
}
}
}
// ------------------------------------------------------------
// NEXT TOKEN
// ------------------------------------------------------------
if (_tokenIter.hasNext()) {
_tokenIter.next();
} else {
break;
}
}
if (line.isNotEmpty) {
_lines.add(line);
}
if (_text.maxLines != null && _lines.length > _text.maxLines!) {
return WrapResult(_text, _style, _maxWidth, Size(0, 0), _lines);
}
final str =
_lines.map<String>((line) => line.map((e) => e.render()).join()).join();
_painter.text = TextSpan(text: str, style: _style);
_painter.layout();
final wrap = WrapResult(
TextHelper.clone(_text, str), _style, _maxWidth, _painter.size, _lines);
// if (kDebugMode) {
// print('RENDERED lines paint:\n${wrap.debugSizeOfLines}');
// print('RENDERED string paint:\n$str');
// print('RENDERED size by paint: ${_painter.size}');
// print('RENDERED size by token: ${wrap.debugSizeByText}');
// print('RENDERED maxWidth: ${wrap.maxWidth}');
// }
return wrap;
}