orderVisually method

List<GlyphRun> orderVisually(
  1. List<GlyphRun> glyphRuns
)

Implementation

List<GlyphRun> orderVisually(List<GlyphRun> glyphRuns) {
  if (direction == TextDirection.ltr) {
    return glyphRuns;
  }
  var visualOrder = <GlyphRun>[];
  if (glyphRuns.isNotEmpty) {
    var reversed = glyphRuns.reversed;
    GlyphRun previous = reversed.first;
    visualOrder.add(previous);
    int ltrIndex = 0;
    for (final run in reversed.skip(1)) {
      if (run.direction == TextDirection.ltr &&
          previous.direction == run.direction) {
        visualOrder.insert(ltrIndex, run);
      } else {
        if (run.direction == TextDirection.ltr) {
          ltrIndex = visualOrder.length;
        }
        visualOrder.add(run);
      }
      previous = run;
    }
  }
  return visualOrder;
}