glyphs method

Iterable<LineRunGlyph> glyphs(
  1. Paragraph paragraph
)

Returns an iterator that traverses the glyphs in a line in visual order taking into account both the paragraph's runs bidi order and the individual glyphs bidi order within a run.

Implementation

Iterable<LineRunGlyph> glyphs(Paragraph paragraph) sync* {
  var displayRuns = <GlyphRun>[];
  var glyphRuns = paragraph.runs;

  for (int i = startRun; i < endRun + 1; i++) {
    displayRuns.add(glyphRuns[i]);
  }

  var startRunRef = displayRuns.first;
  var endRunRef = displayRuns.last;

  var visualRuns = paragraph.orderVisually(displayRuns);

  for (final run in visualRuns) {
    int startGIndex = startRunRef == run ? startIndex : 0;
    int endGIndex = endRunRef == run ? endIndex : run.glyphCount;

    int j, end, inc;
    if (run.direction == TextDirection.rtl) {
      j = endGIndex - 1;
      end = startGIndex - 1;
      inc = -1;
    } else {
      j = startGIndex;
      end = endGIndex;
      inc = 1;
    }

    while (j != end) {
      yield LineRunGlyph(run, j);
      j += inc;
    }
  }
}