Skip to content

Text widget should allow for other line-breaking algorithms #53549

@marcglasberg

Description

@marcglasberg

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: typographyText rendering, possibly libtxtc: proposalA detailed proposal for a change to Fluttercustomer: crowdAffects or could affect many people, though not necessarily a specific customer.engineflutter/engine related. See also e: labels.frameworkflutter/packages/flutter repository. See also f: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions