paintChild method
Paint a child RenderObject.
If the child has its own composited layer, the child will be composited into the layer subtree associated with this painting context. Otherwise, the child will be painted into the current PictureLayer for this context.
Implementation
@override
void paintChild(RenderObject child, Offset offset) {
if (child is RenderParagraph) {
final defaultColor = child.text.style?.color ?? const Color(0xFF000000);
final plainText = child.text.toPlainText();
final colors = <Color>[];
_visitSpan(child.text, defaultColor, colors);
var charOffset = 0;
for (final char in plainText.characters) {
final charLength = char.length;
if (char.trim().isEmpty || char == '\uFFFC') {
charOffset += charLength;
continue;
}
final boxes = child.getBoxesForSelection(
TextSelection(
baseOffset: charOffset,
extentOffset: charOffset + charLength,
),
);
if (boxes.isNotEmpty) {
final color = charOffset < colors.length
? colors[charOffset]
: defaultColor;
final paint = Paint()
..isAntiAlias = false
..color = color;
for (final box in boxes) {
canvas.drawRect(
Rect.fromLTRB(
box.left,
box.top,
box.right,
box.bottom,
).shift(offset),
paint,
);
}
}
charOffset += charLength;
}
} else {
return child.paint(this, offset);
}
}