paint static method
void
paint(})
Implementation
static void paint(Canvas canvas, UDocMarkupKind kind, List<Rect> rects, Color color, {bool selected = false, bool hasNote = false, bool rtl = false, bool drawBadge = true}) {
if (rects.isEmpty) return;
switch (kind) {
case UDocMarkupKind.highlight:
final Paint fill = Paint()..color = color.withValues(alpha: 0.38);
for (final Rect rect in rects) {
canvas.drawRRect(RRect.fromRectAndRadius(rect.inflate(0.6), Radius.circular(rect.height * 0.12)), fill);
}
break;
case UDocMarkupKind.underline:
final Paint line = Paint()
..color = color
..strokeCap = StrokeCap.round;
for (final Rect rect in rects) {
line.strokeWidth = max(1.2, rect.height * 0.08);
canvas.drawLine(Offset(rect.left, rect.bottom - line.strokeWidth / 2), Offset(rect.right, rect.bottom - line.strokeWidth / 2), line);
}
break;
case UDocMarkupKind.strikeThrough:
final Paint line = Paint()
..color = color
..strokeCap = StrokeCap.round;
for (final Rect rect in rects) {
line.strokeWidth = max(1.2, rect.height * 0.08);
canvas.drawLine(Offset(rect.left, rect.center.dy), Offset(rect.right, rect.center.dy), line);
}
break;
case UDocMarkupKind.squiggly:
final Paint wave = Paint()
..color = color
..style = PaintingStyle.stroke
..strokeJoin = StrokeJoin.round;
for (final Rect rect in rects) {
final double amplitude = max(1, rect.height * 0.08);
final double step = max(2, rect.height * 0.22);
wave.strokeWidth = max(1, rect.height * 0.06);
final Path path = Path()..moveTo(rect.left, rect.bottom - amplitude);
bool up = true;
for (double x = rect.left + step; x <= rect.right + 0.1; x += step) {
path.lineTo(x, up ? rect.bottom - amplitude * 2 : rect.bottom);
up = !up;
}
canvas.drawPath(path, wave);
}
break;
case UDocMarkupKind.border:
final Paint stroke = Paint()
..color = color
..style = PaintingStyle.stroke;
for (final Rect rect in rects) {
stroke.strokeWidth = max(1.2, rect.height * 0.07);
canvas.drawRRect(RRect.fromRectAndRadius(rect.inflate(stroke.strokeWidth + 0.5), Radius.circular(rect.height * 0.15)), stroke);
}
break;
case UDocMarkupKind.note:
final Paint fill = Paint()..color = color.withValues(alpha: 0.16);
final Paint line = Paint()
..color = color
..strokeWidth = 1.2
..style = PaintingStyle.stroke;
for (final Rect rect in rects) {
canvas.drawRect(rect.inflate(0.5), fill);
_dashed(canvas, Offset(rect.left, rect.bottom), Offset(rect.right, rect.bottom), line, max(2, rect.height * 0.18));
}
break;
}
if (selected) outline(canvas, rects);
if (drawBadge && (hasNote || kind == UDocMarkupKind.note)) {
final Rect anchor = rtl ? rects.first : rects.last;
final double size = (anchor.height * 0.9).clamp(8, 22).toDouble();
badge(canvas, Offset(rtl ? anchor.left - size * 0.35 : anchor.right + size * 0.35, anchor.top - size * 0.35), color, size);
}
}