paint method

  1. @override
void paint(
  1. Context context
)
override

Draw itself and its children, according to the calculated box.offset

Implementation

@override
void paint(Context context) {
  super.paint(context);
  paintChild(context);

  context.canvas.saveContext();
  context.canvas.setGraphicState(PdfGraphicState(opacity: opacity));
  context.canvas.setStrokeColor(horizontalColor);
  final l = scale;
  final m = l / 2;
  final s = m / 2;

  final allHorizontalDivisions =
      (horizontalDivisions * horizontalSubdivisions).toDouble();
  var n = horizontalOffset;
  for (var x = box!.left + margin.left;
      x <= box!.right - margin.right;
      x += horizontalInterval / allHorizontalDivisions) {
    context.canvas
      ..setLineWidth((n % (horizontalSubdivisions * horizontalDivisions) == 0)
          ? l
          : (n % horizontalSubdivisions == 0)
              ? m
              : s)
      ..drawLine(x, box!.top, x, box!.bottom)
      ..strokePath();
    n++;
  }

  context.canvas.setStrokeColor(verticalColor);
  final allVerticalDivisions =
      (verticalDivisions * verticalSubdivisions).toDouble();
  n = verticalOffset;
  for (var y = box!.top - margin.top;
      y >= box!.bottom + margin.bottom;
      y -= verticalInterval / allVerticalDivisions) {
    context.canvas
      ..setLineWidth((n % (verticalSubdivisions * verticalDivisions) == 0)
          ? l
          : (n % verticalSubdivisions == 0)
              ? m
              : s)
      ..drawLine(box!.left, y, box!.right, y)
      ..strokePath();
    n++;
  }

  if (border.left.style.paint) {
    border.left.style.setStyle(context);
    context.canvas
      ..setStrokeColor(border.left.color)
      ..setLineWidth(border.left.width)
      ..drawLine(box!.left + margin.left, box!.top, box!.left + margin.left,
          box!.bottom)
      ..strokePath();
    border.left.style.unsetStyle(context);
  }
  if (border.right.style.paint) {
    border.right.style.setStyle(context);
    context.canvas
      ..setStrokeColor(border.right.color)
      ..setLineWidth(border.right.width)
      ..drawLine(box!.right - margin.right, box!.top,
          box!.right - margin.right, box!.bottom)
      ..strokePath();
    border.right.style.unsetStyle(context);
  }
  if (border.top.style.paint) {
    border.top.style.setStyle(context);
    context.canvas
      ..setStrokeColor(border.top.color)
      ..setLineWidth(border.top.width)
      ..drawLine(
          box!.left, box!.top - margin.top, box!.right, box!.top - margin.top)
      ..strokePath();
    border.top.style.unsetStyle(context);
  }
  if (border.bottom.style.paint) {
    border.bottom.style.setStyle(context);
    context.canvas
      ..setStrokeColor(border.bottom.color)
      ..setLineWidth(border.bottom.width)
      ..drawLine(box!.left, box!.bottom + margin.bottom, box!.right,
          box!.bottom + margin.bottom)
      ..strokePath();
    border.bottom.style.unsetStyle(context);
  }

  context.canvas.restoreContext();
}