alignedStartX method
Where this line starts when drawn with glyphs, given the alignment
it was broken with. Matches startX unless glyphs (like those from
glyphsWithEllipsis) change the line's width. The line breaker aligned
the full line, which overflows the box when it doesn't wrap, so shift by
however much the width changed to keep right and center aligned lines
inside the box.
Implementation
double alignedStartX(
Paragraph paragraph,
TextAlign alignment,
Iterable<LineRunGlyph> glyphs,
) {
double drawnWidth = 0;
for (final glyph in glyphs) {
drawnWidth += glyph.run.advanceAt(glyph.index);
}
final widthChange = width(paragraph) - drawnWidth;
switch (alignment) {
case TextAlign.right:
return startX + widthChange;
case TextAlign.center:
return startX + widthChange / 2;
case TextAlign.left:
return startX;
}
}