Answer the question
In order to leave comments, you need to log in
How to count the number of characters to display in an image?
There is a big line. A very, very large line. Approximately 100k characters. It is necessary to organize page-by-page and line-by-line output of this line. The question arises: how to calculate the maximum number of characters in a line, if we do not know for sure either the width of one character (each character has a different width) or the width of the screen for output (all devices are different)? Are there any ready-made algorithms?
Answer the question
In order to leave comments, you need to log in
You can pre-render this text.
But first break it into small pieces, otherwise there may be jambs.
Therefore, look how much you fit, select the sizes.
final TextPainter textPainter = TextPainter(
text: TextSpan(text: text, style: style), maxLines: 1, textDirection: TextDirection.ltr)
..layout(minWidth: 0, maxWidth: double.infinity);
return textPainter.size;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question