in packages/diagrams/lib/src/text.dart [382:486]
void paint(Canvas canvas, Size size) {
final Paint paint = Paint();
if (index.isEven) {
paint.color = const Color.fromARGB(255, 235, 235, 235);
} else {
paint.color = const Color.fromARGB(255, 250, 250, 250);
}
canvas.drawRect(Rect.fromLTRB(0, 0, size.width, size.height), paint);
final TextPainter textPainter = TextPainter(
text: TextSpan(
text: 'height:$height, $text',
style: TextStyle(
fontSize: 50,
height: height,
color: Colors.black,
),
),
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
);
textPainter.layout();
final List<TextBox> boxes = textPainter.getBoxesForSelection(
const TextSelection(baseOffset: 0, extentOffset: largeIndex));
paint.color = Colors.black;
paint.strokeWidth = 3.5;
const double top = 0;
final double bottom = textPainter.height;
final double baseline =
textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic);
final double width = boxes[boxes.length - 1].right;
final Offset baseOffset = Offset(
(size.width - width) / 2 + 30, (size.height - textPainter.height) / 2);
textPainter.paint(canvas, baseOffset);
paint.color = Colors.red[900]!;
// Top
canvas.drawLine(
baseOffset,
baseOffset + Offset(width, top),
paint,
);
// Bottom
canvas.drawLine(
baseOffset + Offset(0, bottom),
baseOffset + Offset(width, bottom),
paint,
);
// Baseline
paint.color = Colors.black;
paint.strokeWidth = 2.5;
canvas.drawLine(
baseOffset + Offset(0, baseline),
baseOffset + Offset(width, baseline),
paint,
);
paint.strokeWidth = 2;
paint.style = PaintingStyle.stroke;
paint.color = Colors.blue[900]!;
final Path path = Path();
path.moveTo(baseOffset.dx - 10, baseOffset.dy + top);
path.lineTo(baseOffset.dx - 25, baseOffset.dy + top);
path.lineTo(baseOffset.dx - 25, baseOffset.dy + bottom);
path.lineTo(baseOffset.dx - 10, baseOffset.dy + bottom);
canvas.drawPath(path, paint);
TextPainter label = TextPainter(
text: TextSpan(
text: '${bottom - top}px',
style: const TextStyle(
fontSize: 20,
color: Colors.black,
),
),
textAlign: TextAlign.right,
textDirection: TextDirection.ltr,
);
label.layout();
label.paint(
canvas, baseOffset + Offset(-25.0 - 80, (top + bottom) / 2 - 10));
paint.color = Colors.black;
// Baseline label
label = TextPainter(
text: const TextSpan(
text: 'Alphabetic Baseline',
style: TextStyle(
fontSize: 9,
color: Colors.black,
),
),
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
);
label.layout();
label.paint(canvas, baseOffset + Offset(0, baseline + 1));
}