Skip to content

Expose enough of LibTxt to make custom text layout practical #35994

@suragch

Description

@suragch

This is related to #224, #18656, and #35897, but for a specific purpose. It is also a followup from this medium post.

Need

To be able to perform custom text layout beyond the currently supported ltr and rtl multiline paragraph layout.

Example use cases

Current problem

The ui.Paragraph class is about all we have to work with. This class assumes you are doing multi-line, linear, horizontal layout within a rectangular shape. It seems probable that using a ui.ParagraphBuilder to measure every single glyph in a long string would be slow (but I haven't tested that yet). Many of the metrics related to the paragraph (like line heights and text) are not provided. As far as I know, there is no access to tools like the Minikin LineBreaker.

Feature request

Expose just enough of the low level LibTxt API to make custom layout possible and practical. Based on my experience with custom text layout in Android, these are the features I think would be necessary to do custom text layout:

  • Get font metrics: ascent, descent, baseline, leading, line height
  • Have access to a line/word breaker
  • Be able to measure text runs (including single characters/glyphs) efficiently
  • Be able to measure substrings, similar to Android's Paint.breakText (see example). This is helpful for breaking a word that is longer than the max allowed length for the line. A character measured in the context of a word may have a different size than when it is measured individually. This is true for Mongolian, which like Arabic, has initial, medial, and final forms. Thus, when soft breaking a long word unnaturally across lines, it should render (and measure) the medial form at both sides of the break. Having something like Android's Paint.breakText helps with that. This one may be optional, though. I'd like to know if there is a better way to do it.
  • Be able to paint short text runs efficiently

Note that this is not a feature request of any of the specific example use case I listed in the section above.

Metadata

Metadata

Assignees

Labels

a: typographyText rendering, possibly libtxtc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions