-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Currently the Text widget uses a greedy algorithm to apply line-breaks. Words are laid out until they don't fit, and then it continues in the next line.
I suggest there should be an option to choose other, better, line-breaking algorithms:
enum LineBreakAlgorithm {
greedy,
minimumRaggedness,
totalFit,
custom
}
Text({ ...
List<int> Function(ParagraphInfo) customLineBreakAlgorithm,
LineBreakAlgorithm lineBreakAlgorithm = LineBreakAlgorithm.greedy})
The LineBreakAlgorithm.minimumRaggedness could implement one of the algorithms shown here:
The LineBreakAlgorithm.totalfit could implement the total-fit line breaking algorithm, by Donald Knuth and Michael Plass, which is considered the best there is, and is used in TeX and Adobe InDesign:
- http://www.eprg.org/G53DOC/pdfs/knuth-plass-breaking.pdf
- https://github.com/robertknight/tex-linebreak
- https://github.com/baskerville/paragraph-breaker
- https://cs.uwaterloo.ca/~dberry/ATEP/StudentLectures/Ananya.pdf
- https://news.ycombinator.com/item?id=1134342
- https://www.tug.org/TUGboat/tb21-3/tb68fine.pdf
- https://www.students.cs.ubc.ca/~cs-490/2015W2/lectures/Knuth.pdf
- https://fastapi.metacpan.org/source/MWARD/Text-Reflow-1.17/Reflow.pm
- https://github.com/jaroslov/knuth-plass-thoughts/blob/master/plass.cpp (C++)
- https://gist.github.com/allen-chin/fb660a1fc77b00d1bdce25adb567dc0e (Java)
- https://github.com/manifoldco/ansiwrap/blob/master/ansiwrap.go (Go)
The LineBreakAlgorithm.custom would accept a custom algorithm that would return a list of positions (indexes in the text string) where the line-breaks should be applied. This would allow us to do cool stuff like make text into circular or triangular shapes.