rectsFor method
Implementation
List<Rect> rectsFor(int start, int end, {UDocTextGeometry geometry = UDocTextGeometry.auto}) {
final int from = start.clamp(0, text.length);
final int to = end.clamp(0, text.length);
if (to <= from) return const <Rect>[];
if (usesBox(geometry)) return <Rect>[rect];
final List<Rect> pieces = <Rect>[];
for (int i = from; i < to; i++) {
final Rect piece = charRects[i];
if (piece.width <= 0.01 || piece.height <= 0.01) continue;
pieces.add(piece);
}
if (pieces.isEmpty) return <Rect>[rect];
pieces.sort((Rect a, Rect b) => a.left.compareTo(b.left));
final List<Rect> merged = <Rect>[];
Rect current = pieces.first;
for (int i = 1; i < pieces.length; i++) {
final Rect next = pieces[i];
if (next.left <= current.right + current.height * 0.6) {
current = current.expandToInclude(next);
} else {
merged.add(current);
current = next;
}
}
merged.add(current);
return merged;
}